Urgent.News

What's breaking now, across hundreds of outlets.

AI

Why LLM Structured Output Strict Mode Rejects Valid JSON Schema (additionalProperties & Required Keys)

Switching from prompt-engineered JSON to strict Structured Outputs ( response_format: { type: "json_schema", strict: true } ) often triggers 400 Invalid schema errors on schemas that pass standard JSON Schema validators. Two strict-mode constraints cause almost every failure. 1. Every Object—Including Nested Ones—Needs additionalProperties: false Setting additionalProperties: false only on the…

When transitioning from prompt-engineered JSON to strict Structured Outputs, using response_format: { type: "json_schema", strict: true } often results in 400 Invalid schema errors. This occurs even when the schema passes standard JSON Schema validators. Two main constraints trigger these errors: every object, including nested objects, must have additionalProperties set to false, and every key in properties must also appear in required.

Setting additionalProperties: false only on the root object is insufficient. Strict mode mandates that every nested object inside properties, items, or anyOf explicitly prevents extra keys. Furthermore, optional properties cannot be omitted from required. When modeling an optional field, it must remain in required and its type should be made nullable, such as { "type": "object", "additionalProperties": false, "properties": { "summary": { "type": "string" }, "errorCode": { "type": ["string", "null"] } }, "required": ["summary", "errorCode"] }.

Another crucial consideration is the variability of format keywords (uri, custom formats, complex regex patterns) across different providers like OpenAI, Gemini, and Anthropic. Identifying strict-mode violations locally before submitting to the API can save time and effort. Tools such as openapi-zod-lint (MIT licensed, node-based), a Prompt/Structured Output Schema Converter, an LLM Token Calculator, and a cURL Converter are available to assist in this process.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

A customer asked for the free inspection your website advertises — your AI booked 1,203 site visits and emailed 317 reports no technician ever wrote

A pest-control company — eight branches, twenty-six field technicians, a mix of residential contracts and light commercial — ran a chat assistant on the website.

  • AI booked 1,203 site visits without technician involvement
  • 317 reports emailed by AI, some with nonexistent readings
  • 6.2% of AI-booked inspections resulted in contracts

More from Wednesday 25 November →