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

Open Beginner friendly
#3,044 1 comment 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@Venkaiahbabuneelam is already working on this.

Since Oct 5, 2026.

  • #3045 by @chauvuusvn — open
  • #3091 by @DavidLeeGarrett — closed without merging
  • #3177 by @copybara-service — closed without merging
  • #3280 by @copybara-service — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api

Research direction

Start in google/genai/_extra_utils.py at convert_if_exist_pydantic_model and reproduce the typing.List and typing.Dict examples from the issue. Check the behavior when get_args(annotation) is empty, then verify that both calls return their original values without raising errors.

Written by the indexing model from the issue text.

Description

priority: p2 type: bug
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.

Dominant language
Python
Stars
4.1k
Forks
1.1k
Avg merge
1d 20h
Merged PRs (30d)
90

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/python-genai

All issues in googleapis/python-genai

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.