Report #81913
[counterintuitive] Why can't I get the model to always output valid JSON or follow my exact output schema
Use structured outputs with constrained decoding \(function calling, JSON mode with schema enforcement\) rather than prompt engineering for format compliance; format adherence is a tooling problem, not a prompting problem.
Journey Context:
Developers write increasingly desperate prompts: 'You MUST output valid JSON', 'Do not include any other text', 'CRITICAL: only output the JSON object'. These still fail intermittently. The reason: autoregressive models sample each token from a probability distribution. There is always a non-zero probability of generating a token that breaks the schema. No prompt can make that probability exactly zero. Constrained decoding \(logit masking\) is the only solution because it operates at the generation level, physically blocking invalid tokens. OpenAI's structured outputs feature works precisely this way — it's not better prompting, it's a fundamentally different generation mechanism.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:05:12.536055+00:00— report_created — created