Skip to main content

ConfigDict

A TypedDict for configuring Pydantic behaviour.

Attributes

AttributeTypeDescription
title`strNone` = None
model_title_generator`Callable[[type], str]None` = None
field_title_generator`Callable[[str, FieldInfoComputedFieldInfo], str]
str_to_lowerbool = FalseWhether to convert all characters to lowercase for str types. Defaults to False.
str_to_upperbool = FalseWhether to convert all characters to uppercase for str types. Defaults to False.
str_strip_whitespaceboolWhether to strip leading and trailing whitespace for str types.
str_min_lengthint = NoneThe minimum length for str types. Defaults to None.
str_max_length`intNone` = None
extra`ExtraValuesNone` = 'ignore'
frozenbool = FalseWhether models are faux-immutable, i.e. whether __setattr__ is allowed, and also generates a __hash__() method for the model.
populate_by_namebool = FalseWhether an aliased field may be populated by its name as given by the model attribute, as well as the alias. Defaults to False.
use_enum_valuesbool = FalseWhether to populate models with the [value][enum.Enum.value] property of enums, rather than the raw enum. Defaults to False.
validate_assignmentbool = FalseWhether to validate the data when the model is changed. Defaults to False.
arbitrary_types_allowedbool = FalseWhether arbitrary types are allowed for field types. Defaults to False.
from_attributesboolWhether to build models and look up discriminators of tagged unions using python object attributes.
loc_by_aliasbool = TrueWhether to use the actual key provided in the data (e.g. alias) for error locs rather than the field's name. Defaults to True.
alias_generator`Callable[[str], str]AliasGenerator
ignored_typestuple[type, ...] = ()A tuple of types that may occur as values of class attributes without annotations. Defaults to ().
allow_inf_nanbool = TrueWhether to allow infinity (+inf an -inf) and NaN values to float and decimal fields. Defaults to True.
json_schema_extra`JsonDictJsonSchemaExtraCallable
json_encoders`dict[type[object], JsonEncoder]None` = None
strictboolWhether strict validation is applied to all fields on the model.
revalidate_instancesLiteral['always', 'never', 'subclass-instances'] = 'never'When and how to revalidate models and dataclasses during validation. Defaults to 'never'.
ser_json_timedeltaLiteral['iso8601', 'float'] = 'iso8601'The format of JSON serialized timedeltas. Accepts the string values of 'iso8601' and 'float'. Defaults to 'iso8601'.
ser_json_temporalLiteral['iso8601', 'seconds', 'milliseconds'] = 'iso8601'The format of JSON serialized temporal types from the [datetime][] module. Defaults to 'iso8601'.
val_temporal_unitLiteral['seconds', 'milliseconds', 'infer'] = 'infer'The unit to assume for validating numeric input for datetime-like types ([datetime.datetime][] and [datetime.date][]). Defaults to 'infer'.
ser_json_bytesLiteral['utf8', 'base64', 'hex'] = 'utf8'The encoding of JSON serialized bytes. Defaults to 'utf8'.
val_json_bytesLiteral['utf8', 'base64', 'hex'] = 'utf8'The encoding of JSON serialized bytes to decode. Defaults to 'utf8'.
ser_json_inf_nanLiteral['null', 'constants', 'strings'] = 'null'The encoding of JSON serialized infinity and NaN float values. Defaults to 'null'.
validate_defaultbool = FalseWhether to validate default values during validation. Defaults to False.
validate_returnbool = FalseWhether to validate the return value from call validators. Defaults to False.
protected_namespaces`tuple[strPattern[str], ...]` = ('model_validate', 'model_dump')
hide_input_in_errorsbool = FalseWhether to hide inputs when printing errors. Defaults to False.
defer_buildbool = FalseWhether to defer model validator and serializer construction until the first model validation. Defaults to False.
plugin_settings`dict[str, object]None` = None
schema_generator`type[_GenerateSchema]None`
json_schema_serialization_defaults_requiredbool = FalseWhether fields with default values should be marked as required in the serialization schema. Defaults to False.
json_schema_mode_overrideLiteral['validation', 'serialization', None] = NoneIf not None, the specified mode will be used to generate the JSON schema regardless of what mode was passed to the function call. Defaults to None.
coerce_numbers_to_strbool = FalseIf True, enables automatic coercion of any Number type to str in "lax" (non-strict) mode. Defaults to False.
regex_engineLiteral['rust-regex', 'python-re'] = 'rust-regex'The regex engine to be used for pattern validation. Defaults to 'rust-regex'.
validation_error_causebool = FalseIf True, Python exceptions that were part of a validation failure will be shown as an exception group as a cause. Defaults to False.
use_attribute_docstringsbool = FalseWhether docstrings of attributes (bare string literals immediately following the attribute declaration) should be used for field descriptions. Defaults to False.
cache_strings`boolLiteral['all', 'keys', 'none']` = True
validate_by_aliasbool = TrueWhether an aliased field may be populated by its alias. Defaults to True.
validate_by_namebool = FalseWhether an aliased field may be populated by its name as given by the model attribute. Defaults to False.
serialize_by_aliasbool = FalseWhether an aliased field should be serialized by its alias. Defaults to False.
url_preserve_empty_pathbool = FalseWhether to preserve empty URL paths when validating values for a URL type. Defaults to False.
polymorphic_serializationbool = FalseWhether to use polymorphic serialization for subclasses of the model or Pydantic dataclass. Defaults to False.

Constructor

Signature

def ConfigDict()

Signature

def ConfigDict()