Skip to content

fix(gemini): Normalize tool schemas to Gemini's typed schema subset - #3999

Merged
bobleer merged 2 commits into
openBitFun:mainfrom
bobleer:fix/gemini-untyped-tool-schemas
Nov 19, 2026
Merged

bobleer merged 2 commits into
openBitFun:mainfrom
bobleer:fix/gemini-untyped-tool-schemas

Conversation

@bobleer

@bobleer bobleer commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With a Google Gemini provider (generateContent format), any turn that exposes the Office document tool fails with:

Gemini Streaming API client error 400 Bad Request: INVALID_ARGUMENT
* ...function_declarations[15].parameters.properties[operations].items.properties[slide]...paragraphs.items.properties: only allowed for OBJECT type
* ...properties[rows].items: field predicate failed: $type == Type.ARRAY
...

Gemini function declarations use a strict OpenAPI subset. Keywords must match the schema type: properties/required only on OBJECT, items only on ARRAY, and string enum values 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)

  • Infer the type of untyped schemas: properties gives object, items gives array, and an all-string enum gives string. This is the reported failure. Office paragraph items, which accept a string or an object, and XLSX rows, which also accepts an integer for freeze_panes, leave out type on purpose.
  • Drop keywords the resolved type cannot carry. Mixed-type anyOf/oneOf unions and type arrays collapse to one type, which could leave items, properties, required, minItems, minLength, pattern, or minimum on the wrong type. Dropping them only loosens constraints.
  • Clean up the remaining shapes Gemini rejects:
    • remove null and other non-string values from enums; nullability is still carried by nullable;
    • remove required names that properties does not declare;
    • treat tuple items and boolean items as unconstrained;
    • treat a true property schema as unconstrained and remove a false one.

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 ProductFull registry (124 schemas). A validator checked the sanitized output against the rules above:

Gemini-incompatible nodes
upstream/main 26
this PR 0

The 26 nodes on main:

  • GenOfficeFile: 14, untyped properties/items (the reported error).
  • DesktopCard: 8, null inside string enums.
  • GenerativeUI: 3, untyped string enums.
  • ComputerUse (static schema): 1, minLength left 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.
  • The tool audit above used temporary test code, which is not committed.
  • Local only. The change is confined to the Gemini provider adapter, so it applies the same way for every host and remote scenario.

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).
@bobleer bobleer changed the title fix(gemini): Infer object/array types for untyped tool schemas fix(gemini): Normalize tool schemas to Gemini's typed schema subset Nov 19, 2026
@bobleer
bobleer merged commit 5a9ca6f into openBitFun:main Nov 19, 2026
12 checks passed
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