-
Notifications
You must be signed in to change notification settings - Fork 819
Enum of type: int: X not validating #2199
Copy link
Copy link
Open
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Environment details
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")
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(