fix(gemini): strip deprecated keyword from tool schemas sent to Gemini API#413
fix(gemini): strip deprecated keyword from tool schemas sent to Gemini API#413n24q02m wants to merge 2 commits intorouter-for-me:mainfrom
deprecated keyword from tool schemas sent to Gemini API#413Conversation
…ini API Gemini API rejects function declarations containing the JSON Schema `deprecated` keyword with INVALID_ARGUMENT. Claude Code and other clients include this field in their tool definitions, causing 400 errors on Antigravity/Gemini routes. Add `deprecated` to the unsupported keywords list in removeUnsupportedKeywords() so it is stripped before forwarding.
Summary of ChangesHello, 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 addresses a critical compatibility issue with the Gemini API, where tool declarations containing the 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
This pull request addresses an issue where the Gemini API rejects schemas containing the deprecated keyword. The fix is to add deprecated to the list of unsupported keywords that are stripped from the schema before sending it to Gemini. The change is simple and correct. I've suggested adding a test case to verify this behavior and prevent regressions.
| "$schema", "$defs", "definitions", "const", "$ref", "$id", "additionalProperties", | ||
| "propertyNames", "patternProperties", // Gemini doesn't support these schema keywords | ||
| "enumTitles", "prefill", // Claude/OpenCode schema metadata fields unsupported by Gemini | ||
| "deprecated", // JSON Schema keyword not supported by Gemini API |
There was a problem hiding this comment.
This change correctly adds deprecated to the list of unsupported keywords. To ensure this fix is robust and prevent future regressions, it would be great to add a test case that verifies the deprecated keyword is stripped.
You could add the following test to internal/util/gemini_schema_test.go:
func TestCleanJSONSchemaForGemini_RemovesDeprecatedField(t *testing.T) {
input := `{
"type": "object",
"properties": {
"old_field": {
"type": "string",
"deprecated": true
}
}
}`
expected := `{
"type": "object",
"properties": {
"old_field": {
"type": "string"
}
}
}`
result := CleanJSONSchemaForGemini(input)
compareJSON(t, expected, result)
}Verify that `deprecated` field is stripped from tool schemas while preserving properties named "deprecated" as legitimate field names.
Summary
Gemini API rejects function declarations containing the JSON Schema
deprecatedkeyword withINVALID_ARGUMENT(400). Claude Code and other clients include this field in their tool definitions, causing errors on Antigravity/Gemini routes.Changes
Add
"deprecated"to the unsupported keywords list inremoveUnsupportedKeywords()(internal/util/gemini_schema.go) so it is stripped before forwarding to Gemini.Reproduction
"deprecated": truein tool schemas) with an Antigravity accountINVALID_ARGUMENT/ 400 error from Gemini API:Related
x-google-*vendor extension fields that were already being strippeddeprecatedkeyword from tool schemas sent to Gemini API CLIProxyAPI#1839