Structured output pydantic validation error with int enum

I have a class with an int enum property and I get the following validation error:

properties.time_sensitivity.enum.0
  Input should be a valid string [type=string_type, input_value=0, input_type=int]
    For further information visit https://errors.pydantic.dev/2.10/v/string_type

These is my class and enum:

class OneBasedScale(int, Enum):
    one = 1
    two = 2
    three = 3
    four = 4
    five = 5
    six = 6
    seven = 7
    eight = 8
    nine = 9
    ten = 10

class MetadataSchema_1(BaseModel):
    time_sensitivity: ZeroBasedScale

The documentation states:

Note: Pydantic validators are not yet supported. If a pydantic.ValidationError occurs, it is suppressed, and .parsed may be empty/null.

But the errors are not being suppressed and since validators are not supported, I’m not able to add a “before” validator to convert the strings to int. I added “field before” validator anyway, just to check, and it didn’t run. This happens with the latest 2.5 flash and pro.

The real issue is that the models return string when they should be returning int for this property. The documentation does seem to imply that only string enums are supported?

In some cases you might want the model to choose a single option from a list of options. To implement this behavior, you can pass an enum in your schema. You can use an enum option anywhere you could use a string in the responseSchema , because an enum is an array of strings.

Is there any way to handle this without changing my int enum properties to string? Also, why aren’t the validation errors being suppressed?

@roberto_agi

welcome to the community,

as you mentioned in your post the model can only give string information. this is true with any llm . so there is no supported way to get int from the model itself.

Thanks for the welcome and the response. This is actually NOT an issue with any LLM. I can use structured output with the same pydantic classes on OpenAI, Anthropic, and xAI and they all return the correct int values for the enum. The only LLM’s that fail are from Google.

The other issue is that validation errors are not being suppressed, which according to the documentation, should be happening.