Feedback request: Pydantic migration #24405
Replies: 9 comments 15 replies
-
This to me is the most useful thing to come out of langchain for my use case. However, I realized a while ago that it doesn't work if I import BaseModel from the pydantic package and have to necessarily use langchain.pydantic_v1. Would love if with_structured_output becomes better documented and highlighted as a first-class feature of langchain instead of just an experimental thing. |
Beta Was this translation helpful? Give feedback.
-
For myself, 2 and 3 are more frustrating. 1 would be nice, but since that's pretty low level I find it less frustrating to use v1 syntax to define the output format, and then move that data into my v2 schemas that include additional information anyway. Points 2 and 3 show up when I am trying to do things that are a bit more complicated, and then I find it frustrating to also have to keep in mind the boundary between v1 and v2 objects, particularly with very simple models that aren't obviously taking advantage of new v2 features, but are already coupled to other v2 models within my codebase. If the plan is to stop supporting v1 alltogether (which I think would be acceptable at this point given that I think most other libraries at least support working with v2 installed if not used), I would lean towards doing it all in one go, ideally with some migration scripts that help transition from v1 to v2. |
Beta Was this translation helpful? Give feedback.
-
Only using 1 - so 1 |
Beta Was this translation helpful? Give feedback.
-
Honestly this is so far behind every other framework. Just upgrade everything. Had you done it before, when it was said it would be done, it probably wouldn't be something that had to be migrated. LangChain has been holding back my ecosystem for well over a year now. |
Beta Was this translation helpful? Give feedback.
-
Just want to chime in and say 4 will likely hold us back, as a number of our developers make heavy use of the OpenAPI docs. |
Beta Was this translation helpful? Give feedback.
-
1 is the biggest problem. |
Beta Was this translation helpful? Give feedback.
-
I hope that when upgrading to version 0.3, most of the code won't need to be modified or rewritten. Otherwise, I'm concerned that we might see another startup writing an article titled "Why We Quit LangChain." 🥹🥹 |
Beta Was this translation helpful? Give feedback.
-
v0.3 with Pydantic 2 support is out! #26544 |
Beta Was this translation helpful? Give feedback.
-
Really happy about this launch! Created some major simplification and improvements for my project. Thank you LangChain team!! |
Beta Was this translation helpful? Give feedback.
-
UPDATE 2024-08-01
langchain-core>=0.2.23
). If usingbind_tools
orwith_structured_output
please consult the list above to see compatibility for the partner package you're using.Pydantic Migration Feedback Request
We've previously announced that we're planning on dropping support for Pydantic 1 and migrating to Pydantic 2 (see #19339).
We need your input to determine which parts of this work should be prioritized.
We're aware of four main issues that arise when using Pydantic 2 with LangChain:
1: Using Pydantic 2 Objects to structure LLM outputs
SEE UPDATE ABOVE This issue has been resolved for a number of partner packages.
Oftentimes we use Pydantic Objects to structure LLM outputs. Most notably, we do this in
with_structured_output
,bind_tools
and when specifying tool schema. Eg:model.with_structured_outputs(Class) # this will break
See here for more details: #22782
2: Subclassing
If creating a custom tool or custom chat model, you can only use v1 features via the
pydantic.v1
namespace (e.g., https://python.langchain.com/v0.1/docs/guides/development/pydantic_compatibility/).3: Run-time validation has to be disabled for LangChain objects used inside Pydantic v2 models
e.g.,
4: LangServe cannot generate OpenAPI docs if running Pydantic 2
See: https://python.langchain.com/v0.2/docs/langserve/#pydantic
Our plan & ask
Our sense is that most of the issues are arising with issue number 1 above. We are therefor planning to prioritize a fix for that. We would love feedback on whether this is the case! Is this the biggest pain point? Are points 2&3 larger? Are there other things people are running into?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions