When OpenAI tested how well its models follow complex JSON schemas, the model with Structured Outputs switched on matched the schema 100% of the time. An older model working from its prompt alone, gpt-4-0613, scored less than 40% on the same evals.
A person reading an AI reply forgives a chatty sentence or a date written as "next Thursday". A CRM, a calendar or a billing script expects a field called email with an email in it, a date in one fixed format and an amount as a number. When the reply arrives as a friendly paragraph, the script either fails or saves the wrong thing.
In short.
- Free-text AI replies break the software that receives them, even when they read well.
- A JSON Schema tells the model exactly which fields, types and values are allowed.
- Strict mode uses constrained decoding so the reply fits that schema, refusals and cut-off replies aside.
- You still need null or "unknown" options for missing facts, and your own checks on the values.
Free text reads well to people and breaks the software behind them
Say a customer emails to move their Tuesday appointment, and you ask a model to pull out the details for your booking system. A typical free-text answer starts with "Sure!" and then describes the request in a sentence. Your calendar needs a customer ID, a date, a time slot and a reason, each in its own field, and it gets none of them in a form it can read.
Developers have long patched this with careful prompts, open source parsers and repeated retries. OpenAI lists all three as the workarounds that Structured Outputs was built to replace. Its earlier JSON mode made replies valid JSON, but it did not promise that the JSON had the fields your system expects.
Anthropic's own example is a booking system that needs the number of passengers as a whole number. Without strict mode the model might send "two" or "2" as text, and the booking code that expects the number 2 throws an error.
A JSON Schema turns the model's answer into a form with fixed fields
JSON is the plain text format most software uses to pass data to other software. A JSON Schema is the rulebook for one piece of that data. It names every field, says what type each one holds and lists which fields are required.
It can also close the list of allowed values. A lead status can be limited to new, qualified, lost or unknown, so the model can never invent "warm-ish". A setting called additionalProperties, switched off, stops the model adding fields nobody asked for.
Think of the schema as the paper form your team already fills in, written down so a machine can enforce it.
Constrained decoding blocks every character that would break the schema
A language model writes one token at a time, and by default it may pick any token in its vocabulary. That freedom is how a stray brace or a chatty preamble slips in. Constrained decoding removes every token that would break the schema before the model picks the next one, so the finished reply cannot break it.
OpenAI does this by turning your schema into a grammar, a set of rules for which characters may come next. Training alone took its model to 93% on its benchmark, and the grammar closes the rest of the gap. The trade-off is a short wait the first time a new schema is used, while the grammar is built. Anthropic caches the compiled grammar for 24 hours from last use, so later requests skip that wait.
OpenAI, Anthropic and Google all offer this. OpenAI and Anthropic switch it on with a strict setting, for both direct answers and tool calls, and Google's Gemini API accepts a JSON Schema for its replies too.
Same request, two replies, and only one reaches your system
Case 01
A date written as next Thursday afternoon
Free text gives a phrase your calendar cannot parse. A schema field typed as a date returns one fixed format, and a time slot chosen from your own list.
Case 02
A quantity written as two
Free text may spell the number out or wrap it in quotes. A field typed as an integer returns 2, and the booking code runs.
Case 03
A lead status your CRM has never seen
Free text says the lead seems keen but wants to wait. A status limited to new, qualified, lost or unknown returns one of those words, and your pipeline report stays clean.
Case 04
A phone number that is not in the email
Free text may skip it or copy a number from the signature of someone else. A field that allows null returns null, and the workflow asks a person to call.
Case 05
A friendly sentence before the data
Free text opens with "Sure, here are the details", and the parser stops at the first word. Strict output starts at the opening brace and ends at the closing one.
Escape hatches stop a strict schema from forcing a guess
With OpenAI's Structured Outputs, every field must be marked as required, and the model returns a value for each one. If the customer never gave a phone number, a required text field leaves the model one way out, which is to fill the box with something.
OpenAI's guide shows how to emulate an optional field with a type that allows null, and Google gives the same advice for fields that can be empty. For lists of values, add "unknown" as a choice so the model never has to pick the nearest wrong one.
Then decide what the workflow does with each null and each "unknown". Usually that means a person gets a short task, such as confirming a date or calling for the missing number. Our guide to how AI tool use works for business tasks covers where those handoffs sit when the model is also taking actions.
Valid JSON can still carry the wrong value, so check it before it lands
A schema guarantees shape, and the values inside can still be wrong. Google's own docs tell developers to plan for replies that match the schema but are wrong in meaning, and to validate values in their own code.
Gemini strips minimum and maximum text lengths out of the schema rather than enforcing them. Anthropic notes that a reply cut off at its token limit, or a refusal, might not match the schema, and that capital letters in fixed values are not guaranteed.
So keep a short check layer between the model and your system. Check that the date is in the future, the customer ID exists and the amount sits inside the range you actually charge. Anything that fails goes to a person, along with the original message.
Start with the form your team retypes most often
You do not need a big project to try this. Pick the one message type your team copies into another system by hand, such as booking requests, supplier invoices or new enquiries.
Write down the fields the receiving system needs, with the type of each and the allowed values. Mark which ones can honestly be missing, and give them null or "unknown". Switch strict mode on, run a batch of real messages through it, and read every null and every rejected value. Those tell you whether the schema is wrong or the messages are.
If you are weighing this against other ways to automate the same job, compare where an AI step earns its place and where a plain form or rule does better.
We can build the schema, the checks and the hand-off with you
Our AI transformation and Workflows work covers custom apps, bots and automations built around your process, with a human hand-off wherever a person should step in. That includes the schema, the checks and the monitoring after launch.
Book a consultation and bring the form your team retypes most.



