Inference

JSON Mode

An API setting that forces an LLM to always output valid JSON, without enforcing a specific schema.

JSON mode is the simplest form of structured output. When enabled, the API guarantees the model's response is valid, parseable JSON. It does not constrain what keys or values are present - just that the output can be parsed with JSON.parse() without throwing.

JSON mode vs JSON Schema enforcement

JSON mode: valid JSON, any structure. JSON Schema: valid JSON matching a specific schema. If you need specific fields (e.g., {"summary": string, "sentiment": "positive" | "negative"}), JSON mode alone isn't enough - the model might output {"answer": "positive"} instead. Use full function calling / response_format with a schema for strict field requirements.

When JSON mode is sufficient

JSON mode works well when the prompt reliably produces a consistent structure and you want to guard against occasional formatting errors (stray text before the JSON, missing closing braces). For prototyping and lightweight extraction tasks, it's often the right tradeoff - simpler to prompt than a full schema.

Enabling JSON mode

OpenAI: response_format: { type: "json_object" }. Anthropic: use a tool call with no required parameters and parse the response, or use Anthropic's beta structured outputs. Always include "JSON" or the structure in the prompt itself - models without a prompt hint can produce empty objects.

Related terms

Models relevant to JSON Mode