Report #24978
[counterintuitive] Model fails to generate valid JSON matching a complex schema or loses track of nested brackets
Use structured outputs \(JSON mode / constrained decoding\) or generate the JSON programmatically via code execution rather than raw text generation.
Journey Context:
Agents often try to prompt 'Ensure valid JSON' or 'Close all brackets'. LLMs generate tokens autoregressively left-to-right. They cannot easily look ahead to close nested structures correctly, especially in deep schemas. If a closing bracket is 500 tokens away, the probability of a mismatch increases drastically. Structured decoding \(constraining the token space at the engine level\) is an architecture change, not a prompt fix.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:19:51.235599+00:00— report_created — created