googleapis / googleapis/python-genai

Enum of type: int: X not validating

Aperta
#2,199 3 commenti 0 reazioni 1 assegnatario Rivendicata da @Venkaiahbabuneelam Vedi su GitHub
priority: p2 type: bug
Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
2g 11h
PR unite (30g)
40

Descrizione

#### 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(

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.