Structured Output Errors — JSON Schema Violations Fix Guide 2026 | AI Error Hub
AI Error Hub/Categories/Structured Output & JSON Schema Errors
Category Hub

Structured Output & JSON Schema Errors

Every JSON, schema, and structured-response error across providers — with the fix.

22 documented errors
Structured output is the pattern where you ask an LLM for a specific data shape rather than free-form text. In 2026, every major provider guarantees syntactic JSON validity and shape conformance when you use their structured output primitives correctly. Failures still happen: strict mode violations, deprecated schema keywords, provider-specific quirks, and semantic issues where the JSON parses but the values are wrong. This hub is every documented structured output error and its fix.

Errors in this category

Related pillar guides

Related blog posts

Frequently asked questions

What's the difference between JSON mode and structured outputs?

JSON mode (response_format: json_object) guarantees the response parses as valid JSON — any JSON. Structured outputs (response_format: json_schema with strict: true) also guarantees the JSON conforms to your specific schema. Structured outputs is strictly better where available.

Why does OpenAI strict mode require additionalProperties: false everywhere?

It's a design constraint of the enforcement engine. Without it, the model could add fields not in your schema, which would break the strict guarantee. If you find this restrictive, drop strict: false and validate client-side with Zod or Pydantic instead.

How do I model optional fields in OpenAI strict mode?

Use type unions with null: `{ "type": ["string", "null"] }` and include the field in the required array. The field must be present in the response, but its value can be null. Verbose but reliable.

Can I use anyOf/oneOf across all providers?

OpenAI supports both (with strict mode constraints). Anthropic supports both. Gemini's OpenAPI 3.0 subset supports anyOf but not oneOf. If you need portable schemas, use discriminated unions via anyOf with a discriminator field, or move the union logic to client-side validation.

Why is my JSON response truncated?

Almost always max_tokens too low. Structured schemas with many fields need generous max_tokens. Check response.stop_reason ('length' or 'max_tokens' means truncation), increase max_tokens, or split into smaller extractions.

Does the strict mode apply to nested objects?

Yes, recursively. Every object at every level must have additionalProperties: false and every field listed in required (with null unions for optional). This is why schemas that were fine in permissive mode fail when you flip strict: true.

How do I detect when a JSON response is hallucinated vs. grounded in source?

Add a source-quote pattern: for every extracted value, require a companion field with the verbatim quote from the source text. Post-validate that the value appears in the quote. See G8 Chapter 6 for the pattern.