Skip to content

fix: support list[pydantic.BaseModel] in response.parsed#2190

Open
Adewale-1 wants to merge 2 commits intogoogleapis:mainfrom
Adewale-1:fix/typed-list-pydantic-parsed-v2
Open

fix: support list[pydantic.BaseModel] in response.parsed#2190
Adewale-1 wants to merge 2 commits intogoogleapis:mainfrom
Adewale-1:fix/typed-list-pydantic-parsed-v2

Conversation

@Adewale-1
Copy link

@Adewale-1 Adewale-1 commented Mar 19, 2026

When response_schema is set to list[SomeModel], the response.parsed
field was typed as Optional[Union[pydantic.BaseModel, dict, Enum]],
which excluded list[pydantic.BaseModel]. This caused type errors and
made it impossible to use the parsed field with list-typed schemas.

Changes

  • Add list[pydantic.BaseModel] to the parsed field Union in GenerateContentResponse
  • Add tests covering:
    • Functional list schema parsing (test_parsed_list_support.py)
    • Mypy type checking for list schemas (test_parsed_list_mypy.py)
    • Preservation of LiveClient classes (test_live_client_and_list_type.py)

Fixes #886

When response_schema is set to list[SomeModel], the response.parsed
field was typed as Optional[Union[pydantic.BaseModel, dict, Enum]],
which excluded list[pydantic.BaseModel]. This caused type errors and
made it impossible to use the parsed field with list schemas.

Add list[pydantic.BaseModel] to the Union so response.parsed correctly
reflects list-typed schema responses.
…ibility

- Remove test_parsed_list_support.py (required live API key; type annotation
  is already covered by test_parsed_list_mypy.py)
- Fix LiveConnectConfig field assertion (model -> generation_config)
- Fix LiveClientToolResponse field assertion (function_responses)
- Fix test_combined_functionality to use no live API calls
- Use model_fields instead of deprecated __fields__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant