API Reference
pydantic-explain: human-readable error messages for Pydantic validation errors.
ErrorDetail
dataclass
A single parsed validation error.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
Dotted path to the field, e.g. |
message |
str
|
Human-readable error message from Pydantic. |
error_type |
str
|
Pydantic error type code, e.g. |
input_value |
Any
|
The actual invalid input value. |
context |
dict[str, Any]
|
Extra context dict from Pydantic. |
url |
str
|
Pydantic documentation URL for this error type. |
Source code in src/pydantic_explain/_types.py
| Python | |
|---|---|
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
FormatOptions
dataclass
Configuration for error formatting.
Attributes:
| Name | Type | Description |
|---|---|---|
show_input |
bool
|
Whether to show the |
show_url |
bool
|
Whether to show the Pydantic docs URL. |
show_error_type |
bool
|
Whether to show the error type tag. |
input_max_length |
int
|
Maximum length for input value repr. |
Source code in src/pydantic_explain/_types.py
| Python | |
|---|---|
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
explain(error)
Parse a Pydantic ValidationError into structured ErrorDetail objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
ValidationError
|
A Pydantic ValidationError instance. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ErrorDetail, ...]
|
A tuple of ErrorDetail objects, one per validation error. |
Source code in src/pydantic_explain/_explain.py
| Python | |
|---|---|
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
format_error_detail(detail, *, options=None)
Format a single ErrorDetail as a human-readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detail
|
ErrorDetail
|
A parsed error detail. |
required |
options
|
FormatOptions | None
|
Formatting options. Uses defaults if None. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A formatted multi-line string for one validation error. |
Source code in src/pydantic_explain/_format.py
| Python | |
|---|---|
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
format_errors(error, *, options=None)
Format a Pydantic ValidationError as a human-readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
ValidationError
|
A Pydantic ValidationError instance. |
required |
options
|
FormatOptions | None
|
Formatting options. Uses defaults if None. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A formatted multi-line string describing all validation errors. |
Source code in src/pydantic_explain/_format.py
| Python | |
|---|---|
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |