Skip to content

Normalize OpenAI SDK BaseModel choices/messages to avoid Pydantic serializer warnings - #18972

Merged
2 commits merged into
BerriAI:litellm_staging_01_13_2026from
hummat:fix/normalize-basemodel-choices-message
Jan 13, 2026
Merged

Normalize OpenAI SDK BaseModel choices/messages to avoid Pydantic serializer warnings#18972
2 commits merged into
BerriAI:litellm_staging_01_13_2026from
hummat:fix/normalize-basemodel-choices-message

Conversation

@hummat

@hummat hummat commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Fixes noisy Pydantic v2 "serializer warnings" seen downstream (e.g. when serializing LiteLLM ModelResponse objects).

Changes:

  • Coerce OpenAI SDK (pydantic BaseModel) message objects passed into Choices(...) into LiteLLM's Message.
  • Coerce pydantic BaseModel choice objects passed into ModelResponse(choices=[...]) into LiteLLM's Choices.
  • Override ModelResponseBase.model_dump() to default to exclude_unset=True unless the caller explicitly sets exclude_unset/exclude_none.
    This prevents PydanticSerializationUnexpectedValue warnings caused by OpenAIObject-derived types that omit unset fields.
  • Add regression test tests/test_litellm/test_model_response_normalization.py.

Related: #11759, #11914.

@vercel

vercel Bot commented Jan 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
litellm Ready Ready Preview, Comment Jan 13, 2026 10:26am

@CLAassistant

CLAassistant commented Jan 12, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hummat

hummat commented Jan 13, 2026

Copy link
Copy Markdown
Contributor Author

CI note: the failing mock-tests job shows missing deps (openapi_core) and a missing enterprise module (litellm_enterprise.proxy.common_utils.check_responses_cost). I pushed a follow-up commit to add openapi-core to test deps (Makefile + CI workflow) and add init.py under enterprise proxy/common_utils so the module is importable. There are additional unrelated test failures in the CI log (embedding header assertion, HF 401) that may still need attention if they persist.

@hummat
hummat force-pushed the fix/normalize-basemodel-choices-message branch from 48a0d88 to f1acb7c Compare January 13, 2026 10:24
@ghost
ghost changed the base branch from main to litellm_staging_01_13_2026 January 13, 2026 22:10
@ghost
ghost merged commit 9adc19d into BerriAI:litellm_staging_01_13_2026 Jan 13, 2026
6 of 7 checks passed
Amir-R25 added a commit to RailtownAI/railtracks that referenced this pull request Mar 16, 2026
## What does this add?

Closes #220. LiteLLM merged a fix for the pydantic warnings and
therefore there is no a longer a need for filtering warnings:
BerriAI/litellm#18972

## Type of changes

Please check the type of change your PR introduces:

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 📚 Documentation update (improvements or corrections to
documentation)
- [ ] 🎨 Code style/formatting (changes that do not affect the meaning of
the code)
- [x] ♻️ Refactoring (code change that neither fixes a bug nor adds a
feature)
- [ ] ⚡ Performance improvement (code change that improves performance)
- [ ] ✅ Test update (adding missing tests or correcting existing tests)
- [ ] 🔧 Build/CI changes (changes to build process or continuous
integration)
- [ ] 🗑️ Chore (other changes that don't modify src or test files)
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…ializer warnings (BerriAI#18972)

* Normalize BaseModel choices + suppress serializer warnings

* Fix ModelResponse normalization and test deps
This pull request was closed.
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.

2 participants