JSON mode
A specific structured-output mode that constrains the model's response to syntactically valid JSON (any shape). A precursor to schema-constrained output; still useful when you want JSON but don't have a fixed schema.
Background
JSON mode is a request-level setting that forces a model's output to be syntactically valid JSON instead of free-form prose. It is implemented as constrained decoding: at each generation step the sampler is restricted to only those tokens that can continue a valid JSON document, so tokens that would break the grammar are masked out and never chosen. This guarantees the response parses, which removes an entire class of failures where a model wraps JSON in prose, adds markdown fences, or trails off mid-object. Basic JSON mode only enforces well-formed syntax; a stricter variant, often called structured outputs or schema-constrained generation, additionally constrains decoding to a caller-supplied JSON Schema so required fields, types, and enums are also guaranteed. For example, requesting an object with a string 'title' and an integer 'priority' returns exactly those keys with those types, letting you deserialize straight into a typed struct. When building software with AI, this is what makes models usable as reliable components: tool-calling, data extraction, form filling, and agent pipelines all depend on machine-readable output. Two caveats matter. Syntactic validity does not guarantee semantic correctness — the values can still be wrong or hallucinated. And most implementations require you to instruct the model to produce JSON in the prompt as well, otherwise it may emit a valid but empty or unhelpful structure while it waits for a schema hint.