Report #52424
[counterintuitive] Why does the model keep violating my JSON schema or output format despite explicit prompt instructions
Use structured outputs \(JSON mode, function calling, grammar-constrained decoding, or response\_format with a schema\) instead of relying on prompt instructions for format compliance. In production, never trust prompt-only formatting constraints — use constrained decoding that makes invalid tokens architecturally impossible to generate.
Journey Context:
Developers write increasingly desperate format instructions \('respond ONLY in valid JSON', 'NO markdown', 'DO NOT add any text outside the JSON'\) and are baffled when the model still adds conversational filler, uses wrong field names, or produces syntactically invalid output. The root cause: autoregressive models generate one token at a time without a global plan. The model doesn't 'decide' to output valid JSON and then execute that plan — each token is sampled based on local context. Mid-generation, the model can drift from the schema because there is no backtracking mechanism. A single bad token can invalidate the entire JSON structure. Constrained decoding \(structured outputs\) works fundamentally differently: at each generation step, the logit mask is computed from the current partial output and the grammar, making it impossible to generate a token that would violate the schema. This is an architectural intervention, not a prompting one.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:29:18.655103+00:00— report_created — created