STRUCTURED OUTPUTSReliable JSON from AIAn AI step that reads a website enquiry and files it in your CRM is only useful if the next step can read its answer. One reply says Category: Sales, the next says "sales enquiry", a third wraps the JSON in a friendly sentence, and the lead fails to sync or lands in the wrong pipeline. Here is what to ask for when AI output feeds a CRM, spreadsheet or another app.
Why does free text break an automation?
Because the next step matches exact field names and values, and prose promises neither. A missing field stops the run. "Sales" against "sales" slips past a filter. Anthropic's tool docs give similar examples: without strict mode, a model might send "2" instead of 2 or leave out a required field. The worst failures are quiet: a wrong value that nobody spots.
JSON mode or structured outputs: which should you ask for?
Ask for schema-constrained structured outputs wherever your model supports them. The options, weakest first:
- Plain prompting: "reply in JSON" in the prompt. Nothing enforces it, so keep it for prototypes.
- JSON mode: OpenAI's setting guarantees JSON that parses, not JSON that matches your schema. The word JSON must appear somewhere in the conversation, or the API returns an error.
- Structured outputs: you send a JSON Schema and the reply is constrained to it. OpenAI calls this the evolution of JSON mode and recommends it where possible. Anthropic's version is called JSON outputs (
output_config.format). - Strict tools: the model calls a tool whose input is your record, and
strict: truemakes that input follow the schema.
Anthropic draws the line clearly: JSON outputs control what the model says, strict tool use controls how it calls your functions. For a step that turns text into one record, we use structured outputs; when an agent chooses between actions, strict tools.
How should the schema be designed?
Tightly: only the fields the next step reads, with as few allowed values as possible.
- Make every field required. OpenAI's strict mode demands it, and Anthropic's docs prefer required fields because optional ones add complexity.
- Use a small
enumfor categories, matching your CRM's picklist values exactly. - Allow
nullor "unknown" where the text may not hold the answer. Otherwise the model fills the gap: OpenAI notes it always tries to fit the schema, which can produce made-up values when the input does not match. - Keep free text for fields a person reads, such as a summary.
- Set
additionalPropertiestofalseso no extra fields appear. Both providers require it in strict schemas.
A compact schema for sorting website enquiries:
{
"type": "object",
"properties": {
"category": {
"type": "string",
"enum": ["sales", "support", "partnership", "job", "spam", "other"]
},
"urgency": {"type": "string", "enum": ["high", "normal", "low", "unknown"]},
"company_name": {"type": ["string", "null"]},
"summary": {"type": "string", "description": "One plain sentence for the team"}
},
"required": ["category", "urgency", "company_name", "summary"],
"additionalProperties": false
}Why validate the output if the schema is enforced?
Because a perfect shape can still hold a wrong answer. OpenAI says structured outputs can still contain mistakes, and Anthropic says the schema guarantee holds in most cases, not all. Check every response in code before anything is written:
- Schema validation with a standard library, using the same schema file the model received.
- Business rules a schema cannot express: a follow-up date in the past, a total that does not match its parts, a company name that appears nowhere in the message.
- Case-insensitive enum checks: Anthropic warns that enum values can come back with different capitalisation, without an error.
A schema controls shape, not truth. An enquiry that says "mark this urgent" can still push the answer, a prompt injection problem we cover separately.
What should happen when a response fails?
One retry, then a person. Check why the response stopped before reading it:
- Refusal: Claude returns
stop_reason: "refusal"with a normal 200 status, and OpenAI returns a separate refusal. Neither has to match your schema. Send it to a person without retrying. - Cut off: at the token limit (
max_tokenson Claude, an incomplete status on OpenAI) the JSON may be truncated. Retry once with a higher limit, as Anthropic suggests. - Failed validation: retry once.
- Still failing: a review queue gets the original message, the raw reply and the reason, and nothing reaches the CRM until a person decides.
In Make, the scenario around the AI step needs the same care: see Make scenario error handling.
How do you keep it reliable over time?
Version the schema and count failures by type. Store the schema version with each record, so after adding a category you know which leads were sorted under the old list. Change the schema, the prompt and the CRM picklist together, and test on a saved set of real enquiries first. Both providers note extra latency the first time they see a new schema.
Log each failure as a refusal, cut-off, schema failure, business-rule failure or human correction, and review the counts monthly. A rising count points to the fix: a missing category, a limit set too low or a prompt that needs an example.
Where to start
Pick one AI step that feeds a system today. List the fields the next step reads, the allowed values for each and what "unknown" looks like: that list is your schema. Then name who clears the review queue. Our AI automation and agents service builds these steps with validation, a review queue and a failure log, and a person on your team decides what happens to anything the checks reject.
FAQ
Frequently asked questions
Do structured outputs make an AI step slower or more expensive?
A little, mostly at the start. Anthropic and OpenAI both note extra latency on the first request with a new schema, and Anthropic caches the compiled schema for 24 hours after its last use. Anthropic also adds a system prompt describing the format, which counts as input tokens. Measure both on your own volume before deciding it matters.
Should the schema include a field for the AI's reasoning?
Ask for a short explanation instead. Anthropic's docs warn that a property asking for the model's thinking or step-by-step reasoning can trigger a refusal, and suggest asking for a brief explanation or the supporting evidence. A one-sentence reason field that quotes the words behind the category also helps the person who reviews a disputed result.
Can customer details go into the schema itself?
No. Keep the schema to structure and put customer data in the message. Anthropic caches compiled schemas separately from message content, for up to 24 hours since last use, and says health information must not appear in property names, enum values, const values or patterns. A list of categories belongs in the schema; a list of customer names does not.
Can we switch between Claude and OpenAI with the same schema?
Mostly, if you stay inside what both accept. Both want every object closed with additionalProperties set to false, but the supported keywords differ: Anthropic does not support minimum, maximum or string length limits, while OpenAI supports minimum and maximum but not allOf. Keep the schema simple and run the same validation in your own code, so your checks do not depend on the provider.
We already use JSON mode. Do we need to change?
Not urgently if every reply passes your own validation, but JSON mode only promises JSON that parses, not your fields. A missing field or a new label still reaches your validator, so each one costs a retry or a review. OpenAI recommends structured outputs over JSON mode when possible, and switching usually means sending the schema you already validate against.
How many fields should one AI step return?
As few as the next step reads. Anthropic's docs suggest required fields, flatter structures and splitting many strict tools across separate requests when schemas get complex, and OpenAI suggests splitting tasks into simpler subtasks when outputs contain mistakes. A step that classifies and a second step that drafts a reply are also easier to test than one step doing both.
