Open julian24bas opened 1 month ago
Related, I've noticed that the new json_schema
method with ChatOpenAI's with_structured_output
does not support nested TypedDict
schemas, and I have also not gotten it to work with Pydantic schemas yet.
You also cannot specify which fields are Required
versus NotRequired
when using a TypedDict.
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
Traceback (most recent call last): File "/tmp_extraction_setup.py", line 59, in
response = runnable.invoke({"text": text})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/xyz_core/runnables/base.py", line 2878, in invoke
input = context.run(step.invoke, input, config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/xyz_core/output_parsers/base.py", line 183, in invoke
return self._call_with_config(
^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/xyz_core/runnables/base.py", line 1785, in _call_with_config
context.run(
File "/lib/python3.11/site-packages/xyz_core/runnables/config.py", line 427, in call_func_with_variable_args
return func(input, kwargs) # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/xyz_core/output_parsers/base.py", line 184, in
lambda inner_input: self.parse_result(
^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/xyz_core/output_parsers/abc_tools.py", line 300, in parse_result
raise e
File "/lib/python3.11/site-packages/xyz_core/output_parsers/abc_tools.py", line 295, in parse_result
pydantic_objects.append(name_dict[res["type"]]( res["args"]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in init
raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for Data
people
value is not a valid list (type=type_error.list)
Process finished with exit code 1
Description
I followed the tutorial using ChatOllama from langchain-ollama and model with tool support like llama3.1 to run it. This works fine when using the class
Person
to retrieve the information. However when changing theschema
toData
I get the error above.The data which is passed to the pydantic model has this pattern:
{'people': '[{"name": "Alan Smith", "height": "6 feet", "hair color": "blond"}, {"name": "Alan Poe", "height": "3 feet", "hair color": "grey"}]'}
As you can see here the keys for hair color and height in meters are false. Also the value for
'people'
is a string rather than a list. So there is definitely a problem with theData
class using another pydantic class as attribute.System Info
System Information
Package Information
Optional packages not installed
Other Dependencies