How to List the Errors of a Pydantic ValidationError with errors()
When Pydantic rejects data it raises a ValidationError whose printed form is long and technical. error.errors() gives the same information as a list of dictionaries, one per problem, so you can turn it into a short message of your own. This guide shows the fields you get, with real output from Pydantic 2.14.4.
Syntax
from pydantic import ValidationError
try:
<create or validate a model>
except ValidationError as error:
for problem in error.errors():
<use problem["loc"], problem["type"], problem["msg"]>
| Part | What it means |
|---|---|
error.errors() | A list with one dictionary per problem |
problem["loc"] | Where the problem is, as a tuple; the first item is the field's name |
problem["type"] | A short code, such as missing or int_parsing |
problem["msg"] | A sentence describing the problem |
Pydantic's documentation: errors() "Returns a list of ErrorDetails errors found in the input data." Each one also has input, the value that failed, and some have ctx and url. "The first item in the loc list will be the field where the error occurred".
Prerequisites
- Pydantic 2 in a uv project. This guide uses Pydantic 2.14.4, added with
uv add pydantic, on Python 3.15.2.
Step 1: Write the Script
from pydantic import BaseModel, ValidationError
class Booking(BaseModel):
name: str
nights: int
try:
Booking(nights="two")
except ValidationError as error:
for problem in error.errors():
print(problem["loc"], problem["type"], problem["msg"])

The booking breaks two rules: name is missing, and "two" isn't an integer.
Step 2: Run It
uv run python booking.py
('name',) missing Field required
('nights',) int_parsing Input should be a valid integer, unable to parse string as an integer

Pydantic checked every field before raising, so both problems arrived together. loc[0] is the field's name, which makes a compact message easy: f"{problem['loc'][0]}: {problem['msg']}" gives name: Field required.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Stopping after the first error | The user fixes one problem, then meets the next | Loop over all of errors() |
Showing problem["input"] in a message | For a missing field, input is the whole input, here {'nights': 'two'}, and it may hold secrets | Show the field and message, not the input |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
problem["loc"] has more than one item | The error is inside a nested model or list | Join the items, as in ".".join(map(str, problem["loc"])) |
FAQ
How do I count the problems?
error.error_count() returns the number; here it's 2.
Can I change the messages?
Yes. Map problem["type"] to your own text, and fall back to problem["msg"] for types you haven't mapped.
Conclusion
error.errors() turned one ValidationError into two clear entries, ('name',) missing Field required and ('nights',) int_parsing ..., ready to print in your own words.
Additional Resources
- Error handling —
errors(),error_count()and the fields of each error.
