Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema_json fail with Pydantic BaseModel in langchain-core==0.3.0.dev4 #26250

Closed
5 tasks done
liuhetian opened this issue Sep 10, 2024 · 2 comments
Closed
5 tasks done
Assignees
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core investigate Flagged for investigation. todo

Comments

@liuhetian
Copy link
Contributor

liuhetian commented Sep 10, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_openai import ChatOpenAI
model_chat = ChatOpenAI(api_key='foo')
print(model_chat.get_output_schema().schema_json()[:5])  # ok 

from pydantic import BaseModel
from typing import Any
class Foo(BaseModel):
    bar: Any
model_chat.with_structured_output(Foo, method='json_schema', strict=True).get_output_schema().schema_json()  
# PydanticUserError

Error Message and Stack Trace (if applicable)

PydanticUserError: _oai_structured_outputs_parser_output is not fully defined; you should define PydanticBaseModel, then call _oai_structured_outputs_parser_output.model_rebuild().

Description

meet this question when using langserve add_routes(app, mychain, path='/faq')

System Info

langchain-core==0.3.0.dev4
langchain-openai==0.2.0.dev2

pydantic==2.9.1
pydantic-extra-types==2.5.0
pydantic-settings==2.2.1
pydantic_core==2.23.3

python=3.12

@langcarl langcarl bot added the investigate Flagged for investigation. label Sep 10, 2024
@dosubot dosubot bot added Ɑ: core Related to langchain-core 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Sep 10, 2024
@langcarl langcarl bot added the todo label Sep 10, 2024
eyurtsev added a commit that referenced this issue Sep 10, 2024
* This allows pydantic to correctly resolve annotations necessary for
building pydantic models dynamically.
* Makes a small fix for RunnableWithMessageHistory which was fetching
the OutputType from the RunnableLambda that was yielding another
RunnableLambda. This doesn't propagate the output of the RunnableAssign
fully (i.e., with concrete type information etc.)

Resolves issue: #26250
@eyurtsev
Copy link
Collaborator

After fix it doesn't crash, but also doesn't return the expected schema, so the fix is only partial.

Users will still need to overwrite it using with_types (which is generally recommended)

I'll double check, but believe this is actually not a regression, but an existing issue in 0.2x as well

baskaryan added a commit that referenced this issue Sep 13, 2024
)

- This allows pydantic to correctly resolve annotations necessary when
using openai new param `json_schema`

Resolves issue: #26250

---------

Co-authored-by: Eugene Yurtsev <[email protected]>
Co-authored-by: Bagatur <[email protected]>
Sheepsta300 pushed a commit to Sheepsta300/langchain that referenced this issue Oct 1, 2024
…gchain-ai#26307)

- This allows pydantic to correctly resolve annotations necessary when
using openai new param `json_schema`

Resolves issue: langchain-ai#26250

---------

Co-authored-by: Eugene Yurtsev <[email protected]>
Co-authored-by: Bagatur <[email protected]>
Copy link

dosubot bot commented Dec 10, 2024

Hi, @liuhetian. I'm Dosu, and I'm helping the LangChain team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • The issue involves a bug in LangChain version 0.3.0.dev4 with Pydantic's BaseModel and the schema_json method.
  • A PydanticUserError is encountered, and a partial fix prevents the crash but doesn't return the expected schema.
  • User eyurtsev suggests using with_types as a workaround and notes this might not be a regression but an existing issue from version 0.2x.

Next Steps

  • Please confirm if this issue is still relevant to the latest version of the LangChain repository by commenting here.
  • If there is no further activity, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Dec 10, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core investigate Flagged for investigation. todo
Projects
None yet
Development

No branches or pull requests

2 participants