Report #26785
[counterintuitive] Model outputs invalid JSON or violates output schema despite explicit formatting instructions
Use constrained decoding \(structured outputs, JSON mode, function calling\) instead of prompt-based schema enforcement. When unavailable, generate output then validate programmatically and retry with the specific validation error message.
Journey Context:
Prompting 'output valid JSON' works most of the time but fails unpredictably. The model generates tokens left-to-right with no ability to backtrack. Once it generates a token that breaks the schema, it is committed and will continue generating plausibly but invalidly. This is not a reasoning failure—it is a fundamental property of autoregressive generation without constrained decoding. Constrained decoding solves this by restricting the vocabulary at each step to only tokens that maintain grammatical validity. This requires integration with the inference engine, not better prompting. The practical lesson: if schema adherence matters \(and for coding agents it almost always does\), use the structured output feature of the API. Prompt-based enforcement is a fallback, not a primary strategy.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:21:28.758135+00:00— report_created — created