Skip to main content

Discriminator

This enum defines the strategy used to identify which variant of a union should be used during validation. It supports either traversing specific data paths to locate a tag value or executing a custom function to determine the appropriate discriminator.

Attributes

AttributeTypeDescription
LookupPathsSmallVec< [LookupPath; 1] >A collection of lookup paths used to find the tag, following the same logic as value retrieval in typed_dict aliases.
FunctionPy< PyAny >A reference to a Python function that is called to determine the appropriate tag to use.

Constructor

Signature

def LookupPaths(
paths: SmallVec< [LookupPath; 1] >
) - > [Discriminator](../../pydantic/types/discriminator.md?sid=pydantic_types_discriminator)

Parameters

NameTypeDescription
pathsSmallVec< [LookupPath; 1] >A collection of lookup paths used to locate the discriminator tag within the input data.

Signature

def Function(
func: Py< PyAny >
) - > [Discriminator](../../pydantic/types/discriminator.md?sid=pydantic_types_discriminator)

Parameters

NameTypeDescription
funcPy< PyAny >A reference to a Python callable that returns the discriminator tag for a given input.