esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

JSON Mode vs Strict Structured Outputs

The difference between JSON mode and strict schema structured outputs, why a valid format is not a correct answer, and what your code must still check, for your AI interview.

In short

JSON mode makes the model return valid JSON, with no set shape. Structured outputs take a JSON Schema you supply and hold completed replies to it, but your code still checks refusals, cut-off replies and business rules.

10 min readIntermediateCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

JSON mode makes a model return valid JSON, so the reply should parse, but the field names and types can still be wrong. Structured outputs go further: you give a JSON Schema, and a completed reply has to match it. Neither one checks your business rules. On a card dispute form, I check the amount against the transaction in code, and I retry a cut-off reply.

What is the difference, in plain words?

JSON is a plain text format for data: keys, values and curly brackets that any program can read. Your app reads a reply with a parser, and a reply with a missing bracket makes the parser fail.

JSON mode is the basic setting. The model is kept to valid JSON, except in edge cases your code must detect and handle. A JSON Schema is a written contract for the shape: which fields exist, their types, and which are required. Structured outputs take that contract and hold completed replies to it.

Think of a bank's dispute form. JSON mode is a form the scanner can read. A strict schema is a form where each box takes only the right kind of answer. Neither form checks the figures against the account. That is the clerk's job, and in an AI system the clerk is your code.

Key words

JSON
A text format for data, written as keys and values in curly brackets.
JSON Schema
A written contract for a JSON reply: its fields, their types, and which are required.
JSON mode
The basic setting: the reply is meant to be valid JSON, and nothing more about its shape.
Structured outputs
A completed, non-refusal reply is held to a JSON Schema you supply.

How do the two modes differ?

Both aim at the same goal: your code gets data it can read. They promise different things, so say exactly what each one covers.

  • JSON mode

    Valid JSON only

    The reply should parse, but field names and types can still drift from what your code expects.

  • Structured outputs

    Completed replies match

    Required fields and enum values follow the JSON Schema you supply.

  • Which to use

    Structured, when you can

    OpenAI advises structured outputs over JSON mode when it is possible.

  • “While both ensure valid JSON is produced, only Structured Outputs ensure schema adherence.”

    OpenAI

  • “Without structured outputs, Claude can generate malformed JSON responses or invalid tool inputs that break your applications.”

    Anthropic

Two ways to get JSON, one check in code

Your request

asks for one answer as JSON

JSON mode

Valid JSON

keys and types can still drift

Structured outputs

Matches your schema

fields and enum values follow it

Your code

checks business rules the schema lacks

Used by the system

only after your checks pass

  1. 1JSON mode keeps the model to valid JSON, nothing more.
  2. 2Structured outputs hold completed replies to the JSON Schema you wrote.
  3. 3A JSON mode reply still needs its fields and rules checked.
  4. 4A schema reply still needs the same checks in your code.
  5. 5Only checked replies go on to the system.
JSON mode keeps the reply to valid JSON. Structured outputs also hold completed replies to your schema. Both still pass through your code, because neither knows your limits.

Where do replies still go wrong, and what does it cost?

A schema narrows the reply. It does not check the facts, and it does not cover every bad case. These are the gaps to name in an interview.

  1. 1

    The model refuses

    A refusal can come back instead of the schema, and it takes precedence over the schema. Check for it before you read any fields.

  2. 2

    The reply is cut off

    A reply that stops at the length limit may be incomplete and not match your schema. Treat it as a failure, and retry with more room.

  3. 3

    A word has the wrong capitals

    Enum values can come back with different capitals, such as Approved for approved. Anthropic's structured outputs do not guarantee capitalisation, so normalise in code or reject the reply.

  4. 4

    Your rules are not in the schema

    A schema cannot know your limits, like the original transaction amount or who may approve. Your code checks those.

  5. 5

    The first call is slower

    OpenAI and Anthropic both say the first use of a schema adds delay. Anthropic caches its compiled grammar for 24 hours from last use, so later requests are faster.

  • “Your application still needs to handle refusals, incomplete responses, and API errors, and validate any business rules that the schema does not express.”

    OpenAI

  • “The output might be incomplete and not match your schema.”

    Anthropic

Here is the check in plain Python. The model is not run. These are four replies a dispute bot might send, and the code decides what passes.

