Skip to content

Require optional properties of nested objects in strict mode schemas - #372

Merged
mattt merged 1 commit into
mainfrom
mattt/strict-mode-nested-objects
Oct 26, 2026
Merged

mattt merged 1 commit into
mainfrom
mattt/strict-mode-nested-objects

Conversation

@mattt

@mattt mattt commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes structured output schemas for OpenAILanguageModel and OpenResponsesLanguageModel, which send them with strict: true. OpenAI's strict mode requires every property of every object to be in required, with a null type for an optional one, but the schema conversion applied this only to the root object. An optional property of a nested object, of the objects in an array, or of an enum case such as case note(String?) was left out of required. Optional properties of the root were listed in required but did not allow null, so the model could not leave them empty.

Both providers now share one conversion that applies the rules to every object in the schema, through properties, array items, and anyOf and oneOf choices. An optional property becomes required and allows null: a primitive type without listed values gets "type": ["string", "null"], as in OpenAI's examples, and an enum string, object, array, or union becomes a union with {"type": "null"}. Decoding already reads null as nil. Other providers are unchanged.

Resolves #327

@mattt
mattt merged commit 20e4b94 into main Oct 26, 2026
11 checks passed
@mattt
mattt deleted the mattt/strict-mode-nested-objects branch October 26, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI strict mode rejects optional properties in nested objects

1 participant