Skip to main content

chain_schema

Returns a schema that chains the provided validation schemas, e.g.:

```py
from pydantic_core import SchemaValidator, core_schema

def fn(v: str, info: core_schema.ValidationInfo) - > str:
assert 'hello' in v
return v + ' world'

fn_schema = core_schema.with_info_plain_validator_function(function=fn)
schema = core_schema.chain_schema(
[fn_schema, fn_schema, fn_schema, core_schema.str_schema()]
)
v = SchemaValidator(schema)
assert v.validate_python('hello') == 'hello world world world'
```
def chain_schema(
steps: list[CoreSchema],
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: SerSchema | None = None
) - > ChainSchema

Returns a schema that chains the provided validation schemas.

Parameters

NameTypeDescription
stepslist[CoreSchema]The sequence of validation schemas to be executed in order.
ref`strNone` = None
metadata`dict[str, Any]None` = None
serialization`SerSchemaNone` = None

Returns

TypeDescription
ChainSchemaA schema object that executes multiple validation steps in sequence, passing the output of one step as the input to the next.