Repository navigation
Require optional properties of nested objects in strict mode schemas - #372
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes structured output schemas for
OpenAILanguageModelandOpenResponsesLanguageModel, which send them withstrict: true. OpenAI's strict mode requires every property of every object to be inrequired, with anulltype 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 ascase note(String?)was left out ofrequired. Optional properties of the root were listed inrequiredbut did not allownull, 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
anyOfandoneOfchoices. An optional property becomes required and allowsnull: 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 readsnullasnil. Other providers are unchanged.Resolves #327