Report #92095
[counterintuitive] Why does the model sometimes produce invalid JSON or break output format despite explicit format instructions
Use structured output features \(JSON mode, structured outputs with JSON schema, function calling, constrained decoding\) rather than relying on prompting alone to enforce output format. When these aren't available, keep output structures simple and use a schema preamble.
Journey Context:
The belief is that clear instructions like 'output valid JSON' should be sufficient to guarantee valid output. The model generates tokens one at a time, each sampled from a probability distribution. There is always a non-zero probability of generating a token that breaks the format — a stray comma, an unclosed bracket, a newline in a string value, an unescaped quote. Prompting reduces but cannot eliminate this probability because the model has no built-in format validator during generation. Structured output features work by constraining the token sampling distribution at each step, making invalid tokens impossible to generate — this is a decoding-time intervention that overrides the model's token probabilities, not a prompting technique. It's the difference between asking someone to be careful and putting guardrails on the road.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:10:22.101860+00:00— report_created — created