Report #93317
[counterintuitive] Just prompt the model to output valid JSON and it will consistently work
Use constrained decoding \(JSON mode, structured outputs, grammar-based generation\) for any production structured output. Never rely on prompt engineering alone for format compliance in production systems.
Journey Context:
Developers believe that specifying 'output valid JSON' in a prompt is sufficient. In practice, models frequently produce invalid JSON—missing commas, trailing commas, unescaped quotes in strings, premature structure closure, or breaking out of JSON entirely during long outputs. The model generates token-by-token with no mechanism to ensure structural integrity. Each token is predicted independently, and there is no backtracking when a structural error is made. A single bad token invalidates the entire output. Constrained decoding forces the model to only generate tokens that maintain valid structure, which is a fundamentally different mechanism than asking nicely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:13:06.083592+00:00— report_created — created