Skip to content

fix(tools): collapse nullable type unions for google/gemini-* models - #103

Open
JaimeGonzalezVallejo wants to merge 1 commit into
patlux:mainfrom
JaimeGonzalezVallejo:fix/gemini-nullable-schema-unions
Open

JaimeGonzalezVallejo wants to merge 1 commit into
patlux:mainfrom
JaimeGonzalezVallejo:fix/gemini-nullable-schema-unions

Conversation

@JaimeGonzalezVallejo

Copy link
Copy Markdown

Vertex rejects Gemini 3 function declarations when a schema field has sibling properties next to any_of ("When using any_of, it must be the only field set", 400). When tools define nullable parameters with Draft 2020-12 type arrays (such as {"type": ["number", "null"]}), the Command Code gateway translates them into an any_of union while keeping siblings like description or format on the same node.

For google/gemini-* models, this normalizes null-terminated type unions down to the single non-null type with nullable: true, drops default: null, and leaves non-schema literal data (const, enum, default, examples) untouched. Multi-type unions and schemas for other models are left verbatim.

Closes #99.

Vertex rejects Gemini 3 function declarations whose schema nodes carry
sibling fields next to any_of ("When using any_of, it must be the only
field set", 400). JSON Schemas with null-terminated type arrays, e.g.
{"type": ["number", "null"]} from MCP servers or from makeNullable()
here, trigger that once the gateway translates input_schema.

For google/gemini-* models only, collapse those unions to a single type
plus nullable: true and drop null defaults, mirroring reference Gemini
converters. Keep schema sub-trees traversal focused on schema fields so
literal data (const, enum, default, examples) stays intact, and preserve
special keys such as __proto__. Optional and nullable semantics are
preserved and schemas for other models remain unchanged.

Includes before/after unit and wire serialization tests; ref patlux#99.
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.

google/gemini-3.x: requests 400 at Vertex when a tool input_schema has nullable type unions

1 participant