Open rpgoldman opened 3 months ago
Not sure this is correct, but it might be related to the merge of #18811, in which case it's not the update to langchain-core
, but to langchain
0.1.16
Interestingly, the following code snippet does not cause mypy to report a type error:
def make_parser() -> PydanticOutputParser:
return PydanticOutputParser(pydantic_object=InputSourceResponse)
However, the following, which should be semantically identical, gives the same error:
def make_parser() -> PydanticOutputParser:
parser = PydanticOutputParser(pydantic_object=InputSourceResponse)
return parser
On the other hand, this does not:
def make_parser() -> PydanticOutputParser:
return PydanticOutputParser(pydantic_object=InputSourceResponse)
parser = make_parser()
The following is also OK:
def make_parser() -> PydanticOutputParser:
return PydanticOutputParser(pydantic_object=InputSourceResponse)
def doit():
parser = make_parser()
return parser
Somehow the assignment from the constructor makes all the difference!
I believe I have found the problem:
print(isinstance(InputSourceResponse, langchain_core.output_parsers.pydantic.PydanticBaseModel))
prints False
.
Digging further, this is because PYDANTIC_MAJOR_VERSION == 2
despite the fact that I am using the pydantic_v1
library!
This suggests that either
langchain_core.pydantic_v1
should be an error (i.e., programmers should be forbidden from using it if PYDANTIC_MAJOR_VERSION > 1
), orPYDANTIC_MAJOR_VERSION
is defined and/or used incorrectly, or langchain_core.output_parsers.pydantic.PydanticBaseModel
is defined incorrectly, orI'm not familiar enough with the architecture to know which of these alternatives is correct, but I believe that it was not the intent to remove support for Pydantic v1, was it?
Checked other resources
Example Code
The following code used to pass mypy checks until I updated langchain_core from 0.1.31 to 0.1.44
Now I get this mypy error message:
Error Message and Stack Trace (if applicable)
Description
InputSourceResponse
as being an acceptable value forTBaseModel
.TBaseModel
is defined as follows inpydantic.py
:PydanticOutputParser
to produce an instance of itspydantic_object
is somehow failing. Note that the line that just definesparser
above is not sufficient to cause mypy to error. So something seems to be wrong in terms of the production of the result of invoking the parser.System Info
langchain==0.1.16 langchain-anthropic==0.1.11 langchain-community==0.0.33 langchain-core==0.1.44 langchain-google-vertexai==1.0.1 langchain-openai==0.0.8 langchain-text-splitters==0.0.1
MacOS 14.4.1
python version = 3.12.2