googleapis / googleapis/python-genai

Enum of type: int: X not validating

Ouverte
#2,199 3 commentaires 0 réactions 1 personne assignée Réclamée par @Venkaiahbabuneelam Voir sur GitHub
priority: p2 type: bug
Langage dominant
Python
Étoiles
4k
Forks
1k
Merge moyen
2 j 12 h
PR mergées (30 j)
41

Description

#### Environment details

- Programming language: python
- OS: arch linux
- Language runtime version: 3.13
- Package version: 1.64.0

#### Steps to reproduce
from enum import IntEnum

from google import genai
from google.genai import types

# 1. Define an Integer-based Enum
class DaysEnum(IntEnum):
ONE = 1
FIVE = 5
TEN = 10

# 2. Define a Pydantic model using that Enum
def WeatherRequest(location: str, days: DaysEnum) -> str:
return f"Weather in {location} for {days} days"

def reproduce_error():
# Credentials aren't even needed to see the validation fail
# during schema transformation
client = genai.Client(api_key="DUMMY_KEY")

print("Attempting to use a tool with an IntEnum...")

try:
# The crash happens when the SDK tries to convert the
# Pydantic model into a Google API 'Schema' object.
response = client.models.generate_content(
model="gemini-3.1-flash-lite-preview",
contents="What is the weather in London for 5 days?",
config=types.GenerateContentConfig(tools=[WeatherRequest]),
)
except Exception as e:
print("\nCaught Expected Error:")
print(f"{type(e).__name__}: {e}")

if __name__ == "__main__":
reproduce_error()

The error:
*/.venv/lib/python3.13/site-packages/pydantic/main.py:464: UserWarning: Pydantic serializer warnings:
PydanticSerializationUnexpectedValue(Expected `str` - serialized value may not be as expected [field_name='enum', input_value=1, input_type=int])
PydanticSerializationUnexpectedValue(Expected `str` - serialized value may not be as expected [field_name='enum', input_value=5, input_type=int])
PydanticSerializationUnexpectedValue(Expected `str` - serialized value may not be as expected [field_name='enum', input_value=10, input_type=int])
return self.__pydantic_serializer__.to_python(

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.