Skip to content

fix(llm): unflatten Gemini tool call args with dot-bracket notation#35405

Open
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/gemini-tool-call-unflatten
Open

fix(llm): unflatten Gemini tool call args with dot-bracket notation#35405
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/gemini-tool-call-unflatten

Conversation

@kagura-agent

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #35105

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Gemini models sometimes return tool call arguments in flattened dot-bracket notation (e.g. {"questions[0].header": "Auth"}) instead of properly nested JSON ({questions: [{header: "Auth"}]}). This causes SchemaError(Missing key at ["questions"]) when downstream tool schema validation runs.

The fix adds an unflattenArgs() utility in the Gemini protocol adapter that detects bracket-notation keys and converts them back to nested objects/arrays before they reach schema validation. When args are already nested (no [ in any key), the function returns them as-is with zero overhead.

The utility handles:

  • Fast-path passthrough for already-nested args
  • Dot and bracket notation (a.b, a[0], a[0].b.c[1])
  • Malformed keys (missing ]) without hanging
  • Prototype pollution prevention via key denylist + Object.create(null)

How did you verify your code works?

Screenshots / recordings

N/A — backend change, no UI impact.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Gemini models sometimes return tool call arguments in flattened
dot-bracket notation (e.g. 'questions[0].header') instead of nested
JSON objects, causing SchemaError during tool input validation. Apply
unflattenArgs() to part.functionCall.args to convert flat keys into
the nested structure downstream tools expect.

Closes anomalyco#35105

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

question tool fails with Gemini models (SchemaError: Missing key at ["questions"] due to argument flattening)

1 participant