nullable_schema
Returns a schema that matches a nullable value, e.g.:
from pydantic_core import SchemaValidator, core_schema
schema = core_schema.nullable_schema(core_schema.str_schema())
v = SchemaValidator(schema)
assert v.validate_python(None) is None
def nullable_schema(
schema: CoreSchema,
strict: bool | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: SerSchema | None = None
) - > NullableSchema
Returns a schema that matches a nullable value, e.g.:
from pydantic_core import SchemaValidator, core_schema
schema = core_schema.nullable_schema(core_schema.str_schema())
v = SchemaValidator(schema)
assert v.validate_python(None) is None
Parameters
| Name | Type | Description |
|---|---|---|
| schema | CoreSchema | The inner schema to wrap, defining the type that is allowed to be null. |
| strict | `bool | None` = None |
| ref | `str | None` = None |
| metadata | `dict[str, Any] | None` = None |
| serialization | `SerSchema | None` = None |
Returns
| Type | Description |
|---|---|
NullableSchema | A schema definition that allows the wrapped type to accept None values during validation. |