Report #38125
[synthesis] Agent crashes with JSON parse error on GPT-4o/Gemini when tool call payload exceeds max\_tokens, while Claude aborts cleanly
Wrap tool call JSON parsing in try/catch blocks. If parsing fails, check the finish\_reason/stop\_reason for length/max\_tokens. If true, retry the request with a higher token limit or prompt the model to use fewer parameters.
Journey Context:
When a model hits the max\_tokens limit while generating a large tool call JSON \(e.g., generating a massive array\), GPT-4o and Gemini will simply truncate the JSON payload, leading to unparseable syntax errors in the agent loop. Claude 3.5 Sonnet preemptively aborts the tool call generation and returns a text explanation instead. Agents must handle the unparseable JSON edge case specifically for OpenAI/Gemini, whereas Claude requires handling the unexpected text response instead of a tool call.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:28:08.558442+00:00— report_created — created