Skip to content

fix(translator): fix nullable type arrays breaking Gemini/Antigravity API#1511

Open
stondy0103 wants to merge 1 commit intorouter-for-me:mainfrom
stondy0103:fix/responses-nullable-type-array
Open

fix(translator): fix nullable type arrays breaking Gemini/Antigravity API#1511
stondy0103 wants to merge 1 commit intorouter-for-me:mainfrom
stondy0103:fix/responses-nullable-type-array

Conversation

@stondy0103
Copy link

Summary

  • Fixed a bug in ConvertOpenAIResponsesRequestToGemini where nullable JSON Schema type arrays (e.g. ["string", "null"]) were corrupted into invalid string values "[\"STRING\",\"NULL\"]", causing Gemini/Antigravity API to reject requests with 400 Invalid value at '...type'
  • Removed the unnecessary type uppercasing logic entirely — downstream CleanJSONSchemaForGemini() in antigravity_executor.go already handles type flattening, nullable fields, and schema cleanup correctly
  • The removed code also only processed top-level properties, missing nested schemas

Root Cause

When a tool parameter has "type": ["string", "null"] (JSON array):

  1. gjson.Result.String() returns raw text ["string","null"]
  2. strings.ToUpper()["STRING","NULL"]
  3. sjson.Set() stores as a JSON string "[\"STRING\",\"NULL\"]" (not an array)
  4. flattenTypeArrays() skips it (IsArray() == false on a string)
  5. API rejects: 400 Invalid value at '...type' (Type), "["STRING","NULL"]"

Verified

This fix has been tested and confirmed working with Droid Factory (Antigravity) using Gemini models, where Claude Code sends tool schemas with nullable parameters (e.g. "type": ["string", "null"]). The error no longer occurs after removing the broken uppercasing logic.

Impact

  • Antigravity (Droid Factory): Fixed — CleanJSONSchemaForGemini() handles everything
  • Gemini / Vertex: No impact — uses parametersJsonSchema which accepts raw JSON Schema
  • Gemini CLI: No impact — same as Gemini
  • No other executors are affected

Test plan

  • Tested with Droid Factory (Antigravity) Gemini models via OpenAI Responses API
  • Verified nullable type arrays ["string", "null"] are properly flattened by downstream CleanJSONSchemaForGemini()
  • Confirmed no regression for non-nullable type fields

🤖 Generated with Claude Code

…o-Gemini translator

The `ConvertOpenAIResponsesRequestToGemini` function had code that attempted
to uppercase JSON Schema type values (e.g. "string" -> "STRING") for Gemini
compatibility. This broke nullable types because when `type` is a JSON array
like `["string", "null"]`:

1. `gjson.Result.String()` returns the raw JSON text `["string","null"]`
2. `strings.ToUpper()` produces `["STRING","NULL"]`
3. `sjson.Set()` stores it as a JSON **string** `"[\"STRING\",\"NULL\"]"`
   instead of a JSON array
4. The downstream `CleanJSONSchemaForGemini()` / `flattenTypeArrays()`
   cannot detect it (since `IsArray()` returns false on a string)
5. Gemini/Antigravity API rejects it with:
   `400 Invalid value at '...type' (Type), "["STRING","NULL"]"`

This was confirmed and tested with Droid Factory (Antigravity) Gemini models
where Claude Code sends tool schemas with nullable parameters.

The fix removes the uppercasing logic entirely and passes the raw schema
through to `parametersJsonSchema`. This is safe because:
- Antigravity executor already runs `CleanJSONSchemaForGemini()` which
  properly handles type arrays, nullable fields, and all schema cleanup
- Gemini/Vertex executors use `parametersJsonSchema` which accepts raw
  JSON Schema directly (no uppercasing needed)
- The uppercasing code also only iterated top-level properties, missing
  nested schemas entirely

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @stondy0103, 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 bug in the ConvertOpenAIResponsesRequestToGemini function that caused API requests to Gemini/Antigravity to fail when tool parameters included nullable JSON Schema type arrays. By removing an unnecessary and incorrect type manipulation block, the change ensures that tool schemas are passed correctly, leveraging existing robust downstream processing for schema cleanup and type handling.

Highlights

  • Bug Fix: Resolved an issue where nullable JSON Schema type arrays (e.g., ["string", "null"]) were incorrectly transformed into invalid string values, leading to 400 Invalid value errors from the Gemini/Antigravity API.
  • Code Simplification: Eliminated redundant and faulty type uppercasing logic within the ConvertOpenAIResponsesRequestToGemini function, which was the root cause of the bug.
  • Improved Schema Handling: The system now relies on the existing CleanJSONSchemaForGemini() function downstream to correctly handle type flattening, nullable fields, and overall schema cleanup, making the translation process more robust.

🧠 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
  • internal/translator/gemini/openai/responses/gemini_openai-responses_request.go
    • Removed logic that incorrectly uppercased and modified JSON Schema parameter types, which was causing issues with nullable arrays.
    • Simplified the assignment of parametersJsonSchema to directly use the raw input, relying on downstream processing.
Activity
  • No human activity has been recorded on this pull request yet.
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 effectively resolves a bug where nullable JSON schema type arrays were being corrupted during translation, leading to API errors. The fix is to remove the problematic logic that was incorrectly uppercasing type values. By passing the raw parameters schema and delegating the cleaning to a downstream component, the code is now more robust and simpler. The removed logic was also incomplete as it only handled top-level properties, so this change improves correctness for nested schemas as well. This is a good fix, well-explained in the pull request description.

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.

1 participant