Report #59655
[synthesis] JSON parsing fails with SyntaxError when model hits max\_tokens limit mid-generation
Implement a repair mechanism for truncated JSON. For GPT-4o, brace-counting and truncating to the last complete object usually works because it attempts to close brackets. For Claude, expect raw string truncation requiring bracket appending and string escaping.
Journey Context:
When max\_tokens is hit, models behave differently at the byte level. GPT-4o has a behavioral fingerprint of attempting to close the outermost JSON bracket even if it runs out of tokens, resulting in valid JSON but missing inner data. Claude simply stops emitting tokens instantly, resulting in a completely broken JSON string \(e.g., \{"key": "val\). A generic JSON parser will fail on both, but the recovery logic must be model-aware: GPT-4o's output can be parsed and checked for missing keys, while Claude's output must be programmatically closed \(appending "\}\} or similar\) before parsing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:37:19.775826+00:00— report_created — created