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.
Closes #1661.
Adds an opt-in
strict_schemamodel option for OpenAI models that enables Structured Outputs withstrict: true:What changed
strict_schemaoption available on all OpenAI model options classes. Defaults tofalseso existing behaviour is unchanged. Setting it without a schema raises a clear error._Shared.build_kwargs): adds"strict": trueto thejson_schemaresponse_format._SharedResponses._build_responses_kwargs): sets"strict": trueinstead of the previous hardcodedfalse.llm/default_plugins/openai_strict_schema.py: converts a JSON schema (e.g. one produced by a Pydantic model viamodel_json_schema()) into the restricted strict-compatible form:additionalProperties: falseto every object,required,$defs/$refdefinitions,anyOf: [T, {type: null}]unions,UnsupportedStrictSchemaErrorfor keywords OpenAI strict mode cannot enforce (minItems,maxItems,allOf,multipleOf, etc.), rather than silently weakening the schema.Notes on response handling
The issue also mentions surfacing
finish_reason/ refusal / truncation status. That's a larger change tollm.Responseand is intentionally left out of this PR to keep it focused; the compiler/migration pieces here are the prerequisite for it.Tests
tests/test_openai_strict_schema.py— converter unit tests (19): strict-shape normalization,$defsinlining, null unions, cosmetic-key stripping, error cases, input immutability.tests/test_cli_openai_models.py— 6 integration tests usinghttpx2_mock: chat + responses bodies with/without the option, the requires-schema error, and the unsupported-keyword error.ruff checkandmypyclean.