Inference

JSON Mode

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

JSON mode is the simplest form of structured output. When it is on, the API makes the model return syntactically valid JSON. It does not control which keys or values appear, only that a complete response parses with JSON.parse() without throwing.

JSON mode vs schema enforcement

JSON mode produces valid JSON with any structure. Schema enforcement (structured outputs) constrains the JSON to a specific JSON Schema. If you need specific fields (for example, {"summary": string, "sentiment": "positive" | "negative"}), JSON mode alone is not enough: the model might return {"answer": "positive"} instead. OpenAI's documentation recommends using Structured Outputs instead of JSON mode whenever possible.

When JSON mode is sufficient

JSON mode works when your prompt reliably produces a consistent structure and you mainly want to guard against formatting errors such as stray text around the JSON. It suits prototyping and lightweight extraction, and it accepts any structure, including ones that are awkward to express as a schema. It can still fail in one way: if the response hits the output token limit, the JSON is cut off. OpenAI marks these responses as incomplete with the reason max_output_tokens, so check the status before parsing.

Enabling JSON mode

  • OpenAI: text: { format: { type: "json_object" } } in the Responses API, or response_format: { type: "json_object" } in Chat Completions. The API returns an error if the word "JSON" does not appear somewhere in the context, and without an instruction to produce JSON the model can emit whitespace until it reaches the token limit.
  • Mistral: response_format: { "type": "json_object" }. Mistral also recommends asking for a JSON object and describing the format in the prompt.
  • Anthropic: The Claude API has no schema-free JSON mode. It offers schema-enforced structured outputs (output_config.format) and strict tool use instead, which give stronger guarantees.

Whatever the provider, describe the expected structure in the prompt itself, ideally with an example.

Related terms

Models relevant to JSON Mode