Skip to content

fix(structured-output): strip examples from strict JSON schemas - #3732

Open
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/strip-json-schema-examples-2274
Open

fix(structured-output): strip examples from strict JSON schemas#3732
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/strip-json-schema-examples-2274

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

  • remove the JSON Schema examples metadata keyword when converting Pydantic models to the API's strict structured-output schema dialect
  • strip the keyword recursively, including nested definitions
  • preserve validation keywords and descriptive metadata
  • add regression coverage and run the existing Pydantic schema tests

Fixes #2274

Test plan

  • uv run ruff format src/openai/lib/_pydantic.py tests/lib/test_pydantic_examples.py
  • uv run ruff check --fix tests/lib/test_pydantic_examples.py
  • uv run ruff check src/openai/lib/_pydantic.py tests/lib/test_pydantic_examples.py
  • uv run pytest -o addopts= -q tests/lib/test_pydantic_examples.py
  • uv run pytest -o addopts= -q tests/lib/test_pydantic.py
  • git diff --check

All focused verification steps passed before the branch was reduced to its single final commit.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 25, 2026 00:44
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.

Invalid Schema Error when Using examples Field in Pydantic Model for OpenAI Python Client

1 participant