You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PydanticSerializationError when running LiteLlm based agent via adk web or api_server #6164
Describe the Bug:
When developing agent by LiteLlm, the adk web or adk api_server command raise an exception due to LiteLlm having a client field in type of LiteLLMClient that can't be deserialized to be part of FastAPI's response.
Steps to Reproduce:
Install adk
Develop an agent by LiteLlm (see minimal reproducible code at the end)
Run $ adk web --port 8000
Open http://127.0.0.1:8000
Error and stacktrace:
INFO: 127.0.0.1:57588 - "GET /dev/apps/my_agent/build_graph HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
<... skipped many lines>
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'google.adk.models.lite_llm.LiteLLMClient'>
Expected Behavior:
No 500 error for the HTTP request.
No error message in adk web or adk api_server stdout/stderr.
Observed Behavior:
500 error in HTTP request.
Error message showed as in above.
Environment Details:
ADK Library Version (pip show google-adk): Version: 2.2.0
Desktop OS: macOS
Python Version (python -V): 3.14.4
Model Information:
Are you using LiteLLM: Yes
Which model is being used: google/gemma-4-26B-A4B-it
🟡 Optional Information
Additional Context:
Root cause: LiteLlm.llm_client is a declared Pydantic field but its class LiteLLMClient has no JSON serializer. Any JSON serialization of a LiteLlm instance raises the error, e.g., when using FastAPI.
By contrast, Gemini exposes its api_client as a @cached_property, not a field, so it is never part of the serialized output.
A fix is obvious and trivial.
Minimal Reproduction Code:
model=LiteLlm(
model="...",
api_base="...",
)
root_agent=Agent(
model=model,
name='root_agent',
description='A helpful assistant for user questions.',
instruction='Answer user questions to the best of your knowledge',
)
Hi @claud42 , Thanks for raising this issue and submitting PR.
The PydanticSerializationError / TypeError occurs because LiteLlm includes an internal llm_client field (of type LiteLLMClient). When adk web or adk api_server serializes the agent graph using model_dump(), Pydantic attempts to serialize this live client instance, which is not JSON-serializable.
Setting exclude=True on the llm_client field—as proposed in PR #6165—is the right approach, the PR is currently under review and will be merged upon approval.
Workaround:
In your agent entrypoint exclude the client field and force Pydantic to rebuild the schema:
from google.adk.models.lite_llm import LiteLlm
# Exclude the non-serializable client field and force Pydantic to rebuild the schema
if hasattr(LiteLlm, "model_fields") and "llm_client" in LiteLlm.model_fields:
LiteLlm.model_fields["llm_client"].exclude = True
LiteLlm.model_rebuild(force=True)
Activity
sanketpatil06 commentedon Jun 19, 2026
Hi @claud42 , Thanks for raising this issue and submitting PR.
The PydanticSerializationError / TypeError occurs because LiteLlm includes an internal llm_client field (of type LiteLLMClient). When adk web or adk api_server serializes the agent graph using model_dump(), Pydantic attempts to serialize this live client instance, which is not JSON-serializable.
Setting exclude=True on the llm_client field—as proposed in PR #6165—is the right approach, the PR is currently under review and will be merged upon approval.
Workaround:
In your agent entrypoint exclude the client field and force Pydantic to rebuild the schema:
fix: exclude LiteLlm llm_client from JSON serialization
fix: exclude LiteLlm llm_client from JSON serialization