ValidationState
This class manages the state of a validation process, tracking metadata such as recursion depth, field exactness, and partial validation modes. It maintains context for structured types by tracking field error status, the current field name, and the data dictionary used for validator functions. Additionally, it provides access to the instance being validated and internal configuration for handling extra fields.
Attributes
| Attribute | Type | Description |
|---|---|---|
| recursion_guard | [RecursionState](../../../recursion/guard/recursionstate.md?sid=recursion_guard_recursionstate) | Manages the current recursion depth to prevent stack overflows during nested validation cycles. |
| exactness | [Exactness](exactness.md?sid=validators_validation_state_exactness) | Tracks whether the validation process requires an exact type match or allows for type coercion. |
| fields_set_count | usize | A tally of validated fields used as a tie-breaking mechanism for union validation, excluding extra fields. |
| allow_partial | PartialMode | Indicates if partial validation is enabled, specifically when processing the final element of a sequence or mapping. |
| has_field_error | bool | Flag indicating if at least one field encountered a validation error, used to determine if default factories should be called. |
| field_name | PyString | The name of the field being validated, if applicable. |
| data | PyDict | This is used as the data kwargs to validator functions and default factories (if they accept the argument). |
| self_instance | PyAny | This is an instance of the model or dataclass being validated, when validation is performed from __init__. |
| extra | [Extra](../../mod/extra.md?sid=validators_mod_extra) | Stores additional context or configuration for the validation process and is deliberately read-only. |
Constructor
Signature
def ValidationState()
Methods
field_name()
def field_name() - > string
The name of the field being validated, if applicable.
Returns
| Type | Description |
|---|---|
string | The name of the current field as a Python string, or null if not in a field context |