Skip to main content

ModelFieldsSchema

This class defines the schema for model fields within a TypedDict structure, specifically for use in data validation and serialization frameworks. It maps field names to their respective definitions while supporting additional configurations such as computed fields, strict mode, and attribute-based loading. The schema also provides hooks for handling extra behaviors, metadata, and custom serialization logic.

Attributes

AttributeTypeDescription
typeLiteral['model-fields']A fixed literal identifier used to distinguish this schema as a model-fields type.
fieldsdict[str, [ModelField](modelfield.md?sid=pydantic_core_core_schema_modelfield)]A mapping of field names to their respective ModelField definitions which define the structure of the model.
model_namestringThe name of the model class used for identification and error messaging.
computed_fieldslist[[ComputedField](computedfield.md?sid=pydantic_core_core_schema_computedfield)]A list of fields that are calculated from other attributes rather than being directly assigned.
strictbooleanA boolean flag that determines whether to enforce strict validation rules for the model fields.
extras_schemaCoreSchemaThe CoreSchema used to validate any extra fields provided that are not explicitly defined in the fields mapping.
extras_keys_schemaCoreSchemaThe CoreSchema used to validate the keys of any extra fields provided to the model.
extra_behaviorExtraBehaviorDefines how the model should handle fields that are not defined in the schema, such as allowing, forbidding, or ignoring them.
from_attributesbooleanWhether to allow extracting values from object attributes during validation instead of just mapping-like objects.
refstringA unique string reference used for recursive schemas or to identify this specific schema in a larger context.
metadatadict[str, Any]A dictionary of arbitrary metadata used to store additional information for third-party extensions or custom logic.
serializationSerSchemaThe serialization schema used to define how the model should be converted into a serializable format.