Structured Outputs Across Claude, GPT, and Gemini APIs
Compare JSON schema enforcement across Anthropic, OpenAI, and Google: API parameter shapes, SDK tooling, strict constraints, and pricing tiers.
- Anthropic specifies schemas under output_config.format with type json_schema, returning validated JSON in the content block.
- OpenAI uses text.format or response_format with type json_schema and requires strict: true alongside additionalProperties: false.
- Google Gemini sets schemas via response_format with type text, mime_type application/json, and a schema object.
- Token pricing spans from $0.10 input on Gemini 2.5 Flash-Lite and GPT-6 Luna up to $10 input on GPT-6 Astra and Claude Fable 5.1.
Enforcing JSON Schemas Across Major LLM Providers
Reliable data extraction and agent workflows require language models to produce deterministic, valid JSON that matches programmatic types. When applications parse unconstrained text, unexpected formatting errors, missing keys, and invalid datatypes frequently lead to failed downstream operations. Structured outputs solve this issue through constrained decoding, which forces model token generation to conform directly to a supplied JSON Schema.
Anthropic, OpenAI, and Google Gemini each offer native mechanisms for schema enforcement. While all three platforms accept standard JSON Schema definitions or types derived from libraries like Pydantic and Zod, their REST request structures, parameter naming conventions, and validation semantics differ. Understanding these architectural variances allows development teams to build portable pipelines and choose the appropriate model tier based on operational requirements.
API Request Shapes and Parameter Configurations
In the Anthropic Claude API, schema configuration is nested inside the output_config block. Developers provide format with type: "json_schema" and the schema definition. Claude validates the resulting object and delivers the JSON payload inside the response’s standard text content block.
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Extract contact details."}
],
"output_config": {
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"email": {"type": "string"}
},
"required": ["name", "email"],
"additionalProperties": false
}
}
}
}'
In the OpenAI Responses API, structured outputs are configured within the text.format object. The payload includes type: "json_schema", a descriptive name, the schema definition, and strict: true. Setting strict mode guarantees complete schema compliance.
curl https://api.openai.com/v1/responses \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-astra",
"input": [
{"role": "user", "content": "Extract event details."}
],
"text": {
"format": {
"type": "json_schema",
"name": "event",
"strict": true,
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"date": {"type": "string"}
},
"required": ["name", "date"],
"additionalProperties": false
}
}
}
}'
For the Google Gemini Interactions API, schema enforcement is configured directly via response_format. The object requires type: "text", mime_type: "application/json", and the raw schema object, supporting constructs such as anyOf and nested items.
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.8-flash",
"input": "Extract recipe items.",
"response_format": {
"type": "text",
"mime_type": "application/json",
"schema": {
"type": "object",
"properties": {
"recipe_name": {"type": "string"}
},
"required": ["recipe_name"]
}
}
}'
SDK Support and Language Integration
All three ecosystems offer high-level language bindings that convert native classes or runtime validators directly into compliant JSON schemas without manual serialization. The integration mechanisms for each provider include:
- Anthropic: Python uses client.messages.parse() with Pydantic models. TypeScript employs zodOutputFormat() with Zod schemas. C# supports generic Create<T>() methods. Go offers BetaJSONOutputFormatParam, while Java uses Jackson and Swagger annotations with outputConfig(Class<T>).
- OpenAI: Python provides client.responses.parse() passing Pydantic classes to text_format. Node.js uses zodTextFormat() helpers. Ruby integrates Sorbet structs via OpenAI::StructuredOutput.from_sorbet, and Java utilizes ResponseFormatTextJsonSchemaConfig.
- Google GenAI: Python passes Pydantic models using Recipe.model_json_schema() into response_format. JavaScript constructs schemas using z.fromJSONSchema(), and Java builds CreateModelInteractionResponseFormat definitions with Jackson-compatible maps.
When building automated publishing workflows, such as those described in /posts/automated-blog-pipeline-gemini-architecture/ and /posts/gemini-structured-output-response-schema-lessons/, programmatic SDK parsing eliminates custom regex routines and unmarshaling boilerplate.
Provider Comparison and Technical Constraints
Each provider establishes specific rules regarding schema completeness, validation timing, and unsupported keywords. OpenAI and Anthropic require schemas to explicitly define additionalProperties: false on object declarations, and all property keys must typically appear in the required array.
| Provider | Config Parameter | Schema Format Identifier | Required Schema Constraints | SDK Object Support |
|---|---|---|---|---|
| Anthropic Claude | output_config.format | type: json_schema | additionalProperties: false, all properties required in derived classes | Pydantic, Zod, C# types, Java classes, Go structs |
| OpenAI GPT | text.format | type: json_schema, strict: true | additionalProperties: false, complete required arrays, schema name required | Pydantic, Zod, Sorbet T::Struct, Java, C# |
| Google Gemini | response_format | type: text, mime_type: application/json | mime_type declaration, support for anyOf and enum unions | Pydantic, Zod, Java Map/Builders, Go structs |
For Java developers using the Anthropic SDK, local schema validation executes before making network calls, catching incompatible constraints locally. Developers can disable local checks using JsonSchemaLocalValidation.NO if newer API features conflict with client-side checks.
Model Pricing and Token Economics
Because structured output models generate schema syntax like field keys, brackets, and quotes, output token counts can exceed standard unstructured prose. Comparing input, cached input, and output costs per 1M tokens across tiers is critical when sizing high-volume pipelines. Developers can evaluate comprehensive breakdowns at /tools/llm-api-pricing/ or analyze custom usage scenarios with the /tools/llm-api-cost-calculator/.
| Model Identifier | Input Cost ($/1M) | Cached Input ($/1M) | Output Cost ($/1M) |
|---|---|---|---|
| claude-fable-5.1 | $10 | $0.25 | $50 |
| claude-opus-5.5 | $4 | $0.2 | $20 |
| claude-sonnet-5.5 | $2 | $0.2 | $10 |
| claude-haiku-4.5 | $1 | $0.1 | $5 |
| gpt-6-astra | $10 | $1 | $50 |
| gpt-6.1-sol | $2 | $0.1 | $10 |
| gpt-6-luna | $0.1 | $0.01 | $0.5 |
| gpt-5.6-sol | $4 | $0.4 | $20 |
| gpt-5.6-terra | $2 | $0.2 | $12 |
| gpt-5.6-luna | $0.2 | $0.02 | $1.2 |
| gpt-5.4-mini | $0.75 | $0.075 | $4.5 |
| gpt-5.4-nano | $0.2 | $0.02 | $1.25 |
| gemini-3.1-pro-preview | $2 | $0.2 | $12 |
| gemini-3.8-flash | $0.75 | $0.075 | $3.75 |
| gemini-3.5-flash | $1.5 | $0.15 | $9 |
| gemini-3.5-flash-lite | $0.3 | $0.03 | $2.5 |
| gemini-3.1-flash-lite | $0.25 | $0.025 | $1.5 |
| gemini-2.5-pro | $1.25 | $0.125 | $10 |
| gemini-2.5-flash | $0.3 | $0.03 | $2.5 |
| gemini-2.5-flash-lite | $0.1 | $0.01 | $0.4 |
For cost-sensitive applications, lightweight tiers like Gemini 2.5 Flash-Lite ($0.10 input, $0.40 output) and GPT-6 Luna ($0.10 input, $0.50 output) offer affordable baseline extraction. Intermediate processing works well on Gemini 3.8 Flash ($0.75 input, $3.75 output) or Claude Haiku 4.5 ($1 input, $5 output). Flagship extraction tasks requiring complex reasoning can use Claude Opus 5.5 ($4 input, $20 output) or GPT-6 Astra ($10 input, $50 output). More details on choosing models based on budgets are covered in /posts/choosing-an-llm-api-model-by-cost-tier/.
Implementation Checklist for Structured Outputs
Before deploying structured schema endpoints to production environments, confirm each requirement against this implementation checklist:
- Verify provider-specific nesting: output_config.format for Claude, text.format for OpenAI, and response_format for Gemini.
- Set additionalProperties to false on all object definitions when targeting OpenAI or Claude APIs.
- Ensure all object properties appear in the required array unless using explicitly supported optional types.
- Include prompt instructions that clearly describe the expected data transformations alongside the schema definition.
- Handle safety refusals programmatically, checking completion status codes and response metadata before parsing payloads.
- Verify pricing metrics and establish per-request execution budgets using /posts/per-run-cost-cap-for-llm-api-calls/.
By aligning JSON schemas with each provider’s structural parameters, engineering teams can eliminate runtime deserialization failures while maintaining predictable costs.