fix(tools): Handle JSON Schema boolean schemas in Gemini schema conversion#4531
fix(tools): Handle JSON Schema boolean schemas in Gemini schema conversion#4531onematchfox wants to merge 1 commit intogoogle:maingoogle/adk-python:mainfrom onematchfox:fix-gemini-schema-boolonematchfox/adk-python:fix-gemini-schema-boolCopy head branch name to clipboard
Conversation
…rsion
JSON Schema allows `true` and `false` as valid boolean schemas, where
`true` accepts any value and `false` rejects all values. Some MCP servers
use this pattern for unconstrained fields. The schema sanitizer previously
passed booleans through unchanged, causing a Pydantic ValidationError when
`_ExtendedJSONSchema` tried to validate them as schema objects.
Convert boolean schemas to `{"type": "object"}` as the closest
approximation available in Gemini's schema model.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Brian Fox <878612+onematchfox@users.noreply.github.com>
Summary of ChangesHello @onematchfox, 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 resolves a Pydantic ValidationError that occurred when the Gemini schema conversion process encountered boolean JSON schemas (e.g., Highlights
🧠 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. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
The pull request correctly addresses the Pydantic ValidationError encountered when processing JSON schemas that use boolean values (e.g., "field": true), which is a valid pattern in JSON Schema (Draft 7+) often used by MCP servers to indicate unconstrained fields. By converting these boolean schemas to an unconstrained object schema ({"type": "object"}), the utility now handles these cases gracefully instead of crashing. The implementation is correctly placed within the recursive sanitization logic and is supported by comprehensive unit tests covering various nesting scenarios including properties and array items.
Problem:
JSON Schema allows
trueandfalseas valid boolean schemas, wheretrueaccepts any value andfalserejects all values. Some MCP servers use this pattern for unconstrained fields. E.g. mcp-grafana - see grafana-mcp-list-tools.json which was obtained fromtools/listThe schema sanitizer previously passed booleans through unchanged, causing a Pydantic ValidationError when
_ExtendedJSONSchematried to validate them as schema objects.Solution:
Convert boolean schemas to
{"type": "object"}as the closest approximation available in Gemini's schema model.Testing Plan
Unit Tests:
Checklist