Skip to main content

Comparison

OpenAI vs Anthropic Structured Outputs Comparison: What Strict Mode Guarantees and Where It Still Breaks

By AInews Desk
OpenAI vs Anthropic Structured Outputs Comparison: What Strict Mode Guarantees and Where It Still Breaks
7 min read
1328 words

Anthropic's structured outputs are out of beta. The old output_format parameter has moved to output_config.format, and beta headers are no longer required. If you still send the deprecated parameter without the structured-outputs-2025-11-13 header, the API returns a 400 error. This OpenAI vs Anthropic structured outputs comparison is for developers who run JSON.parse on model output in production. It covers how to turn on each vendor's schema mode, what each one rejects before generation starts, and which responses can still fail your parser.

Two switches on each side

OpenAI offers Structured Outputs in two forms: through function calling, or through a json_schema response format. In the Responses API, the response format goes in text.format, and the guide compares that option with function calling. You set strict: true to enable it. If you do that and send an unsupported JSON Schema, you get an error instead of a quietly degraded result. The feature is supported in the Responses, Chat Completions, Assistants, Fine-tuning and Batch APIs. You don't have to write schemas by hand: the Python and JavaScript SDKs let you define them with pydantic.BaseModel and z.object, and the Ruby SDK supports Sorbet T::Struct.

Anthropic also has two features. JSON outputs use output_config.format to shape Claude's reply. Strict tool use (strict: true on a tool) guarantees schema validation on tool names and inputs. You can use them separately or together in the same request.

Don't confuse either one with OpenAI's older JSON mode. OpenAI's guide puts it plainly: both produce valid JSON, but only Structured Outputs ensures schema adherence.

Different kinds of limits

The two vendors limit schemas in different ways. OpenAI limits which JSON Schema keywords you can use. Anthropic limits how complex your schemas can get in a single request.

OpenAI's guide lists composition keywords it doesn't support: allOf, not, dependentRequired, dependentSchemas and if/then/else. Fine-tuned models lose more: minLength, maxLength, pattern and format for strings; minimum, maximum and multipleOf for numbers; patternProperties; and minItems/maxItems. Each nested schema inside an anyOf must also fit within the supported subset.

OpenAI's strict mode also sets two schema rules. All fields must be required; to emulate an optional field, you give it a union type that includes null. And additionalProperties: false must always be set in objects.

Anthropic allows optional fields, but it counts them. Like OpenAI, it requires additionalProperties to be set to false for objects. Per request, you get 20 strict tools, 24 optional parameters, and 16 parameters with union types. The optional and union limits apply across all strict tool schemas and JSON output schemas combined. Non-strict tools don't count toward the 20. Union types create exponential compilation cost, and each optional parameter roughly doubles a portion of the grammar's state space. Anthropic's advice is to mark only critical tools as strict, make parameters required where possible, flatten nesting, and split work across requests. In practice, a schema with lots of nullable fields will hit the limits early.

DimensionOpenAIAnthropic
How to enablejson_schema format + strict: trueoutput_config.format / strict: true tool
Main type of limitUnsupported keywordsPer-request complexity limits
Optional params cap—24 across strict schemas
Union-type cap—16 across strict schemas
Strict tools cap—20 per request
First-request latencyAny new schema (one note says fine-tuned only)Every new schema
Schema cache—24 hours from last use
Refusal signalrefusal fieldstop_reason: "refusal" (200 status, tokens billed)
Max tokens reachedOutput may be incompletestop_reason: "max_tokens"
Enum capitalization—Not guaranteed

The first request with a new schema is slower

On OpenAI, the guide's notes don't agree with each other. Two of them say the first request you make with any schema will have additional latency as the API processes the schema, and later requests with the same schema won't. A third limits this to fine-tuned models and says other models don't have this limitation. Plan for a slower first call either way.

On Anthropic, the first use of any new schema adds latency while the grammar compiles. Compiled grammars are then cached for 24 hours from last use. The cache resets if you change the schema's structure or, when you combine structured outputs with tools, the set of tools. Changing only name or description fields doesn't reset it. If your code builds a slightly different schema on each request, you pay the compile cost every time.

The cache also has privacy implications. Anthropic says prompts and outputs aren't stored; only the JSON schema is cached, for up to 24 hours. The same applies to strict tool use. Because the schema itself is kept, Anthropic says PHI must not be included in JSON schema definitions: not in property names, enum values, const values or pattern regular expressions, because cached schemas don't get the same PHI protections as prompts and responses. Healthcare teams should check their field names and enum values.

When strict mode still returns output your parser can't use

Neither vendor guarantees that every response matches your schema, so check the response before you parse it.

On OpenAI, a request built on user-generated input may occasionally be refused for safety reasons. A refusal doesn't necessarily follow your schema, so the response includes a refusal field. Check that field first. Then show the refusal in your UI or handle it in code instead of sending it to your parser. The guide names one more case: a response can fail to match your schema if you reach a max tokens limit and the response is incomplete.

On Anthropic, a safety refusal looks different. The response has stop_reason: "refusal", comes back with a 200 status code, and you're billed for the tokens generated. The output might not match your schema, because the refusal message takes precedence over schema constraints. So a 200 doesn't mean the JSON is usable.

A response that runs out of tokens comes back with stop_reason: "max_tokens", and the output might be incomplete and not match your schema. The fix is to retry with a higher max_tokens. Your schema design can also cause refusals. A property that asks for the model's step-by-step reasoning might lead to a reasoning_extraction refusal, so ask for a short explanation instead.

Anthropic adds one caveat that doesn't raise any error: structured outputs don't guarantee the capitalization of string enum and const values. A value can differ from your schema only in its capital letters, and the response still completes normally. Compare enum values case-insensitively, and avoid enum values that differ only in capitalization.

If you're still using OpenAI's JSON mode, it has its own failure modes. Without an explicit instruction to produce JSON, the model may generate an unending stream of whitespace until it reaches the token limit. The API throws an error if "JSON" doesn't appear in the context to help you avoid that.

Recommendation

Pick based on how your schemas look, not on brand.

On OpenAI, the rules are about which keywords you can use: every field required, additionalProperties: false everywhere, no allOf or if/then/else, and fewer constraint keywords on fine-tuned models.

On Anthropic, optional fields are allowed but counted: 24 optional parameters and 16 union-type parameters across all strict schemas in a request, and at most 20 strict tools. Keep the schema structure stable so the 24-hour grammar cache keeps working. If you hit the limits, make optional fields required and leave less important tools non-strict.

Both vendors' SDKs let you define the schema in code, including Pydantic models in Python.

Whichever you use, check for a refusal or a max-tokens stop before you parse, and on Anthropic compare enum values case-insensitively.

Sources

7 min read
•
1328 words

Tags

OpenAI vs Anthropic structured outputs comparisonAnthropic strict schema mode guaranteesOpenAI structured outputs schema enforcementAI refusal handling structured outputs

Related Articles