AI tools helped gather research and write the first draft of this article. I edited it and checked every quote and figure against the source page listed at the end, read on 1 December 2026. The cover illustration is AI-generated. Details at the end.
When a chat assistant has to do something, not just say something, teams usually ask the model for a structured reply: a small JSON object with an action name and some fields. Model vendors now offer ways to make that object match a JSON Schema. That removes a whole class of broken replies. It does not make the reply the right one. A valid structure says the reply has the right shape. It does not say the action is the one the user asked for, that it is allowed, or that it should run now. Those checks belong to the application, and they are part of the same contract as the schema.
This article reads what three model vendors and the JSON Schema specification actually promise, walks a fictional example where every field is valid and the action is still wrong, and ends with a checklist. It is not a comparison of vendors.
What the schema promises
Start with the claims, in the vendors' own words.
OpenAI's structured outputs guide says: "Structured Outputs constrains completed, non-refusal model output to your supplied JSON Schema" [1]. The next sentence matters as much: "Your application still needs to handle refusals, incomplete responses, and API errors, and validate any business rules that the schema does not express" [1].
Anthropic's documentation says that "Structured outputs guarantee schema-compliant responses through constrained decoding", and lists "Always valid: No JSON parsing errors" and "Type safe: Guaranteed field types and required fields" [2]. Its page on strict tool use says that setting strict to true "guarantees Claude’s tool inputs match your JSON Schema" [3]. The guarantee there is about the match to the schema.
Google's Gemini documentation describes structured output as making responses "adhere to a provided JSON Schema", and its best-practices list says: "While output is syntactically correct JSON, always validate values in your application" and "Implement robust error handling for schema-compliant but semantically incorrect outputs" [4].
Read together, the three say the same thing from different angles. The schema constrains the form. Whether the content is right is a separate question that the vendors leave to you. None of them claims otherwise. The risk comes from a team reading "guarantees" and hearing "correct".
A fictional example: valid, and still wrong
The following example is invented. Example Wallet is a made-up app with a chat assistant, and EMBER is a made-up token. Nothing here describes a real product.
The assistant has one action, a token transfer. The schema requires four fields: an action name that must be transfer, a token from a fixed list, an amount that is a number greater than zero, and a recipient address that is a string. A user types: "Send 5 EMBER to Mia." The model replies with an object that passes every rule in the schema. Here is what the application should still ask about each field:
| Field | Value in the reply | What the schema confirmed | What the application must still check |
|---|---|---|---|
| action | transfer | It is the one allowed name | Is a transfer what the user asked for? |
| token | EMBER | It is in the list | Does this user hold EMBER? |
| amount | 500 | A number above zero | The user said 5. Is 500 within the balance and any limit? |
| recipient | a well-formed address | A string | Is it the address saved as "Mia", or a different one? |
Every cell in the third column is true, and the reply is still unsafe to execute. The amount is a hundred times what was requested, and the address looks like an address but is not the one saved for the contact. A schema has no way of knowing either, because neither is a property of the shape. This is what Gemini's phrase "schema-compliant but semantically incorrect" describes [4].
A second case needs no mistake by the model at all. The user writes: "What would a transfer of 5 EMBER to Mia cost?" The model, asked to answer in the transfer format, produces a transfer object. OpenAI's guide names this pressure: "The model will always try to adhere to the provided schema, which can result in hallucinations if the input is completely unrelated to the schema" [1]. A reply format that has no way to say "this is a question, not a command" can turn any message into a command.

What the vendors say can still go around the schema
The documentation lists the exceptions itself. They are worth knowing by name, because each one is a case where the code that receives the reply cannot assume the schema was applied.
Refusals. OpenAI notes that "a refusal does not necessarily follow the schema you have supplied", so the response carries a separate refusal field [1]. Anthropic describes the same case: with a stop reason of refusal, "The output might not match your schema because the refusal message takes precedence over schema constraints" [2].
Truncation. Anthropic's page says that if the response reaches the token limit, "The output might be incomplete and not match your schema" [2]. A reply cut off in the middle of an object is not a smaller version of the right answer.
Constraints that are not enforced. Gemini's page lists keywords such as minLength, maxLength, uniqueItems and contains as "not enforced by the constrained decoding grammar engine", says the API strips them, and tells you to validate those yourself, for example with Pydantic or Zod [4]. A schema generated from a typed model may contain constraints that read like rules but are not applied when the model generates. Vendors support a subset of the language: Anthropic's page says "some limitations" [2] and Gemini's limitations list begins with "Schema subset" [4].
Details of values. Anthropic notes that structured outputs "don’t guarantee the capitalization of string enum and const values", and its advice is: "Compare enum values case-insensitively" [2].
Plain mistakes. OpenAI says it directly: "Structured Outputs can still contain mistakes" [1].
The vendors say where their promise ends, and the application's job starts there.
What the specification itself says
JSON Schema is not a language for correct decisions. It is a language for describing the structure of data. The validation specification says that "JSON Schema validation asserts constraints on the structure of instance data" [5]. The same document says, in its section on the format keyword: "Structural validation alone may be insufficient to allow an application to correctly utilize certain values" [5].
The format keyword is a good example. A schema can say that a string has a format such as an email address or a date. In the specification's format-annotation vocabulary, the value is collected as an annotation. An implementation may also treat it as an assertion, but it "MUST provide options to enable and disable such evaluation and MUST be disabled by default" [5]. In other words, whether a "valid" date is checked at all depends on the library and its settings. Whether a recipient string is well formed is a question about syntax. Whether it is the right recipient is not a question the specification asks.
The specification text is an Internet-Draft dated 16 June 2022, and the vendors support only part of the language [2][4]. Treat the schema as a statement of shape, and claim no more for it.
A contract has more than one layer
A useful way to think about an action reply is as a contract with layers, each checked by something different:
- Syntax. Is it parseable JSON? Constrained generation largely handles this.
- Schema. Do types, required fields and enum values match? Also largely handled, within the supported subset.
- Business rules. Is the amount within the balance and the limit? Does the token exist for this user? Does this recipient belong to this user? The schema cannot express most of these, and OpenAI's guide names them as the application's job [1].
- Intent. Does the action match what the user asked for? This is the "500 instead of 5" layer. It is checked by comparing the reply with the request, by a rule, or by asking the user.
- Authorization and timing. Is this action permitted here, and is it ready to run now, or does it need the user's confirmation first? A persuasive model reply is not an authorization.
The model produces a proposal. Code decides whether the proposal passes layers 3 to 5. In a design where the reply is checked only for layers 1 and 2, the model's output is effectively the command.

Shrink what the model has to say
The best check is a field the model never fills. OpenAI's function-calling guide gives a concrete rule: "Don’t make the model fill arguments you already know" [6]. Its example: if an order identifier is already known from a previous step, define a refund function with no parameters and pass the identifier in code [6]. The same page advises: "Use enums and object structure to prevent invalid states", with a light switch function that takes separate on and off flags as an example of a call that can be invalid [6].
Applied to the wallet: if the application already holds a resolved contact for "Mia", the model need not produce an address at all. It can name the contact, and code looks up the saved address. A field that comes from a lookup cannot be invented by the model. A model that picks from a short list of saved contacts can still pick the wrong contact, but the failure is then visible and checkable, and it cannot produce an address that was never saved.
Give the reply a way to say "no action"
OpenAI suggests telling the model what to do when the input cannot produce a valid response, such as returning empty parameters or a specific sentence [1]. The design consequence, which is the author's proposal and not a vendor requirement, is to put that option inside the schema. Make the action field an enum with a value such as none or clarify, and add a short reason field. Then a question, an unclear request or an out-of-scope message has a valid reply that is not an action.
The same applies to the reply that is not a normal object at all. Branch on the stop reason before parsing: refusals and truncation come with their own signals in the documentation [1][2], and the code should treat them as their own outcomes, not as parse errors to be retried blindly. How to retry safely, without repeating an action the user asked for once, is a separate question for the next article in this series.
A checklist to adapt
This is the author's proposal, not an industry standard. Before an action reply can run:
- Branch first. Check the stop reason and any refusal field before reading the content.
- Validate again. Run the schema check in your own code, including the constraints the API does not enforce [4].
- Compare with the request. Does each value come from what the user said or from a lookup? Flag any number or recipient that does not.
- Check the rules the schema cannot express. Balance, limits, ownership, allowed times.
- Confirm what is hard to undo. Show the resolved values to the user in plain words before an action that moves value or cannot be reversed.
- Test the failures. Keep a small set of fixed examples, such as the amount that is too large, the unknown recipient, the truncated reply and the question that looks like a command, and run them each time the schema or prompt changes.
A schema that passes can still be wrong, so the test set should include replies that pass the schema and must still be rejected. If the set only contains broken JSON, it measures the layer the vendor already covers.
What this article does not settle
It does not tell you how often models produce valid but wrong actions. None of the sources reports a rate, and the example is invented. It does not compare vendors: the quotes show what each page says, not how the features perform. It does not describe how any specific product builds its checks. The five layers and the checklist are a proposal. The JSON Schema page read is a 2022 draft, and vendor documentation changes; the quotes are as read on 1 December 2026.
How this article was made
| Task | What the AI did | What a person did | How it was checked |
|---|---|---|---|
| Research | Gathered candidate sources and drafted notes | Chose the question and which pages to rely on | Every quote checked against the page named in the sources, downloaded as raw text on 1 December 2026 |
| Draft | Wrote the first draft from the notes | Edited the text, the example and the checklist | An independent review compares claims with the sources before publication |
| Images | Generated the cover illustration | Chose and checked it | Labelled as AI-generated in the disclosure line and alt text |
| Not done by AI | — | The decision to publish and responsibility for the text | — |
Conflicts of interest: none. The author has no commercial relationship with the organisations named here.
Responsible for this article: Dmitriy Lastovka, author. Corrections: contact form.
Sources
Labels: documentation (a vendor's product documentation), specification (a draft standard). Quotes are as on the pages read on 1 December 2026.
- OpenAI, "Structured model outputs" (API guide). https://platform.openai.com/docs/guides/structured-outputs Documentation.
- Anthropic, "Structured outputs" (Claude Platform docs). https://docs.anthropic.com/en/docs/build-with-claude/structured-outputs Documentation.
- Anthropic, "Strict tool use" (Claude Platform docs). https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/strict-tool-use Documentation.
- Google, "Structured outputs" (Gemini API docs). https://ai.google.dev/gemini-api/docs/structured-output Documentation.
- IETF Internet-Draft, "JSON Schema Validation: A Vocabulary for Structural Validation of JSON" (draft-bhutton-json-schema-validation-01, 16 June 2022), as served by json-schema.org. https://json-schema.org/draft/2020-12/json-schema-validation Specification (draft).
- OpenAI, "Function calling" (API guide). https://platform.openai.com/docs/guides/function-calling Documentation.










