Skip to content

Pydantic serializer warnings for internal issue (response_modalities) #4869

@lgenzelis

Description

@lgenzelis

🔴 Required Information

Describe the Bug:
RunConfig.response_modalities is typed as Optional[list[str]], but ADK assigns it directly to LiveConnectConfig.response_modalities, which is typed as Optional[list[Modality]] (an enum) by google-genai. Pydantic coerces the enum to a string at the RunConfig level, then warns when serializing the string into a field that expects an enum. This warning fires on every live streaming session and pollutes production logs.

Steps to Reproduce:

  1. Set up a live streaming agent using RunConfig with response_modalities=[types.Modality.AUDIO]
  2. Start a live streaming session (the warning is triggered inside ADK's internal flow when LiveConnectConfig is built from RunConfig, not at construction time)
  3. Observe the warning in logs

Expected Behavior:
No Pydantic serialization warning. RunConfig.response_modalities should be typed as list[Modality]

Observed Behavior:

/path/to/.venv/lib/python3.13/site-packages/pydantic/main.py:464: UserWarning: Pydantic serializer warnings:
  PydanticSerializationUnexpectedValue(Expected `enum` - serialized value may not be as expected [field_name='response_modalities', input_value='AUDIO', input_type=str])
  return self.__pydantic_serializer__.to_python(

Environment Details:

  • ADK Library Version: 1.26.0
  • Desktop OS: macOS
  • Python Version: 3.13.7

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: gemini-live-2.5-flash-native-audio

🟡 Optional Information

Regression:
Unknown — this has been present as long as we've used live streaming.

Logs:

/path/to/.venv/lib/python3.13/site-packages/pydantic/main.py:464: UserWarning: Pydantic serializer warnings:
  PydanticSerializationUnexpectedValue(Expected `enum` - serialized value may not be as expected [field_name='response_modalities', input_value='AUDIO', input_type=str])
  return self.__pydantic_serializer__.to_python(

Additional Context:
The type mismatch is in google/adk/agents/run_config.py:

response_modalities: Optional[list[str]] = None

vs google/genai/types.py (LiveConnectConfig):

response_modalities: Optional[list[Modality]] = None

The fix (LLM generated, just in case) would be changing RunConfig.response_modalities from list[str] to list[Modality].

Minimal Reproduction Code:
A minimal standalone repro requires a full live session. The code path that triggers it is in flows/llm_flows/basic.py:

llm_request.live_connect_config.response_modalities = (
    invocation_context.run_config.response_modalities
)

How often has this issue occurred?:

  • Always (100%)

Metadata

Metadata

Assignees

Labels

live[Component] This issue is related to live, voice and video chat

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions