-
Notifications
You must be signed in to change notification settings - Fork 160
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
genai: Fixed nested pydantic structures recursion #658
Conversation
Great work! |
Hi @lkuligin , could you please review this pull request when you get a chance? |
thanks for your contribution! could you add a unit test for a nested Pydantic, please? |
Hi, @MahlerTom and I added several tests regarding the PR. |
Thank you @lkuligin! |
Thanks @lkuligin! Could you please do a rebase and merge instead of squash and merge? I'd like my commits to be included :) |
PR Description
While working with gregpr07/browser-use, @MahlerTom and I found several bugs in langchain handling of nested
Pydantic
structured inwith_structured_output
. Specifically, the issues occurred in_get_properties_from_schema
method inlibs\genai\langchain_google_genai\_function_utils.py
.glm.Type.OBJECT
and only took care of the first layer.pydantic
fields are required (no default value is provided), the method did not properly add these fields to therequired
list.glm.Type.OBJECT
had empty properties, there was an error that properties of typeglm.Type.OBJECT
must not be empty.Relevant issues
Fixes #657,
May be related to langchain-ai/langchain#24225
Type
🐛 Bug Fix
Changes
As mentioned above:
glm.Type.OBJECT
and only took care of the first layer. We fixed the recursion with:However, we found that when sending nested
pedantic
objects with required fields as expected output structure, like the case in the following method from gregpr07/browser-use below:Here, when we observed the
response['parsed']
was oftenNone
andresponse['parsing_error']
included validation errors for missing fields that were required.required
list when parsing thepydantic
objects. We added the nestedif
to our fix:But still got this error:
This was because in cases where an object of type
glm.Type.OBJECT
had empty properties, as was the case with the 'go_back' action in gregpr07/browser-use, there was an error that properties of typeglm.Type.OBJECT
must not be empty. We changed that by adding dummy type in such cases adding the lastelse
statement:Testing
Tested on the code described in #657
Note