Skip to content

strict_schema: recurse into prefixItems entries for tuple schemas#3467

Open
Dev-X25874 wants to merge 1 commit into
openai:mainfrom
Dev-X25874:fix/strict-schema-prefix-items
Open

strict_schema: recurse into prefixItems entries for tuple schemas#3467
Dev-X25874 wants to merge 1 commit into
openai:mainfrom
Dev-X25874:fix/strict-schema-prefix-items

Conversation

@Dev-X25874
Copy link
Copy Markdown

Summary

_ensure_strict_json_schema in strict_schema.py handles "items" for homogeneous
arrays but has no branch for "prefixItems" — the key Pydantic v2 emits for
fixed-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": false is never added to nested objects → OpenAI rejects
    the tool definition under strict mode at runtime.
  • "default": null is not stripped from inner schemas.
  • anyOf/oneOf inside tuple positions are not normalized.

The fix adds a parallel block immediately after the existing items block that
iterates over prefixItems entries and applies _ensure_strict_json_schema
recursively to each one, mirroring the existing handling for anyOf, oneOf,
and allOf.

Test plan

  • Confirmed the bug by tracing _ensure_strict_json_schema"prefixItems" is
    absent from the function entirely before this change.
  • The existing tests/test_strict_schema.py suite covers the surrounding logic;
    a new test case for a prefixItems schema (e.g. a nested object inside a tuple
    position) should be added to confirm additionalProperties: false is propagated
    correctly.

Issue number

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants