Skip to content

feat: Add support for structured output (response_format) in GoogleGenAIChatGenerator#2946

Merged
anakin87 merged 6 commits intodeepset-ai:mainfrom
aelhajj:feat/google-genai-structured-output
Mar 12, 2026
Merged

feat: Add support for structured output (response_format) in GoogleGenAIChatGenerator#2946
anakin87 merged 6 commits intodeepset-ai:mainfrom
aelhajj:feat/google-genai-structured-output

Conversation

@aelhajj
Copy link
Copy Markdown
Contributor

@aelhajj aelhajj commented Mar 10, 2026

Related Issues

Proposed Changes:

Add support for response_format in GoogleGenAIChatGenerator's generation_kwargs, enabling structured output with cross-provider portability (matching the OpenAI integration's API)

How did you test it?

Unit tests (test_chat_generator_utils.py): test_process_response_format covers Pydantic model, dict schema, missing key, native key precedence, unsupported type error, and input immutability.

Unit tests (test_chat_generator.py):
test_to_dict_with_response_format_pydantic, test_to_dict_with_response_format_dict, and test_serde_with_response_format for serialization/deserialization.

Integration tests (test_chat_generator.py):

test_live_run_with_structured_output_pydantic, test_live_run_with_structured_output_dict_schema (sync), and test_live_run_async_with_structured_output (async), all verified with a Google Studio API key

Notes for the reviewer

  • The approach mirrors how _process_thinking_config works: a pure function that returns a new dict, chained in both run() and run_async().
    Google's SDK natively accepts Pydantic BaseModel classes for response_schema, so no manual JSON schema conversion is needed at runtime — only for serialization in to_dict().
  • The to_dict() serialization is done inline (converting Pydantic → model_json_schema()) matching the pattern used in other integrations (Mistral, TogetherAI, etc.).

Checklist

@aelhajj aelhajj requested a review from a team as a code owner March 10, 2026 17:34
@aelhajj aelhajj requested review from anakin87 and removed request for a team March 10, 2026 17:34
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 10, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added integration:google-genai type:documentation Improvements or additions to documentation labels Mar 10, 2026
@aelhajj aelhajj force-pushed the feat/google-genai-structured-output branch from bd6715a to a1a6981 Compare March 10, 2026 17:38
Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

I left some comments

Comment thread integrations/google_genai/tests/test_chat_generator.py Outdated
@aelhajj
Copy link
Copy Markdown
Contributor Author

aelhajj commented Mar 12, 2026

Thank you for the contribution!

I left some comments

thank you for taking the time to review !

@aelhajj aelhajj requested a review from anakin87 March 12, 2026 16:32
Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@anakin87 anakin87 merged commit 43e483b into deepset-ai:main Mar 12, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:google-genai type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add support for GenAI (Google) GoogleGenAIChatGenerator structured output

3 participants