Decoding & Sampling

JSON mode

JSON mode is constrained decoding aimed at one very common need: getting back data your program can read instead of a friendly paragraph. When you switch it on, the decoder is restricted to tokens that keep the output a syntactically valid JSON object — every brace matched, every string quoted, commas in the right places. Stronger versions take a schema you supply and guarantee the exact keys and value types too, so the response slots straight into your code.

Before this existed, developers begged models with prompts like 'reply only in JSON' and then wrote brittle parsers to clean up the strays. JSON mode removes that whole class of failure by making malformed output impossible at the decoding level. Two honest caveats remain: valid syntax is not valid meaning — the model can still put a wrong number in a correctly-shaped field — and forcing structure too early can crowd out the model's reasoning, so many setups let it think first and emit JSON only at the end.

Also called
structured outputJSON schema mode