Report #65564
[counterintuitive] Instruct the model to output valid JSON or a specific structured format and it will comply reliably
Use constrained decoding—JSON mode, structured outputs, grammar-constrained generation—rather than relying on prompting alone to enforce output format. Prompting for format is a suggestion; constrained decoding is a guarantee.
Journey Context:
Adding 'output valid JSON only' or 'respond in the following XML format' to a prompt feels sufficient because models usually comply on short, simple outputs. But prompting-based format control is inherently unreliable: the model generates tokens probabilistically and can drift from the requested format, especially in longer outputs or when the content itself is complex. A single unescaped quote or missing bracket breaks downstream parsing. The widespread practice of wrapping format instructions in increasingly emphatic prompting \('YOU MUST output ONLY valid JSON, no other text\!'\) is a category error—it treats a structural constraint as a content instruction. Constrained decoding restricts the model's token choices to only those that maintain valid structure during generation. 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-20T16:32:10.582751+00:00— report_created — created