strict_schema: recurse into prefixItems entries for tuple schemas#3467
Open
Dev-X25874 wants to merge 1 commit into
Open
strict_schema: recurse into prefixItems entries for tuple schemas#3467Dev-X25874 wants to merge 1 commit into
Dev-X25874 wants to merge 1 commit into
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.
Summary
_ensure_strict_json_schemainstrict_schema.pyhandles"items"for homogeneousarrays but has no branch for
"prefixItems"— the key Pydantic v2 emits forfixed-length tuple types (e.g.
tuple[int, MyModel]) per JSON Schema draft 2020-12.As a result, any nested object schema inside a tuple position is never visited, so:
"additionalProperties": falseis never added to nested objects → OpenAI rejectsthe tool definition under strict mode at runtime.
"default": nullis not stripped from inner schemas.anyOf/oneOfinside tuple positions are not normalized.The fix adds a parallel block immediately after the existing
itemsblock thatiterates over
prefixItemsentries and applies_ensure_strict_json_schemarecursively to each one, mirroring the existing handling for
anyOf,oneOf,and
allOf.Test plan
_ensure_strict_json_schema—"prefixItems"isabsent from the function entirely before this change.
tests/test_strict_schema.pysuite covers the surrounding logic;a new test case for a
prefixItemsschema (e.g. a nested object inside a tupleposition) should be added to confirm
additionalProperties: falseis propagatedcorrectly.
Issue number
Checks
make lintandmake format