langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
35.89k stars 4.25k forks source link

Structured Output component wrong 'content' #4788

Open mirco-gnuva opened 5 days ago

mirco-gnuva commented 5 days ago

Bug Description

Hello!

Langflow version: langflowai/langflow-nightly:v1.1.0.dev4 (Docker)

I designed a flow that uses:

I'm facing the following strange behaviour:

Schema A

Name Description Type Multiple
title text False
article text False

with that schema all works as expected

Schema B

Name Description Type Multiple
title text False
content text False

The following Error is raised: Error building Component Structured Output: Output should be a Pydantic BaseModel, got <class 'str'> <the string that with the A schema is the 'article' key value>

Conclusion

I suspect that under the hood the completion.choices[0].content.content is returned (in other words, the 'content' attribute of the resulting Pydantic object) instead of the resulting Pydantic object itself.

Reproduction

Screenshot 2024-11-22 at 17 49 11 Screenshot 2024-11-22 at 17 50 05

Expected behavior

The Structured Output component runs successfully with the following schema: Name Description Type Multiple
title text False
article text False

Who can help?

No response

Operating System

Docker

Langflow Version

1.1.0.dev4

Python Version

None

Screenshot

No response

Flow File

No response

dosubot[bot] commented 5 days ago

Hey there, @mirco-gnuva! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together!

The issue you're encountering with the Structured Output component seems to be related to the handling of the 'content' field. In Langflow, the 'content' field is subject to a custom serialization process, which might be causing the unexpected behavior you're seeing when using Schema B. The BaseContent class includes a serialize_model method that attempts to serialize the model using jsonable_encoder with custom encoders. If an exception occurs, it falls back to a default serialization method [1].

This custom handling could be affecting how the 'content' field is processed, leading to the error where a string is returned instead of a Pydantic BaseModel. To resolve this, you might consider checking if there are any specific transformations or custom encodings applied to the 'content' field that could be interfering with its expected behavior in the Structured Output component.

To continue talking to Dosu, mention @dosu.