Strict JSON schema rules for OpenAI and Claude
Eight rules that keep a JSON schema from a 400 on OpenAI or Claude structured outputs, plus two jq checks.
Published here , updated · 2 sources · Resume reading
OpenAI strict mode and Claude structured outputs reject different JSON schema features, so a schema that works on one can get a 400 on the other [1][2]. These eight rules cover both, and two jq commands check a schema before you send it.
Apply the eight rules
-
Both:
"additionalProperties": falseon every object, nested ones too. -
OpenAI: use
json_schemawithstrict: true. JSON mode (json_object) gives valid JSON, not your schema. -
OpenAI: list every field in
required. Optional field ={"type": ["string", "null"]}. -
OpenAI: up to 5000 object properties, 10 levels of nesting.
-
Claude raw API: no minimum, maximum, multipleOf, minLength, maxLength, recursive schemas or external $ref. You get a 400. SDK helpers strip these and check them in your code. OpenAI strict does accept minimum, maximum, multipleOf and pattern.
-
Key order: OpenAI keeps schema order. Claude puts required keys first, then optional ones. Read fields by name.
-
Both: check for a refusal or a max tokens cutoff before you parse. The output may not match the schema.
-
Claude: the first call with a new schema is slower while the grammar compiles; it is cached for 24 h from last use.
Claude also limits one request to 24 optional parameters and 16 parameters with union types, counted across all strict schemas [2]. A nullable field like the one in rule 3 counts as a union type.
Check your schema with jq
Run both on your schema.json:
jq '[.. | objects | select(.type=="object") | .additionalProperties] | all(. == false)' schema.jsonjq -c '[.. | objects | keys[] | select(IN("minimum","maximum","multipleOf","minLength","maxLength"))]' schema.jsonA schema with an open object, a minLength and a minimum prints false and ["minLength","minimum"]. After the fix, you should see true and [].
Send this to the friend whose JSON schema works on OpenAI and gets a 400 on Claude.
Keep this guide
Filed under AI agents
Questions about this guide
Why does Claude reject minimum and maximum?
Claude's raw API does not support minimum, maximum, multipleOf, minLength, maxLength, recursive schemas or external $ref. SDK helpers strip these and check them in your code.
Does OpenAI keep the key order?
Yes. Claude puts required keys first, then optional ones. Read fields by name.
How do I make a field optional in OpenAI strict mode?
Keep it in `required` and let its type include null, as in rule 3. OpenAI strict mode requires every field to be listed.
Sources
- OpenAI docs: structured outputsdevelopers.openai.com
- Claude docs: structured outputsplatform.claude.com