Skip to content

fix: convert oneOf to anyOf in strict schema for discriminated unions#5324

Merged
longcw merged 2 commits intomainfrom
longc/fix-strict-schema-discriminated-union
Apr 3, 2026
Merged

fix: convert oneOf to anyOf in strict schema for discriminated unions#5324
longcw merged 2 commits intomainfrom
longc/fix-strict-schema-discriminated-union

Conversation

@longcw
Copy link
Copy Markdown
Contributor

@longcw longcw commented Apr 3, 2026

Summary

  • Pydantic emits oneOf for discriminated unions (e.g., Annotated[Car | Bike, Field(discriminator="vehicle")]), but OpenAI strict mode rejects oneOf with 'oneOf' is not permitted
  • Convert oneOf to anyOf in _ensure_strict_json_schema, which is semantically equivalent and accepted by the API

Fixes #5302

Pydantic emits oneOf for discriminated unions, but OpenAI strict mode
rejects oneOf. Convert oneOf to anyOf which is semantically equivalent
and accepted by the API.

Fixes #5302
@chenghao-mou chenghao-mou requested a review from a team April 3, 2026 09:47
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@longcw longcw merged commit d81975a into main Apr 3, 2026
20 of 21 checks passed
@longcw longcw deleted the longc/fix-strict-schema-discriminated-union branch April 3, 2026 12:54
@inickt
Copy link
Copy Markdown
Contributor

inickt commented Apr 3, 2026

thanks!!

osimhi213 added a commit to de-id/livekit-agents that referenced this pull request Apr 5, 2026
* upstream/main:
  fix: add PARTICIPANT_KIND_CONNECTOR to default participant kinds (livekit#5339)
  feat: expose service_tier in CompletionUsage from OpenAI Responses API (livekit#5341)
  feat: answering machine detection (livekit#4906)
  fix: wait_for_participant waits until participant is fully active (livekit#5271)
  (gemini realtime): add warnings in update_chat_ctx and update_instructions (livekit#5332)
  fix: convert oneOf to anyOf in strict schema for discriminated unions (livekit#5324)
  fix(voice): make function call history preservation configurable in AgentTask (livekit#5288)
osimhi213 added a commit to de-id/livekit-agents that referenced this pull request Apr 5, 2026
* fix(voice): make function call history preservation configurable in AgentTask (livekit#5288)

* fix: convert oneOf to anyOf in strict schema for discriminated unions (livekit#5324)

* (gemini realtime): add warnings in update_chat_ctx and update_instructions (livekit#5332)

* fix: wait_for_participant waits until participant is fully active (livekit#5271)

* feat: answering machine detection (livekit#4906)

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* feat: expose service_tier in CompletionUsage from OpenAI Responses API (livekit#5341)

* fix: add PARTICIPANT_KIND_CONNECTOR to default participant kinds (livekit#5339)

---------

Co-authored-by: Gopal Bagaswar <67310594+GopalGB@users.noreply.github.com>
Co-authored-by: Long Chen <longch1024@gmail.com>
Co-authored-by: Tina Nguyen <72938484+tinalenguyen@users.noreply.github.com>
Co-authored-by: David Zhao <dz@livekit.io>
Co-authored-by: Chenghao Mou <chenghao.mou@livekit.io>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Piyush Gambhir <90608533+piyush-gambhir@users.noreply.github.com>
Co-authored-by: Anunay Maheshwari <anunaym14@gmail.com>
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.

build_strict_openai_schema emits oneOf for discriminated unions, which OpenAI strict mode rejects

3 participants