Skip to content
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

Support for required fields in Pydantic structured-output #642

Open
ravwojdyla opened this issue Nov 29, 2024 · 2 comments
Open

Support for required fields in Pydantic structured-output #642

ravwojdyla opened this issue Nov 29, 2024 · 2 comments
Assignees
Labels
component:python sdk Issue/PR related to Python SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working

Comments

@ravwojdyla
Copy link

ravwojdyla commented Nov 29, 2024

Description of the bug:

It appears that all fields in the structured-output are effectively marked as optional by this line: https://github.com/google-gemini/generative-ai-python/blob/b8772ed1424a080911151b354764d76a0e7af2af/google/generativeai/types/content_types.py#L490

It was added in e09e7f2, possible cause:

service fails if 'required' is used in nested objects

Actual vs expected behavior:

I have a Pydantic schema with nested objects (most of them required). Gemini API consistently doesn't fill all the required fields, which triggers Pydantic validation error. If I monkey-patch the fix or comment out the line https://github.com/google-gemini/generative-ai-python/blob/b8772ed1424a080911151b354764d76a0e7af2af/google/generativeai/types/content_types.py#L490, the Gemini API consistently returns complete JSON objects.

Any other information you'd like to share?

No response

@Aungyehtut8
Copy link

Close

@Aungyehtut8
Copy link

Description of the bug:

It appears that all fields in the structured-output are effectively marked as optional by this line:

https://github.com/google-gemini/generative-ai-python/blob/b8772ed1424a080911151b354764d76a0e7af2af/google/generativeai/types/content_types.py#L490

It was added in e09e7f2, possible cause:

service fails if 'required' is used in nested objects

Actual vs expected behavior:

I have a Pydantic schema with nested objects (most of the required). Gemini API consistently doesn't fill all the required fields, which triggers Pydantic validation error. If I monkey-patch the fix by commenting out the line

https://github.com/google-gemini/generative-ai-python/blob/b8772ed1424a080911151b354764d76a0e7af2af/google/generativeai/types/content_types.py#L490

, the Gemini API consistently returns complete json objects.

Any other information you'd like to share?

No response

Ke

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants