Skip to main content

model_schema

A model schema generally contains a typed-dict schema. It will run the typed dict validator, then create a new class and set the dict and fields set returned from the typed dict validator to __dict__ and __pydantic_fields_set__ respectively.

def model_schema(
cls: type[Any],
schema: CoreSchema,
generic_origin: type[Any] | None = None,
custom_init: bool | None = None,
root_model: bool | None = None,
post_init: str | None = None,
revalidate_instances: Literal['always', 'never', 'subclass-instances'] | None = None,
strict: bool | None = None,
frozen: bool | None = None,
extra_behavior: ExtraBehavior | None = None,
config: CoreConfig | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: SerSchema | None = None
) - > ModelSchema

A model schema generally contains a typed-dict schema. It will run the typed dict validator, then create a new class and set the dict and fields set returned from the typed dict validator to __dict__ and __pydantic_fields_set__ respectively.

Parameters

NameTypeDescription
clstype[Any]The Python class to be instantiated and populated by the model validator
schemaCoreSchemaThe underlying schema (typically a model_fields_schema) used to validate the model's data
generic_origin`type[Any]None` = None
custom_init`boolNone` = None
root_model`boolNone` = None
post_init`strNone` = None
revalidate_instances`Literal['always', 'never', 'subclass-instances']None` = None
strict`boolNone` = None
frozen`boolNone` = None
extra_behavior`ExtraBehaviorNone` = None
config`CoreConfigNone` = None
ref`strNone` = None
metadata`dict[str, Any]None` = None
serialization`SerSchemaNone` = None

Returns

TypeDescription
ModelSchemaA dictionary representing the Pydantic Core model schema configuration