Skip to content

fix(models): exclude LiteLlm's llm_client from field serialization#6165

Open
claud42 wants to merge 1 commit into
google:mainfrom
claud42:fix-issue-6164
Open

fix(models): exclude LiteLlm's llm_client from field serialization#6165
claud42 wants to merge 1 commit into
google:mainfrom
claud42:fix-issue-6164

Conversation

@claud42

@claud42 claud42 commented Jun 18, 2026

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
LiteLlm stores its client as a Pydantic field which has no JSON serializer. Any JSON dump of a LiteLlm therefore raises PydanticSerializationError, which surfaces as a 500 in adk web / adk api_server whenever a LiteLlm reaches a response payload.

Solution:
Ether provider (Gemini, Anthropic, Apigee) keeps its client off the model as a @cached_property, so it is never serialized. LiteLlm intentionally exposes llm_client as an injectable field for testing, so rather than convert it, mark it exclude=True — the client is dropped from serialization while remaining constructible and unchanged at runtime.

Testing Plan

Unit Tests:

  • [ Y ] All unit tests pass locally.

pytest tests/unittests/models/test_litellm.py (all pass)

Manual End-to-End (E2E) Tests:

Code and commands to re-produce the issue was provided in original issue ticket.

The problem resolved end to end with this fix.

Checklist

  • [ Y ] I have read the CONTRIBUTING.md document.
  • [ Y ] I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • [ Y ] New and existing unit tests pass locally with my changes.
  • [ Y ] I have manually tested my changes end-to-end.
  • [ Y ] Any dependent changes have been merged and published in downstream modules.

Fixes google#6164

LiteLlm stores its client as a Pydantic field which has no JSON serializer. Any JSON dump of a LiteLlm therefore raises `PydanticSerializationError`, which surfaces as a 500 in `adk web` / `adk api_server` whenever a LiteLlm reaches a response payload.

Ether provider (Gemini, Anthropic, Apigee) keeps its client off the model as a @cached_property, so it is never serialized. LiteLlm intentionally exposes llm_client as an injectable field for testing, so rather than convert it, mark it `exclude=True` — the client is dropped from serialization while remaining constructible and unchanged at runtime.

Testing:
  - pytest tests/unittests/models/test_litellm.py (all pass)
@google-cla

google-cla Bot commented Jun 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@wuliang229

Copy link
Copy Markdown
Collaborator

@claud42 can you sign the CLA?

@wuliang229 wuliang229 self-assigned this Jun 18, 2026
@claud42

claud42 commented Jun 19, 2026

Copy link
Copy Markdown
Author

@wuliang229 I submitted the CLA immediately after created this PR. Not sure how long it would take to be approved or synchronized here though.

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.

PydanticSerializationError when running LiteLlm based agent via adk web or api_server

2 participants