Resources

What Is Structured Output (JSON Schema) and Why Automate With It?

Structured output means asking an AI model to reply in a fixed, machine-readable format, usually JSON that follows a schema you define, instead of free-flowing prose. It matters for automation because software cannot reliably read a paragraph, but it can read a field called invoice_total. If the AI's answer feeds another system, structure is what turns a clever chat reply into a dependable step in a workflow.

Why free text breaks automation

Imagine you ask Claude to read a supplier email and tell you the delivery date. A person is happy with "It looks like they're promising delivery by the end of next week." A spreadsheet, a database or an approval workflow is not. It needs a date in a known format, in a known place, every single time.

Free text varies from run to run: different wording, extra commentary, a polite opening line. Each variation is a chance for the next system in the chain to fail. Structured output removes that variation by agreeing the shape of the answer in advance.

What a schema is, in plain terms

A JSON schema is a written description of the answer you will accept. It lists the fields, what type each one holds (text, number, true/false, a list, one choice from a fixed set) and which fields are required. Think of it as a form the AI must fill in, rather than a blank page.

A simple example for processing customer enquiries might define:

  • category: one of "billing", "delivery", "technical" or "other"
  • urgent: true or false
  • summary: a short piece of text
  • order_number: text, or empty if the customer did not give one

Whoever receives the result, whether a ticketing tool or a dashboard, knows exactly what to expect.

Designing a schema that works

Most failures come from the schema, not the model. A few habits help:

  1. Use fixed choices where you can. A field limited to four categories is far easier to route than free text that might say "billing issue", "payments" or "invoice problem".
  2. Allow "not found". If a field can legitimately be missing, mark it optional or nullable. If you force a required order_number and the email does not contain one, the model is pushed to invent a plausible-looking value. A nullable field gives it an honest way to say there is nothing there.
  3. Keep it small. Ask only for the fields a downstream step will actually use. Every extra field is another place for error.
  4. Name fields clearly and describe them. A short description beside each field removes ambiguity about what you mean by "date" or "amount".
  5. Separate facts from judgement. Extracted facts (a date quoted in the email) and the model's interpretation (the customer seems annoyed) are different kinds of data. Keep them in different fields.

A well-formed answer is not always a correct answer

This is the point people most often miss. A schema fixes the shape of the reply, not the truth of its contents. The model can return perfectly valid JSON in which the delivery date is wrong. Structure solves the formatting problem; it does not replace checking. Our guide on how to check if AI output is accurate covers the verification side, and what an AI hallucination is explains why confident-looking answers can still be wrong.

Validate, then retry with feedback

A sound automation does not trust the reply blindly. After the model responds, your code checks it against the schema and against simple business rules: is the date in the future, does the total match the line items, is the category one of the allowed values?

When a check fails, a common pattern is to send the failure back to the model along with the original request, for example "the date field was not a valid date; please correct it", and ask again, for a limited number of attempts. This validation-and-retry loop fixes many one-off slips. Two cautions:

  • Retries cannot fix missing information. If the source document never mentions the delivery date, asking again will not produce it. That is where the nullable field earns its place.
  • Cap the attempts. After a few failures, send the item to a person instead of looping forever. That is a simple form of human in the loop.

Where structured output is useful at work

  • Pulling fields from invoices, quotations, forms or emails into a spreadsheet or accounting tool
  • Classifying and routing customer messages to the right team
  • Tagging documents or feedback so they can be counted and filtered
  • Producing the inputs for an automated workflow where a later step is plain code, not a person

If your use is a person reading the answer, such as a draft email or a summary, free text is usually better. Use structure when a machine is the reader.

What to learn next

Schema design, prompting for consistent output and reliable pipelines are part of what people build in the Claude Certified Architect (CCAR-F) path, which Agmo Studio, a Select Partner of the Anthropic Claude Partner Network, prepares people for through exam-preparation workshops. The certification itself is issued by Anthropic. See the CCAR-F workshop, look up unfamiliar terms in the glossary, or browse our wider AI training in Malaysia programs.

Common Questions

FAQ

What is structured output in AI?
It is a way of getting an AI model to reply in a fixed, machine-readable format, usually JSON that follows a schema you define, so other software can use the answer reliably.
Does a JSON schema make the AI's answer correct?
No. A schema fixes the shape of the reply, not that the values are true. You still need validation rules and, for important decisions, human review.
Why should some schema fields be nullable?
If the source material may not contain a value, a nullable field lets the model say so. A required field pushes it to invent a plausible value instead.
Do I need to code to use structured output?
Building it into an automated workflow usually involves some technical setup, but business teams can still help define which fields, categories and checks the workflow needs.

Questions about AI training for your team?

Message us on WhatsApp or email — we'll point you to the right program.

Chat With Us on WhatsApp Email Us