- Symptom
- Invalid schema for response_format: In context=(), 'required' is required to be supplied and to be an array including every key in properties.400 invalid_json_schema for a Pydantic model with an optional or dict fieldZod discriminated union at the root is rejected
- Cause
- With strict set to true every property must be listed in required, every object needs additionalProperties false, and the root must be a plain object, not anyOf. Optional fields and open maps break those rules.
- Fix
- Make optional fields required but nullable, replace free form dicts with arrays of key and value objects, and wrap unions inside a root object.
- Apply
{"type": "object", "additionalProperties": false, "required": ["name", "nickname"], "properties": {"name": {"type": "string"}, "nickname": {"type": ["string", "null"]}}}- Affected
- OpenAI Structured Outputs with strict true, Responses and Chat Completions, checked October 2026
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders