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
_safe_json_serialize in lite_llm.py does not handle ValueError from json.dumps causing LLM request construction failure #5412
Describe the Bug:
The _safe_json_serialize function in google/adk/models/lite_llm.py is intended to safely serialize Python objects into JSON for LLM request construction. However, it does not handle all exceptions that can be raised by json.dumps, specifically ValueError caused by circular references.
As a result, certain inputs can cause serialization failures during LLM message construction instead of gracefully falling back to a safe representation.
Steps to Reproduce:
Install google-adk
Construct an LLM request where message content includes an object with a circular reference
Example: an object referencing itself directly or indirectly
Trigger _content_to_message_param in google/adk/models/lite_llm.py
Observe failure during JSON serialization
Expected Behavior:
All non-serializable or problematic Python objects should be safely converted into strings or fallback representations without raising exceptions during LLM request construction.
Observed Behavior: json.dumps raises ValueError (circular reference) which is not caught by _safe_json_serialize, causing LLM request construction to fail.
Environment Details:
ADK Library Version (pip show google-adk): 1.25.1
Desktop OS: Ubuntu 24.04.4 LTS
Python Version (python -V): Python 3.12.3
Model Information:
Are you using LiteLLM: Yes
Which model is being used: e.g. gemini-2.5-pro (or N/A if not applicable)
🟡 Optional Information
Providing this information greatly speeds up the resolution process.
Regression:
Unknown / N/A
Logs:
N/A - failure occurs during message serialization in LLM request construction
Screenshots / Video:
N/A
Additional Context:
This issue is less severe than the telemetry one because it affects LLM request construction rather than execution flow. However, it still violates the intended "safe serialization" contract and results in hard failures where a fallback (e.g. string conversion) is expected.
Minimal Reproduction Code:
classNode:
def__init__(self):
self.ref=selfobj=Node()
# Using obj in a message payload passed through LiteLLM adapter# triggers json.dumps circular reference failure
Activity
fix: catch ValueError in safe-JSON serializers for circular refs
fix: catch ValueError in safe-JSON serializers for circular refs