What JSON mode guarantees and what it does not

L1ScreenConcept6 minScreenML breadth

RolesLLM Product EngineeringAgent Systems EngineeringDeveloper Experience and Education

The question

A teammate turned on the provider's JSON mode and says the extraction output is now guaranteed. What does JSON mode guarantee, what does it not, and what do you turn on instead?

Answer it first, aloud or on paper. Then open the answer.

The answer

Show short answer

JSON mode guarantees that a finished output parses, nothing more; a response cut at the token limit can still fail, so check the finish reason first. It does not guarantee your keys, your types, your enum values or the absence of extra fields. Turn on the schema mode, where the provider takes a JSON Schema and constrains decoding to it, and keep a check on your side for the values that a schema cannot judge.

Show full answer

Four levels of control

LevelGuaranteeTypical failure
A prompt that says "respond in JSON"none; about 90 percent validcode fences, preamble text, truncation, wrong structure
JSON modevalid syntaxextra keys, wrong types, missing fields
Schema modethe output conforms to your schemaa wrong value with the right type, or a refusal
Constrained decodingevery token is valid for the schemathe same as schema mode; this is how schema mode is built

The constrained decoding lesson is blunt about it: pure JSON mode guarantees valid JSON, not JSON that is valid for your use case, so always provide a full schema.

What strict schema mode asks of you

The structured output lesson lists the strict mode rules: every property appears in required, additionalProperties is false everywhere, and there is no unresolved reference. A schema that breaks these is rejected at request time with a 400.

What stays with you

Under strict enforcement two failures disappear for a response that finishes, the parse error and the schema violation. A response cut at the token limit can still fail to parse, so check the finish reason before you read it. Two more remain. The model can refuse when the input does not fit the schema, which your code treats as a typed outcome. And the model can fill a field with a value that has the right type and the wrong content; no format layer sees that.

Follow-ups

  1. L1ScreenWhich failure remains under strict schema mode?

    Show expected answer

    a refusal, when the model decides the input does not fit the schema; handle it as a typed outcome, and route a response cut at the token limit to the error path.

  2. L2WorkingWhat does strict mode demand of the schema?

    Show expected answer

    every property required, additional properties forbidden, no unresolved references; otherwise the request is rejected with a 400.

  3. L2WorkingThe output matches the schema and the price is wrong. Which layer failed?

    Show expected answer

    none of the format layers; the value is invented, and only a semantic check or an eval catches that.

  4. L3SeniorA field is sometimes unknown in the source text. How do you write the schema?

    Show expected answer

    allow null or a sentinel; a grammar that forces a value makes the model invent one, such as a date.

Wrong answers

Show the wrong answers that interviewers hear
  • “JSON mode means the keys match my model.”

    It only guarantees syntax; extra keys, wrong types and missing fields still happen.

  • “Adding 'respond in valid JSON' to the prompt is the same thing.”

    A prompt-only approach is about 90 percent reliable and fails with fences, preambles and truncation.

  • “With schema mode I can drop validation.”

    A schema cannot catch a wrong value with the right type; keep a semantic check.

Taught in

The lesson structured outputs lays out the four levels, the lesson constrained decoding warns against JSON mode without a schema, and the lesson structured output gives the strict mode rules.