fix(llm): unflatten Gemini tool call args with dot-bracket notation#35405
Open
kagura-agent wants to merge 1 commit into
Open
fix(llm): unflatten Gemini tool call args with dot-bracket notation#35405kagura-agent wants to merge 1 commit into
kagura-agent wants to merge 1 commit into
Conversation
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>
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.
Issue for this PR
Closes #35105
Type of change
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 causesSchemaError(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:
a.b,a[0],a[0].b.c[1])]) without hangingObject.create(null)How did you verify your code works?
questiontool fails with Gemini models (SchemaError: Missing key at["questions"]due to argument flattening) #35105, mixed bracket + plain keys, malformed keys, and prototype pollution attemptsbun testinpackages/llm)Screenshots / recordings
N/A — backend change, no UI impact.
Checklist