Skip to content

[Bug]: TypeError: Object of type IntentMandate is not JSON serializable - sqlite_session_service fails to serialize Pydantic models in session state #129

@diptendulkar

Description

@diptendulkar

What happened?

Image **Environment** ADK Version: 1.13.0 (via google-adk) Python Version: 3.13.5 OS: macOS (darwin 24.5.0, arm64) Installation: pip/uv

Description
When storing a Pydantic BaseModel subclass in the ADK session state, sqlite_session_service.py raises a TypeError because json.dumps() is called directly on the Pydantic model object instead of its serialized representation.

Steps to Reproduce

  1. Create a Pydantic model and store it in the session state:
class IntentMandate(BaseModel):    
  natural_language_description: str    i
  ntent_expiry: str    # ... other fields

# In an agent tool or executor:
ctx.state["mandate"] = IntentMandate(    natural_language_description="Buy red shoes",    
intent_expiry="2025-12-30T00:00:00Z"
)
  1. The ADK attempts to persist the session state to SQLite
  2. Error is raised

Expected Behavior
The session service should handle Pydantic models gracefully, either by:
Calling .model_dump() on Pydantic BaseModel instances before JSON serialization
Using a custom JSON encoder that handles Pydantic models
Documenting that session state values must be JSON-serializable primitives

Actual Behavior
TypeError: Object of type IntentMandate is not JSON serializable (ref screenshot)

Relevant log output

2025-12-29 20:31:45,807 - ERROR - adk_web_server.py:1509 - Error in event_generator: Object of type IntentMandate is not JSON serializable
Traceback (most recent call last):
  File ".venv/lib/python3.13/site-packages/google/adk/cli/adk_web_server.py", line 1499, in event_generator
    async for event in agen:
    ...
      yield f"data: {sse_event}\n\n"
  File ".venv/lib/python3.13/site-packages/google/adk/runners.py", line 505, in run_async
    async for event in agen:
      yield event
  File ".venv/lib/python3.13/site-packages/google/adk/runners.py", line 493, in _run_with_trace
    async for event in agen:
      yield event
  File ".venv/lib/python3.13/site-packages/google/adk/runners.py", line 769, in _exec_with_plugin
    await self.session_service.append_event(
        session=session, event=event
    )
  File ".venv/lib/python3.13/site-packages/google/adk/cli/utils/local_storage.py", line 200, in append_event
    return await service.append_event(session, event)
  File ".venv/lib/python3.13/site-packages/google/adk/sessions/sqlite_session_service.py", line 369, in append_event
    await self._update_session_state_in_db(...)
  File ".venv/lib/python3.13/site-packages/google/adk/sessions/sqlite_session_service.py", line 504, in _update_session_state_in_db
    json.dumps(delta),
  File "/opt/homebrew/Cellar/[email protected]/3.13.5/.../json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  ...
TypeError: Object of type IntentMandate is not JSON serializable

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions