Skip to content

Enum of type: int: X not validating #2199

@alonahmias

Description

@alonahmias

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(

Metadata

Metadata

Labels

priority: p2Moderately-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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions