Skip to content

fix: inject default items schema for array parameters in Gemini normalization#1010

Open
nldhuyen0047 wants to merge 1 commit intoRightNow-AI:mainfrom
nldhuyen0047:fix/gemini-array-items-missing
Open

fix: inject default items schema for array parameters in Gemini normalization#1010
nldhuyen0047 wants to merge 1 commit intoRightNow-AI:mainfrom
nldhuyen0047:fix/gemini-array-items-missing

Conversation

@nldhuyen0047
Copy link
Copy Markdown

@nldhuyen0047 nldhuyen0047 commented Apr 7, 2026

Summary

Fixes a crash/rejection from the Gemini API (INVALID_ARGUMENT) that occurs when a tool schema contains an array-typed parameter without an items field.

Root cause

JSON Schema allows arrays without items, but the Gemini API strictly requires every array parameter to have an items schema. MCP tools commonly emit array parameters without items, causing all Gemini requests involving those tools to fail.

Fix

In normalize_schema_recursive() (openfang-types/src/tool.rs): after building the normalized schema, if the type is array and items is absent, inject a default {"type": "string"} items schema.

  • Existing items definitions are preserved unchanged
  • Only applies during Gemini normalization (called via normalize_schema_for_provider)
  • Covers nested array properties recursively

Test plan

  • Use an MCP tool that declares an array parameter without items with Gemini — should no longer return INVALID_ARGUMENT
  • Verify tools with explicit items (e.g. items: {type: integer}) are not overwritten
  • cargo test --workspace passes (two new unit tests added)

@nldhuyen0047 nldhuyen0047 changed the title fix: ensure message history starts with a user turn for Gemini compatibility fix: inject default items schema for array parameters in Gemini normalization Apr 7, 2026
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