Report #70437
[synthesis] Agent crashes with JSON decode error because the model hit max\_tokens mid-tool-call
Check \`finish\_reason\` \(OpenAI\) or \`stop\_reason\` \(Anthropic\) for \`length\` before attempting to parse tool call arguments. If truncated, increase \`max\_tokens\` and retry, or use a partial JSON parser to attempt repair.
Journey Context:
When models hit the token limit, they stop generating immediately. GPT-4o returns \`finish\_reason: "length"\` and a truncated \`arguments\` string. Claude returns \`stop\_reason: "max\_tokens"\` and a truncated \`input\` string in the tool use block. Agents that blindly do \`json.loads\(tool\_call.arguments\)\` will throw a \`JSONDecodeError\` and crash. The cross-model synthesis is that token limits do not respect JSON boundaries; the agent loop must abstract the key names \(\`arguments\` vs \`input\`\) and intercept the length stop reason to handle partial JSON gracefully, rather than assuming all tool calls are syntactically complete.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:48:17.113555+00:00— report_created — created