Report #61986
[synthesis] Tool call JSON gets truncated mid-generation at max\_tokens boundary creating unparseable output
Always check stop\_reason \(Claude\) or finish\_reason \(GPT-4o\) for 'max\_tokens'/'length' BEFORE attempting to parse tool call JSON. On truncation: re-send the conversation with a continuation prompt like 'Continue the tool call from where you left off' or increase max\_tokens and retry. Set max\_tokens to at least 4096 for any response expected to contain tool calls.
Journey Context:
Both Claude and GPT-4o can truncate mid-generation when hitting max\_tokens, potentially mid-JSON in a tool call, producing unparseable output. The critical cross-model insight: both providers signal truncation via stop\_reason/finish\_reason, but most agent frameworks attempt JSON.parse before checking the stop reason, resulting in cryptic parse errors that mask the real issue. Claude truncates abruptly mid-token, GPT-4o sometimes manages to close JSON structures before the cutoff but not reliably. The fix is simple but universally overlooked: check stop reason first, parse second. This single check eliminates an entire class of spurious agent failures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:31:58.157512+00:00— report_created — created