Validation¶
Field validation logic for checking constraints on configuration values.
validation ¶
Field validation logic for dotenvmodel.
validate_field ¶
Validate a field value against its constraints.
When to use
- Called automatically by
DotEnvConfig.load()after type coercion - Call directly if you need to validate a value outside of config loading
Validates
- Numeric constraints:
ge,le,gt,lt(for int, float, Decimal) - String constraints:
min_length,max_length,regex(for str, SecretStr) - Choice validation:
choices(for any type) - Collection size:
min_items,max_items(for list, set, tuple, dict) - UUID version:
uuid_version(for UUID)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
Name of the field being validated (for error messages) |
required |
value
|
Any
|
Value to validate (already type-coerced) |
required |
field_info
|
FieldInfo
|
Field metadata containing validation constraints |
required |
env_var_name
|
str
|
Name of the environment variable (for error messages) |
required |
Raises:
| Type | Description |
|---|---|
ConstraintViolationError
|
If any constraint is violated |
See Also
FieldInfo: Contains all constraint definitions.ConstraintViolationError: Exception on failure.