Skip to main content

set_schema

Returns a schema that matches a set of a given schema, e.g.:

from pydantic_core import SchemaValidator, core_schema

schema = core_schema.set_schema(
items_schema=core_schema.int_schema(), min_length=0, max_length=10
)
v = SchemaValidator(schema)
assert v.validate_python({1, '2', 3}) == {1, 2, 3}
def set_schema(
items_schema: CoreSchema | None = None,
min_length: int | None = None,
max_length: int | None = None,
fail_fast: bool | None = None,
strict: bool | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: SerSchema | None = None
) - > SetSchema

Returns a schema that matches a set of a given schema.

Parameters

NameTypeDescription
items_schema`CoreSchemaNone` = None
min_length`intNone` = None
max_length`intNone` = None
fail_fast`boolNone` = None
strict`boolNone` = None
ref`strNone` = None
metadata`dict[str, Any]None` = None
serialization`SerSchemaNone` = None

Returns

TypeDescription
SetSchemaA dictionary representing the set validation schema, containing the specified constraints and item definitions.