googleapis / googleapis/python-genai
Enum of type: int: X not validating
- Dominant language
- Python
- Stars
- 4k
- Forks
- 1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 40
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(
Contributor guide
Assessment
This issue has not been assessed yet.