Report #75389
[counterintuitive] Instructing the model to 'always respond in valid JSON' in the system prompt reliably produces parseable JSON
Use constrained decoding \(OpenAI Structured Outputs with json\_schema, Guidance, Outlines\) instead of prompt-based formatting instructions for any production JSON output.
Journey Context:
The model generates one token at a time, each chosen independently based on the preceding context. It has no mechanism to ensure structural completeness — no way to 'know' that it needs to eventually emit a closing bracket to balance an opening one. It's producing the most likely next token that resembles JSON, not generating from a JSON grammar. As output length grows, the probability of at least one structural error approaches 1. Prompt instructions reduce error rates but never eliminate them because the model has no structural state machine. Constrained decoding masks the model's vocabulary at each step to only tokens valid under the current grammar state, making invalid output structurally impossible.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:08:30.527105+00:00— report_created — created