MEDIUM SEVERITYCONFIRMED
model_validator(mode='before') raises raw TypeError on bad input (not ValidationError)
Package
pydantic
Version
2.12.5
Verified
2026-03-28
Description
When a `model_validator(mode='before')` raises a raw `TypeError` (e.g., `can't multiply sequence by non-int of type 'str'`), pydantic does not wrap it in a `ValidationError`. The raw `TypeError` propagates to the caller. In FastAPI, this causes an HTTP 500 instead of a 422 validation error.
Reproduction
# Model with model_validator(mode='before') that triggers TypeError on string input
# e.g. validator multiplies a field by an int
# Result: TypeError propagates instead of ValidationError