Skip to content

Implement OutputResponseProcessor to enable use of OutputSchema and tools#441

Merged
dpasiukevich merged 6 commits intogoogle:mainfrom
caglar10ur:main
Jan 13, 2026
Merged

Implement OutputResponseProcessor to enable use of OutputSchema and tools#441
dpasiukevich merged 6 commits intogoogle:mainfrom
caglar10ur:main

Conversation

@caglar10ur
Copy link
Contributor

on Gemini models that does not support structured outputs with tools [1]

Based on adk-python [2], if both specified on non-supported model,

  • Do not set output schema on the model config,
  • Add a special tool called set_model_response using the output schema,
  • Instruct the model to use this tool to output its final result, rather than output text directly.

Fixes #307

Tested via https://gist.github.com/caglar10ur/52e49e9be5f64f5ac47107810c9e60fb

[1] https://ai.google.dev/gemini-api/docs/structured-output?example=recipe#structured_outputs_with_tools
[2] google/adk-python@af63567

tools

on Gemini models that does not support structured outputs with tools [1]

Based on adk-python [2], if both specified on non-supported model,
   - Do not set output schema on the model config,
   - Add a special tool called set_model_response using the output schema,
   - Instruct the model to use this tool to output its final result,
     rather than output text directly.

Fixes google#307

Tested via https://gist.github.com/caglar10ur/52e49e9be5f64f5ac47107810c9e60fb

[1] https://ai.google.dev/gemini-api/docs/structured-output?example=recipe#structured_outputs_with_tools
[2] google/adk-python@af63567

Signed-off-by: Çağlar Onur <caglaronur@google.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @caglar10ur, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the system's ability to handle structured outputs from Gemini models, particularly those that lack native support for combining structured outputs with tool usage. It achieves this by implementing a new processor that, when necessary, injects a custom set_model_response tool and guides the model to use it for generating responses conforming to a specified output schema. This ensures consistent structured output behavior across a wider range of Gemini models.

Highlights

  • Structured Output for Gemini Models: Implemented a mechanism to enable structured outputs for Gemini models that do not natively support combining structured outputs with tool usage.
  • Workaround with set_model_response Tool: Introduced a special tool named set_model_response that encapsulates the desired output schema. The model is instructed to use this tool for its final structured response.
  • Conditional Schema Application: Modified the request processing flow to conditionally apply the output schema directly to the model config or use the set_model_response tool workaround, depending on the model's capabilities and the presence of other tools.
  • Model Variant Utilities: Added new utility functions to identify Gemini models, their versions (e.g., Gemini 2.0+), and whether they support native structured output with tools, allowing for intelligent application of the workaround.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a workaround for Gemini models that don't support using both tools and an output schema simultaneously. It introduces an outputSchemaRequestProcessor that, when needed, injects a special set_model_response tool. This tool is defined with the desired output schema, and the model is instructed to use it for its final structured response. The response from this tool call is then extracted and treated as the final model output. The changes are well-structured and include comprehensive tests. My review includes a few suggestions for improving performance and test code quality by adhering to Go best practices.

Signed-off-by: Çağlar Onur <caglaronur@google.com>
@baptmont
Copy link
Contributor

Hi @caglar10ur, thank you for the contribution! There are some lint checks failing and the test files are missing the copyright header, let me know if you are able to fix them!

Signed-off-by: Çağlar Onur <caglaronur@google.com>
@caglar10ur
Copy link
Contributor Author

Hi @caglar10ur, thank you for the contribution! There are some lint checks failing and the test files are missing the copyright header, let me know if you are able to fix them!

Just pushed a commit hopefully addressing those issues.

@baptmont
Copy link
Contributor

baptmont commented Jan 2, 2026

@caglar10ur the checks are still failing. There seems to be missing a line break between the copyright header and the package. The lint check also mentions the indentation on the // http://www.apache.org/licenses/LICENSE-2.0 part and a missing line break for the "github.com/google/go-cmp/cmp" import in outputschema_processor_test.go

Signed-off-by: Çağlar Onur <caglaronur@google.com>
@caglar10ur
Copy link
Contributor Author

@caglar10ur the checks are still failing. There seems to be missing a line break between the copyright header and the package. The lint check also mentions the indentation on the // http://www.apache.org/licenses/LICENSE-2.0 part and a missing line break for the "github.com/google/go-cmp/cmp" import in outputschema_processor_test.go

Sorry about the noise, turns out I was not using goimports with correct flags (-local google.golang.org/adk was missing), pushed another commit to solve the remaining cosmetic issues.

baptmont
baptmont previously approved these changes Jan 5, 2026
@baptmont baptmont requested a review from dpasiukevich January 5, 2026 09:13
Copy link
Collaborator

@dpasiukevich dpasiukevich left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Left a couple of questions/clarifications.

Signed-off-by: Çağlar Onur <caglaronur@google.com>
Signed-off-by: Çağlar Onur <caglaronur@google.com>
@caglar10ur
Copy link
Contributor Author

@dpasiukevich let me know if you want more changes. Thanks!

@dpasiukevich
Copy link
Collaborator

LGTM!

@dpasiukevich dpasiukevich merged commit 012d380 into google:main Jan 13, 2026
4 checks passed
davidli2010 pushed a commit to davidli2010/adk-go that referenced this pull request Feb 4, 2026
…ools (google#441)

* Implement OutputResponseProcessor to enable use of OutputSchema and
tools

on Gemini models that does not support structured outputs with tools [1]

Based on adk-python [2], if both specified on non-supported model,
   - Do not set output schema on the model config,
   - Add a special tool called set_model_response using the output schema,
   - Instruct the model to use this tool to output its final result,
     rather than output text directly.

Fixes google#307

Tested via https://gist.github.com/caglar10ur/52e49e9be5f64f5ac47107810c9e60fb

[1] https://ai.google.dev/gemini-api/docs/structured-output?example=recipe#structured_outputs_with_tools
[2] google/adk-python@af63567

Signed-off-by: Çağlar Onur <caglaronur@google.com>

* Address gemini-code-assist comments

Signed-off-by: Çağlar Onur <caglaronur@google.com>

* Add missing copyright headers and fix formatting isssues

Signed-off-by: Çağlar Onur <caglaronur@google.com>

* Address remaining formatting isssues

Signed-off-by: Çağlar Onur <caglaronur@google.com>

* Address incorrect return after yield comment

Signed-off-by: Çağlar Onur <caglaronur@google.com>

* Adjust the tests based on the previous change

Signed-off-by: Çağlar Onur <caglaronur@google.com>

---------

Signed-off-by: Çağlar Onur <caglaronur@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OutputSchema should be allowed alongside tools

3 participants