pydantic
Pydantic Error Codes
Error type identifiers used by Pydantic v2, the Python data validation library. These codes appear as the 'type' field in ValidationError details and as the 'code' property on PydanticUserError exceptions.
45 codes
references docs.pydantic.dev/latest/errors/validation_errors/docs.pydantic.dev/latest/errors/usage_errors/
· All codes 45 codes
- assertion_error Assertion Error A field validator raised an AssertionError (e.g. via assert). The error message comes from the assertion or the validator function.
- bool_parsing Boolean Parsing Error The input string could not be parsed as a boolean. Accepted string values include 'true', 'false', 'yes', 'no', '1', and '0' (case-insensitive).
- bool_type Boolean Type Expected The input value is not a valid boolean. In strict mode, Pydantic only accepts True/False; in lax mode it also accepts 1/0 and certain strings.
- date_type Date Type Error The input value could not be interpreted as a date. In lax mode, ISO 8601 date strings are accepted; in strict mode only date objects are allowed.
- datetime_type Datetime Type Error The input value could not be interpreted as a datetime. In lax mode, ISO 8601 strings and numeric timestamps are accepted; in strict mode only datetime objects are allowed.
- decimal_max_digits Decimal Has Too Many Digits The Decimal value has more total digits than the max_digits constraint allows.
- decimal_max_places Decimal Has Too Many Decimal Places The Decimal value has more digits after the decimal point than the decimal_places constraint allows.
- decimal_type Decimal Type Error The input value cannot be interpreted as a Decimal. Accepted types include integers, floats, strings, and Decimal objects.
- dict_type Dictionary Type Expected The input value is not a dictionary. In strict mode only actual dict instances are accepted; in lax mode mappings may be coerced.
- enum Enum Value Error The input value is not a valid member of the expected enum. The value must be one of the enum's defined members.
- extra_forbidden Extra Fields Forbidden The input contains fields not defined in the model, and the model is configured with model_config = {'extra': 'forbid'}. Remove the unexpected fields or change the extra setting.
- float_parsing Float Parsing Error The input string could not be parsed as a floating-point number. Ensure the value is a valid numeric string.
- float_type Float Type Expected The input value is not a valid number. Pydantic expected a float but received a value it cannot interpret as a numeric type.
- frozen_instance Instance Is Frozen An attempt was made to modify a field on a model instance that was configured with frozen=True. Frozen models are immutable after construction.
- greater_than Value Too Small (Greater Than Constraint) The numeric input is not strictly greater than the gt constraint value.
- greater_than_equal Value Below Minimum (Greater Than or Equal Constraint) The numeric input is less than the ge (greater-than-or-equal) constraint value.
- int_from_float Integer Expected, Got Float With Fractional Part A float was provided for an integer field but it has a non-zero fractional part (e.g. 1.5). Use a whole number or change the field type to float.
- int_parsing Integer Parsing Error The input value (typically a string) could not be parsed as an integer. Ensure the value contains only digits (and an optional leading sign).
- int_type Integer Type Expected The input value is not a valid integer. Pydantic expected an int but received a value it cannot coerce to one.
- is_instance_of Instance Check Failed The input value is not an instance of the expected type. This occurs with IsInstance[] annotated types or in strict mode for object fields.
- json_invalid Invalid JSON The input string could not be parsed as valid JSON. This occurs when a Json[] annotated field receives malformed JSON.
- json_type JSON Input Must Be String or Bytes A Json[] annotated field received a value that is not a string, bytes, or bytearray. Only these types can be parsed as JSON.
- less_than Value Too Large (Less Than Constraint) The numeric input is not strictly less than the lt constraint value.
- less_than_equal Value Exceeds Maximum (Less Than or Equal Constraint) The numeric input exceeds the le (less-than-or-equal) constraint value.
- list_type List Type Expected The input value is not a list. In strict mode only actual list instances are accepted; in lax mode other sequences may be coerced.
- literal_error Literal Value Error The input value is not one of the allowed literal values specified with Literal[...]. The value must exactly match one of the declared options.
- missing Required Field Missing A required field was not provided in the input data. The field has no default value and must be supplied.
- model_type Model Type Error The input value is not a valid dictionary or model instance. Pydantic models expect a dict or an existing model instance for initialization.
- multiple_of Value Not a Multiple Of The numeric input is not a multiple of the multiple_of constraint value.
- recursion_loop Recursion Loop Detected A cyclic reference was detected while validating nested models. The object graph contains a cycle that Pydantic cannot resolve.
- set_type Set Type Expected The input value is not a set or frozenset. In lax mode other sequences may be coerced to a set.
- string_pattern_mismatch String Pattern Mismatch The input string does not match the regular expression pattern constraint defined on the field.
- string_too_long String Too Long The input string exceeds the maximum length constraint (max_length) defined on the field.
- string_too_short String Too Short The input string is shorter than the minimum length constraint (min_length) defined on the field.
- string_type String Type Expected The input value is not a string. Pydantic expected a str (or bytes/bytearray in some contexts) but received a different type.
- tuple_length Wrong Tuple Length A fixed-length tuple field received a sequence with the wrong number of items after validation.
- tuple_type Tuple Type Expected The input value is not a tuple. In lax mode other sequences may be coerced to a tuple.
- union_tag_invalid Union Discriminator Tag Invalid The value of the discriminator field does not match any of the expected tag values for the discriminated union. Check that the discriminator field value corresponds to one of the union's model types.
- union_tag_not_found Union Discriminator Tag Not Found The discriminator field specified for a discriminated union is absent from the input data.
- url_parsing URL Parsing Error The input string could not be parsed as a valid URL. Check that the URL is well-formed and includes a valid scheme.
- url_scheme URL Scheme Not Permitted The URL's scheme is not in the list of allowed schemes defined on the field (e.g. the field allows only 'https' but 'http' was provided).
- url_type URL Type Error The input is not a string or URL instance. Pydantic URL fields expect a string that can be parsed as a URL.
- uuid_parsing UUID Parsing Error The input string could not be parsed as a valid UUID. Ensure it conforms to the standard 8-4-4-4-12 hexadecimal format.
- uuid_type UUID Type Error The input value is not a valid UUID. Pydantic accepts UUID instances or strings/bytes in standard UUID format.
- value_error Value Error A field validator raised a ValueError. The error message comes from the validator function and describes the specific constraint that was violated.