Python
# A card dispute bot proposes one form. The model is not run here;
# these are four replies it might send, and the code decides.
import json

TRANSACTION_AMOUNT = 120.00  # from the card system, never from the model
DISPUTE_TYPES = {"fraud", "duplicate", "not_received"}

REPLIES = [
    '{"transaction_id": "T-88121", "dispute_type": "fraud", "amount": 120.0}',
    '{"transaction_id": "T-88121", "dispute_type": "Fraud", "amount": 120.0}',
    '{"transaction_id": "T-88121", "dispute_type": "fraud", "amount": 540.0}',
    '{"transaction_id": "T-88121", "dispute_type": "fraud", "amou',
]

def check(reply):
    try:
        data = json.loads(reply)
    except json.JSONDecodeError:
        return "REJECT: cut off or not JSON, retry or ask a person"
    if not isinstance(data, dict):
        return "REJECT: not an object"
    if data.get("dispute_type") not in DISPUTE_TYPES:
        return "REJECT: unknown dispute type " + str(data.get("dispute_type"))
    amount = data.get("amount")
    if not isinstance(amount, (int, float)) or amount > TRANSACTION_AMOUNT:
        return "REJECT: amount missing or above the transaction"
    return "OK: dispute for " + str(amount)

for reply in REPLIES:
    print(check(reply))

Output

OK: dispute for 120.0
REJECT: unknown dispute type Fraud
REJECT: amount missing or above the transaction
REJECT: cut off or not JSON, retry or ask a person

Where a neat reply can still fail

Model reply

parses, and fits the schema, or not

Known ways to fail

Cut off at length limit

stops before the schema ends

Model refuses

a refusal can replace the reply

Wrong capital letters

Approved, not approved

Fits the schema

fields present, types right

Retry or ask a person

never pass a bad reply on

Check business rules

amount, dates, limits, approvals

Used by the system

only when every check passes

  1. 1A reply with one of the known problems goes this way.
  2. 2A reply with the right fields and types moves on.
  3. 3A bad reply is retried, or passed to a person.
  4. 4A reply that fits the schema still gets its rules checked.
  5. 5Only a reply that passes every check is used.
A schema match does not finish the job. Cut-off replies, refusals and wrong capitals go back for a retry or to a person. A reply that fits the schema still gets your business rules checked before anything uses it.

How would you choose for a card dispute form?

A card dispute bot fills in a form: the transaction, the dispute type and the amount. The card system accepts only up to the original amount, and the form is filed with it straight away.

  • Plain JSON, no checks

    Parses, then breaks later

    A capital letter or a sum above the transaction reaches the card system as if it were fine.

  • Schema and code checks

    Bad replies are caught

    The schema fixes the shape. Your code checks the amount against the transaction before anything is filed.

Tip

Say that the schema is not the last check. The amount rule lives in your code, where the model cannot change it.

What does the interviewer want to hear?

A strong answer covers

  • JSON mode means valid JSON. Structured outputs also hold completed replies to a schema you supply.
  • A schema fixes the shape, not whether the values are true.
  • Refusals, cut-off replies and business rules still need code.
  • Name the vendor feature you would use, and what it does not promise.
  • Mention the cost: structured outputs add delay on a schema's first call.

Common traps

  • Trap"JSON mode means the data is correct."

    BetterIt means the reply should parse. The field names and values can still be wrong.

  • Trap"A schema stops the model making things up."

    BetterA schema fixes the shape. A made-up number still fits a number field.

  • Trap"The schema handles every error."

    BetterRefusals, cut-off replies and business rules need checks in your code.

Can you spot the gap?

Spot the gap

Your schema says amount is required and must be a number. Which reply can still do harm?

Quick check

Your dispute bot is moving to structured outputs. What else does it need to be safe?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 5

What will they ask next?

  1. Q085How do you get reliable JSON output?12 min
  2. Q234How should an app handle refusals?Coming soon
  3. Q478Parse and validate LLM JSON, retrying on failure.Coming soon
  4. Q448How do you extract structured data from documents and images?Coming soon
  5. Q176How should an agent handle tool errors and retries?14 min

Learn it in depth

Last updated on 26 November 2026

Building a bot that fills in forms or records?

I design and build AI products and agents: the schema, the checks in code and the path to a person when a reply fails. Book a short call and tell me what your bot needs to write.