Repository navigation
fix(gemini): Normalize tool schemas to Gemini's typed schema subset - #3999
Merged
bobleer merged 2 commits intoNov 19, 2026
Merged
Conversation
Gemini only accepts properties on OBJECT schemas and items on ARRAY schemas. Tool schemas that intentionally omit type (Office paragraph items accept strings or objects; XLSX rows also accept an integer for freeze_panes) were forwarded untyped and rejected with 400 INVALID_ARGUMENT. Infer the structural type in the Gemini sanitizer while keeping fully untyped leaves unconstrained.
Mixed-type anyOf/oneOf unions and type arrays collapse to one Gemini type, which could leave items, properties, required, or string/number constraints on a type that cannot carry them. Gemini also rejects non-string enum values, untyped enums, required names missing from properties, tuple items, and boolean property schemas. Normalize these in the Gemini sanitizer. Across the 62 product tools, this removes the remaining Gemini-incompatible nodes in DesktopCard (nullable string enums), GenerativeUI (untyped enums), and ComputerUse (minLength left on an object).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With a Google Gemini provider (
generateContentformat), any turn that exposes the Office document tool fails with:Gemini function declarations use a strict OpenAPI subset. Keywords must match the schema
type:properties/requiredonly on OBJECT,itemsonly on ARRAY, and stringenumvalues only on STRING. The Gemini sanitizer forwarded several valid JSON Schema shapes that break these rules.Fix (Gemini sanitizer only,
GeminiMessageConverter::strip_unsupported_schema_fields)propertiesgivesobject,itemsgivesarray, and an all-stringenumgivesstring. This is the reported failure. Office paragraph items, which accept a string or an object, and XLSXrows, which also accepts an integer forfreeze_panes, leave outtypeon purpose.anyOf/oneOfunions andtypearrays collapse to one type, which could leaveitems,properties,required,minItems,minLength,pattern, orminimumon the wrong type. Dropping them only loosens constraints.nulland other non-string values from enums; nullability is still carried bynullable;requirednames thatpropertiesdoes not declare;itemsand booleanitemsas unconstrained;trueproperty schema as unconstrained and remove afalseone.Shared tool schemas are unchanged, so other providers still receive the full JSON Schema.
Audit of every product tool
I dumped the static and model-facing input schemas of all 62 tools in the
ProductFullregistry (124 schemas). A validator checked the sanitized output against the rules above:upstream/mainThe 26 nodes on
main:GenOfficeFile: 14, untypedproperties/items(the reported error).DesktopCard: 8,nullinside string enums.GenerativeUI: 3, untyped string enums.ComputerUse(static schema): 1,minLengthleft on an object after union collapse.No real tool uses non-string enums, so dropping those loses no information today. They are handled for MCP and dynamic tools.
Verification
cargo test -p openbitfun-ai-adapters --lib: 422 passed. This includes new regression tests for untyped structural schemas and for union, enum, and required normalization.