Report #46241
[synthesis] stop sequences fail to halt generation mid-json in gpt-4o
Do not rely on stop sequences for truncating JSON outputs or enforcing strict length limits in GPT-4o. Instead, use max\_tokens and validate the output. For Claude, stop sequences can be reliably used for formatting \(e.g., stopping before a closing tag to inject data\).
Journey Context:
Stop sequences are implemented differently across providers. Claude treats them as hard interrupts: if the sequence appears, generation stops instantly. GPT-4o treats them as soft suggestions; it often completes the current syntactic structure \(like closing a JSON brace\) or finishes a logical clause before stopping, sometimes omitting the stop sequence entirely. If an agent relies on a stop sequence to prevent a model from generating a closing \} so it can append tool results, this works flawlessly on Claude but results in malformed JSON on GPT-4o. The cross-model solution is to avoid using stop sequences for structural JSON manipulation and instead let the model complete its thought, then parse the complete JSON.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T08:05:27.797117+00:00— report_created — created