Skip to content

fix: support list[pydantic.BaseModel] in response.parsed type annotation : Issue #886#906

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

fix: support list[pydantic.BaseModel] in response.parsed type annotation : Issue #886#906
Adewale-1 wants to merge 6 commits intogoogleapis:mainfrom
Adewale-1:fix/typed-list-pydantic-parsed

Conversation

@Adewale-1
Copy link

This PR fixes issue #886 by adding support for list[pydantic.BaseModel] in the parsed field's type annotation of GenerateContentResponse.

Problem

Currently, when using response_schema=list[SomeModel] in the API call, the code functionally works (returning a list of model objects), but mypy type checking fails because the type annotation doesn't include the possibility of a list of pydantic models.

This requires developers to use explicit type casting (as shown in PR #886), which reduces confidence in unit tests and type safety.

Solution

Added list[pydantic.BaseModel] to the Union type in the parsed field type annotation.

Testing

Added comprehensive tests in:

  • test_parsed_list_support.py
  • test_parsed_list_mypy.py
  • test_live_client_and_list_type.py

Tests verify both runtime behavior and mypy type checking compatibility.

@google-cla
Copy link

google-cla bot commented Jun 1, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ghost
Copy link

ghost commented Sep 9, 2025

@Adewale-1 looks like you will have to sign the contributor agreement for this PR to be accepted.

@janasangeetha janasangeetha self-assigned this Nov 7, 2025
@janasangeetha janasangeetha added the size:XL Code changes > 100 lines label Nov 7, 2025
@janasangeetha
Copy link
Collaborator

Hey @Adewale-1
Can you please resolve conflicts? Thank you!

Resolved merge conflicts in google/genai/types.py while preserving the
list[pydantic.BaseModel] support in the parsed field type annotation.
@Adewale-1 Adewale-1 force-pushed the fix/typed-list-pydantic-parsed branch from 5797bc6 to 12e18cc Compare November 7, 2025 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants