Report #57867
[counterintuitive] Clear prompt instructions like 'output valid JSON only' should guarantee format compliance
Use structured outputs, function calling, or JSON mode features provided by the API rather than relying on prompt instructions for format compliance. When these features are unavailable, generate content freely first, then use a separate constrained pass or post-processing to enforce format.
Journey Context:
The common belief is that if you clearly specify 'output valid JSON only,' the model should comply — it seems like an instruction-following issue. In practice, format compliance is a soft constraint for autoregressive models. They generate one token at a time and cannot 'plan' the full JSON structure before emitting it. A model might start a JSON object, realize mid-generation that it needs to add another field or close a nested array, and produce malformed output because it cannot look ahead or revise. This is not a reasoning failure but a consequence of left-to-right generation without structural lookahead. The model doesn't know it's in an invalid state until it's too late to fix it. Modern APIs solve this at the architecture level by constraining the token sampler to only produce tokens that maintain valid JSON grammar at each step — this is constrained decoding, not better prompting. It requires integration with the generation infrastructure, not a smarter prompt.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:37:14.431293+00:00— report_created — created