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 theresponseSchema
, 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?