Visitar URL original
[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFC · Issue #3044 · googleapis/python-genai · GitHub
Skip to content

[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFC #3044

Description

@chauvuusvn

Describe the bug

In google/genai/_extra_utils.py, inside convert_if_exist_pydantic_model:

if isinstance(value, list) and get_origin(annotation) == list:
    item_type = get_args(annotation)[0]  # Crashes with IndexError on typing.List
    ...
if isinstance(value, dict) and get_origin(annotation) == dict:
    _, value_type = get_args(annotation) # Crashes with ValueError on typing.Dict
    ...

When a user defines a tool function with unsubscripted generic type annotations like typing.List or typing.Dict:

  • get_origin(List) is list, but get_args(List) returns (). Accessing [0] raises IndexError: tuple index out of range.
  • get_origin(Dict) is dict, but get_args(Dict) returns (). Unpacking _, value_type = get_args(Dict) raises ValueError: not enough values to unpack (expected 2, got 0).

This causes Automatic Function Calling (AFC) to crash during function argument conversion.

Steps to Reproduce

from typing import Dict, List
from google.genai._extra_utils import convert_if_exist_pydantic_model

# 1. Test typing.List
convert_if_exist_pydantic_model([1, 2], List, 'items', 'my_func')
# Raises IndexError: tuple index out of range!

# 2. Test typing.Dict
convert_if_exist_pydantic_model({'a': 1}, Dict, 'config', 'my_func')
# Raises ValueError: not enough values to unpack (expected 2, got 0)!

Expected Behavior

If get_args(annotation) is empty for unsubscripted typing.List or typing.Dict, convert_if_exist_pydantic_model should safely return the original value without raising IndexError or ValueError.

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Oct 5, 2026
  2. Venkaiahbabuneelam commented on Oct 5, 2026

    @Venkaiahbabuneelam

    Hi @chauvuusvn, Thank you for bringing this to our attention. We truly appreciate you flagging this issue regarding unsubscripted typing.List and typing.Dict crashing convert_if_exist_pydantic_model in AFC, we will file a bug internally.
    Thanks

  3. added a commit that references this issue on Oct 9, 2026
    cdc3c4d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions