
Does structured output enforce the constraints in your JSON schema?
Unity Horizon7 min read
Its shape only. One pydantic model sent seven constraints through OpenAI's SDK and one through Anthropic's, which moved the other six into a description.
Its shape only. Constrained decoding guarantees the field names, their types, the required list, and nothing past that. You did not write a loose schema. The client sent a loose one.
The values inside those fields are a different question. The Claude API rejects minLength with a 400. The Gemini API strips it server-side and carries on. The official Claude SDKs delete it from your schema and paste it into a field description before the request leaves your machine.
We put one pydantic model with seven constraints through two SDKs. Seven reached OpenAI's wire schema. One reached Anthropic's.
Everything below was checked by Unity Horizon on 2 December 2026, against the vendor documentation and the library code linked in place.
What does constrained decoding guarantee?
Anthropic's structured outputs page states the guarantee in three lines: "Always valid: No JSON parsing errors", "Type safe: Guaranteed field types and required fields", "Reliable: No retries needed for schema violations". Read the middle one twice. Field types and required fields.
The number everyone quotes comes from OpenAI's August 2024 announcement, where gpt-4o-2024-08-06 with Structured Outputs "achieves 100% reliability in our evals, perfectly matching the output schemas" against "less than 40%" for gpt-4-0613. The eval set is not published and its size is not given. The same page says the feature "doesn't prevent all kinds of model mistakes".
The figure holds. It holds for the schema the API kept.
We made the next part of this argument in Does forcing JSON output make an AI model worse at reasoning?, which quoted a paper's line that schema conformance "is necessary but not sufficient for semantic correctness". That was about where conformance ends. This is about the schema ending sooner than you wrote it.
What happens to a constraint the API does not support?
| What you declare | Claude API | OpenAI, strict: true |
Gemini API |
|---|---|---|---|
minLength, maxLength |
unsupported, 400 | absent from the supported string list | "strips and ignores them during request normalization" |
minimum, maximum, multipleOf |
unsupported, 400 | supported | supported |
pattern |
supported, regex subset | supported | not documented |
minItems |
values 0 and 1 only | supported | enforced |
maxItems |
not documented | supported | enforced |
| any unsupported keyword | "you'll receive a 400 error with details" | "you will receive an error" | stripped, the request proceeds |
The Gemini page is the blunt one, and it says where the work goes instead: "To enforce the other constraints, validate the output in your client application." OpenAI's supported-properties list names pattern and format for strings. It never mentions minLength in either direction, so a pydantic model's min_length=9 reaches OpenAI with no documented behaviour attached to it at all.
What does an SDK send when you write minLength?
Method, repeatable in two minutes. Declare one pydantic model with seven constraints across three fields, hand it to each SDK's own schema helper, and print the schema the helper puts on the wire. Versions: anthropic 2.16.0 with pydantic 2.14.4, openai 3.62.0, @anthropic-ai/sdk 1.16.0 with zod 4.6.7.
openai sent all seven, plus additionalProperties: false and every field marked required. anthropic sent minItems: 1. The other six arrived as English, inside two description strings:
"vat_number": {
"type": "string",
"description": "{maxLength: 9, minLength: 9, pattern: ^[0-9]{9}$}"
},
"amount": {
"type": "number",
"description": "{maximum: 100000, minimum: 0}"
}
The mechanism is nine lines at the end of transform_schema in _transform.py. Supported keywords are popped off the schema one at a time. Whatever is still in the dict at the end gets concatenated into the description. The comment over those lines does not oversell what happens next: "so we add them to the description so that the model might follow them."
pattern sits in that leftover bucket in both official SDKs, Python and TypeScript. The API would have compiled it into the grammar. The client turned it into a hint.
Does anything check the value on the way back?
Fourteen call paths across ten libraries, read on 2 December 2026. Five raise. Six hand you the violating value with their defaults as shipped.
| Call path | What happens when the response breaks your constraint |
|---|---|
anthropic 2.16.0, output_format=Model |
pydantic.ValidationError. Our deliberately bad response produced three errors |
anthropic 2.16.0, raw schema dict in output_config |
nothing checks it, parsed_output is None, you read the text |
@anthropic-ai/sdk 1.16.0, zodOutputFormat |
AnthropicError listing the zod issues |
@anthropic-ai/sdk 1.16.0, jsonSchemaOutputFormat |
returns it. Its parse is JSON.parse and a try block |
openai 3.62.0, .parse() |
pydantic.TypeAdapter(...).validate_json on the content |
| Vercel AI SDK, zod or any standard schema | the validator's error, wrapped |
Vercel AI SDK, jsonSchema() with no validate |
if (actualSchema.validate == null) return { success: true, value } |
| langchain-anthropic, pydantic class | PydanticOutputParser raises |
langchain-anthropic, dict or TypedDict |
its docstring: "the model output will be a dict and will not be validated" |
google-genai Python, pydantic response_schema |
model_validate_json inside try, then except ValueError: pass. parsed is None and the reason is gone |
@google/genai 2.27.0 for JS |
no parsed accessor on the response at all. You JSON.parse the text yourself |
| LiteLLM | a full jsonschema validate against your original schema, behind enable_json_schema_validation, which is False |
| instructor | re-asks the model with the error. max_retries defaults to 1 |
| pydantic-ai | the ValidationError becomes a ToolRetryError and goes back as a tool result |
Two of those rows are the same SDK, and the outcome is decided by which of its two helpers you imported.
LiteLLM is the one that re-validates against the schema you wrote rather than against a restated model of it, and it ships with the flag off. Its own filter also keeps pattern while claiming in its docstring to mirror the Anthropic SDK transformation, so two layers that describe themselves as doing the same thing disagree about your regex.
Who pays for this, and who never notices?
Teams whose extracted fields land in a database with constraints of its own never find out. A NOT NULL and a CHECK constraint are the oldest validation layer in the building, and a nine-digit tax number that arrived with two digits fails them on the way in. The write is rejected, somebody reads a stack trace, the schema gets fixed that afternoon.
The bill lands on pipelines whose output goes straight into a form or a payment instruction. We built OFFSET, which files declarations directly to the ΑΑΔΕ portal. A filing takes the value, types it into a government form and submits it, and nothing further down the line holds a second opinion about what the value should have looked like.
We hit the same gap from the other side in What does an AI agent do with a tool call the model never finished?. The object parses. The type is right. The only layer that knew what the value should look like was the schema that got rewritten on the way out.
What do you change on Monday?
Validate after parse, against the schema you wrote rather than the one your client sent. In Python that is jsonschema.validate, or your pydantic model run against the raw text; in TypeScript, the zod object rather than the JSON Schema you handed the helper. Whatever the API dropped is now yours to check. The list is in the table above, and it is longer than most teams expect.
Then count the violations before you design around them. A re-ask on Claude Opus 5.5, with a 6,000-token prompt returning as a cache hit at $0.20 per million and 300 output tokens at $20 per million, costs about seven tenths of a cent at the list prices we checked on 2 December 2026. Nobody skips this check because of the retry bill. They skip it because the failure is a well-formed object and there is no log line to find.
We have not sent these schemas to the API itself. Every row above is a code read and the wire schema the client built in front of us, so what a model does with {minimum: 0} sitting in a description is still the vendors' account of their own grammar. The number we want is the violation rate per thousand calls with a constraint in the description against the same constraint in the prompt, and we have not logged it. If somebody has, we would like the figure.
If you are scoping an extraction or filing pipeline and want the checks placed before it ships, that is what our agentic AI systems work covers. Which field in your pipeline would do real damage at the wrong length, and what in your code would notice?
Common questions
Does structured output enforce minLength?
On no major API as you wrote it. The Claude API lists minLength and maxLength as unsupported string constraints and returns a 400 error, and the official Claude SDKs pre-empt that by moving the constraint into the field's description. The Gemini API documents that minLength and maxLength are not enforced by its constrained decoding grammar and that the API strips and ignores them during request normalization. OpenAI's supported-properties list for strings names pattern and format, and does not name minLength. Checked 2 December 2026.
Does the Claude API support the pattern keyword in a JSON schema?
The API does, within a documented regex subset: full and partial matching, the simple quantifiers, character classes and groups, with no backreferences, lookaround or word boundaries. The SDKs do not pass it on. transform_schema in anthropic 2.16.0 and transformJSONSchema in @anthropic-ai/sdk 1.16.0 both keep only format for a string and append everything else, pattern included, to the description.
Should I validate an AI model's structured output against my own schema?
Yes, against the schema you wrote rather than the one your client sent. Six of the fourteen client call paths we read on 2 December 2026 hand back a value that breaks a declared constraint without raising anything, and Google's own structured output page says to enforce the unenforced constraints by validating the output in your client application.
What does a retry on a schema violation cost?
About seven tenths of a cent on Claude Opus 5.5, for a re-ask whose 6,000-token prompt comes back as a cache hit and whose answer is 300 output tokens: 6,000 at $0.20 per million plus 300 at $20 per million. List prices checked 2 December 2026. The retry is not what makes teams skip the check.


