Skip to content

fix(lite_llm): exclude llm_client from model_dump to fix build_graph …#5375

Open
ammarfitwalla wants to merge 1 commit intogoogle:mainfrom
ammarfitwalla:fix/lite-llm-serialization-error
Open

fix(lite_llm): exclude llm_client from model_dump to fix build_graph …#5375
ammarfitwalla wants to merge 1 commit intogoogle:mainfrom
ammarfitwalla:fix/lite-llm-serialization-error

Conversation

@ammarfitwalla
Copy link
Copy Markdown

@ammarfitwalla ammarfitwalla commented Apr 17, 2026

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

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added test_lite_llm_model_dump_excludes_llm_client in tests/unittests/models/test_litellm.py.
This test asserts that llm_client is absent from model_dump(mode="python", exclude_none=True) output.
246 passed, 1 warning in 6.15s

Manual End-to-End (E2E) Tests:

Unable to perform E2E testing at this time due to lack of a LiteLLM-compatible API key.
The unit test directly covers the root cause — llm_client being present in model_dump() output — which is the exact field that causes the PydanticSerializationError in the builder serialization path.

Checklist

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

Additional context

The builder endpoint in adk_web_server.py serializes agent fields via model_dump().
For LiteLlm, this included llm_client -- a LiteLLMClient instance that Pydantic
cannot serialize, causing:
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize
unknown type: <class 'google.adk.models.lite_llm.LiteLLMClient'>

Fix: Mark llm_client with exclude=True in its Pydantic Field definition.
This drops it from model_dump() output while keeping the client fully functional at runtime.

# Before
llm_client: LiteLLMClient = Field(default_factory=LiteLLMClient)

# After
llm_client: LiteLLMClient = Field(default_factory=LiteLLMClient, exclude=True)

@adk-bot adk-bot added the models [Component] Issues related to model support label Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] Issues related to model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adk web build_graph crashes with LiteLlm model due to non-serializable LiteLLMClient

2 participants