Skip to main content
Set response_format: {"type": "json_object"} and the model’s output is constrained while it generates, the response parses as JSON every time, with no markdown fences and no prose preamble. Every model in the catalog supports it, including the reasoning models.

Syntax is guaranteed, your schema is not

JSON mode promises valid JSON of some shape, not your shape. Left without instructions, a model may invent its own keys. The reliable pattern has three parts: spell out the exact keys in the prompt, enable JSON mode, and validate the result before using it:
When validation fails, retry once with the validation error appended to the conversation, models are good at repairing a named mistake. The stricter json_schema response format (server-enforced schemas) is not available yet, so client-side validation is the contract.

Pitfalls

  • Truncation. If max_tokens cuts generation off, you get invalid JSON with finish_reason: "length", check it before parsing, and size max_tokens for your largest expected object.
  • Example contamination. Models copy example JSON from the prompt very literally, keep any inline example minimal and syntactically perfect, or describe the keys in words instead.
  • Streaming. JSON mode streams like any response, but the object is only parseable once complete, accumulate deltas and parse at the end.
  • Numbers as strings. If a field must be numeric, say so explicitly (“age (number, not a string)”), and let your validator coerce or reject.
Extraction tasks run fine on the smaller models, start with GLM-5.3 Flash and keep the bigger models for inputs that need judgment, not just parsing.