-
Notifications
You must be signed in to change notification settings - Fork 212
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
RuntimeError calling add_routes with chains that have input types in Pydantic v2 #725
Comments
langchain-core should not have any requirements on pydantic at the moment -- it allows installing either pydantic 1 or 2. Could you tell me where you are seeing this? LangServe will not support generation with pydantic 2 right now ( https://python.langchain.com/v0.2/docs/how_to/pydantic_compatibility/#4-langserve-cannot-generate-openapi-docs-if-running-pydantic-2) I'll update this: This is referring specifically to the list shown below -- i'll update the language so not ambiguous
|
Closing since it's a duplicate of a known issue |
tl;dr
How to use LangChain with different Pydantic versions | π¦οΈπ LangChain says
I think there is an issue with Langserve's API not accepting chains with v2 pydantic objects. See below for reproduction criteria pytest, particularly around the lines
with pytest.raises(RuntimeError) as re
, which occur when callingadd_routes
when passing chains with input types declared with pydantic v2 models.As far as I can tell, due to FastAPI's lack of actual support for v1 and v2 pydantic models coexisting, it seems like the only solution is to use an older version of langchain-core that supports the pydantic v1 langserve requires?
Details
I'm attempting to upgrade a set of langserve endpoints to pydantic 2.8, in order to try to adjust to
langchain-core
's new requirement for pydantic > 2.7.4, and trying to cope with V1 models for response and body by chbndrhnns Β· Pull Request #10223 Β· fastapi/fastapi not being merged into FastAPI yet in a way that solves the errors described in its other issue, Working with Pydantic v1 while having v2 installed Β· Issue #10360 Β· fastapi/fastapi.I have a pydantic v2's
pydantic.BaseModel
.The docstring to langserve's
add_routes
states with respect toinput_type: Union[Type, Literal["auto"], BaseModel] = "auto",
So instead of defining this parameter, I put on my chain,
before passing it to
add_routes
, but then it ends up erroring inlangserve.api_handler._resolve_model
, which calls:which for me, at least, it falling into the
else
branch, withbecause it's failing the
issubclass
check:Error signature:
ChatHistoryInput
adheres to pydantic 2.8's documentation with respect to arbitrary_types_allowed - ConfigDict - pydantic 2.8, so I don't think this is the actual issue; instead, I think the issue is that bothBaseModel
andcreate_model
are getting imported from pydantic v1, not pydantic v2, in spite of pydantic v2 being loaded.I've seen how How to use LangChain with different Pydantic versions | π¦οΈπ LangChain mentions that the OpenAPI docs page won't work for pydantic v2 models.
I've seen π¦οΈπ LangServe | π¦οΈπ LangChain mentions that LangChain uses the v1 namespace in pydantic v2, links back to the former page, but it seems like the issue is that
langchain-core
is now requiring pydantic v2, but langserve is requiring pydantic v1.Perhaps langserve 0.2.2's pyproject.toml should have a dependency of `langchain-core = ">=0.1,<0.2.23" instead of langchain-core = ">=0.1,<0.3"?
Reproduction Criteria - pytest
Here is a pytest that reproduces the observations above:
The text was updated successfully, but these errors were encountered: