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.
Describe the bug
In
google/genai/_extra_utils.py, insideconvert_if_exist_pydantic_model:When a user defines a tool function with unsubscripted generic type annotations like
typing.Listortyping.Dict:get_origin(List)islist, butget_args(List)returns(). Accessing[0]raisesIndexError: tuple index out of range.get_origin(Dict)isdict, butget_args(Dict)returns(). Unpacking_, value_type = get_args(Dict)raisesValueError: not enough values to unpack (expected 2, got 0).This causes Automatic Function Calling (AFC) to crash during function argument conversion.
Steps to Reproduce
Expected Behavior
If
get_args(annotation)is empty for unsubscriptedtyping.Listortyping.Dict,convert_if_exist_pydantic_modelshould safely return the originalvaluewithout raisingIndexErrororValueError.