Forces the model to output valid JSON instead of free-form text.
JSON mode constrains the model output to be valid JSON. This eliminates the need for fragile regex parsing. Some providers go further with "structured output" mode, where you provide a JSON Schema and the output is guaranteed to conform to it.
During token generation, the model applies a grammar constraint that only allows tokens forming valid JSON. This happens at the logit level, masking out tokens that would break JSON syntax. With schema-constrained output, additional constraints ensure required fields are present.
Any time you need to parse model output programmatically. Data extraction from unstructured text. Building APIs where the response feeds directly into your application. Generating database records or configuration files.
Using JSON mode without specifying what JSON structure you want. Not using structured output when available. Requesting deeply nested JSON structures that the model struggles with.
Available in OpenAI GPT-4o+ (json_object mode + structured outputs), Anthropic Claude 3+ (tool_use with schema), Google Gemini (responseSchema parameter).