BroadRouter
Get started

JSON mode

Updated

JSON mode is an LLM API setting, response_format {"type": "json_object"} in OpenAI-style APIs, that makes the model's reply valid, parseable JSON. Unlike structured outputs with a JSON Schema, it does not guarantee which keys, types or values the object contains.

Also called: json_object, JSON output mode, JSON response mode

JSON mode answers one question: will json.loads() succeed? It does not answer the second: is this the object my code expects?

How it works

In the Chat Completions API you turn it on with one field:

{"response_format": {"type": "json_object"},
 "messages": [
   {"role": "system", "content": "Return JSON with keys name and email."},
   {"role": "user", "content": "Reach me at Sara, sara@example.com"}]}

OpenAI’s API reference calls this “the older JSON mode, which ensures the message the model generates is valid JSON.” Two rules come with it. You must ask for JSON in a message: OpenAI’s guide says the API “will throw an error if the string ‘JSON’ does not appear somewhere in the context.” And the shape is up to the model. The guide states that JSON mode “will not guarantee the output matches any specific schema.”

Structured output is the stricter option. It passes a JSON Schema with {"type": "json_schema", ...}, and the model is constrained to it.

JSON mode (json_object) Structured outputs (json_schema)
Valid JSON yes yes
Required keys and types no yes
You supply a schema no yes
Must mention “JSON” in prompt yes (OpenAI) no

OpenAI recommends “always using Structured Outputs instead of JSON mode when possible.”

Why it matters

  • Validation is still yours. With JSON mode, a missing key or a number sent as a string parses fine and fails later. Validate against a schema in code.
  • Truncation. If the reply hits max_tokens, the JSON is incomplete. Reasoning models are more exposed, since thinking uses the same budget.
  • Fallback. OpenAI’s guide lists JSON mode on older models where json_schema is not available. Support varies by provider and model, so JSON mode plus your own validation is the fallback when a schema is not accepted.

On BroadNet Inference

BroadNet’s API reference lists structured output for GLM 5.3 and Qwen3.8 27B. It does not say whether json_object or json_schema is the supported response_format, or whether DeepSeek V4.1 Flash and BroadNet Gemma 4 VL 26B accept either. Test both on your model. To write the schema, use the JSON Schema generator. The post JSON mode vs json_schema covers repair and monitoring, and the invoice guide shows JSON extraction from images.

Questions

Is JSON mode the same as structured outputs?

No. OpenAI's guide says both produce valid JSON, but only Structured Outputs ensure schema adherence. JSON mode can return any valid object.

Why does JSON mode return an error about the word JSON?

OpenAI requires the instruction to produce JSON somewhere in the messages and errors if the string "JSON" does not appear in the context.

Can JSON mode still return broken JSON?

Yes, if the reply is cut off by max_tokens or the context limit. Check finish_reason before parsing.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity