pydantic / pydantic

Data validation using Python type hints
https://docs.pydantic.dev
MIT License
20.36k stars 1.83k forks source link

More information for debugging ValidationError #9890

Open will-e-yams opened 1 month ago

will-e-yams commented 1 month ago

Initial Checks

Description

When a single api call builds many objects it becomes very difficult to know which model failed to validate. Currently, we have:

But validation errors are needlessly obtuse:

{
  'type': 'string_type',
  'loc': ('form_name',),
  'msg': 'Input should be a valid string',
  'input': None,
  'url': 'https://errors.pydantic.dev/2.7/v/string_type'
}

Two things of note that I think are missing:

  1. the model (class name) that failed
  2. a stack trace so i can find it!

I'm not seeing ctx being used in ValidationError, so perhaps that could be used?

Affected Components

sydney-runkle commented 1 month ago

Hi @will-e-yams,

Could you please provide some sort of minimal reproducible example? It's hard for us to get enough context without a runnable snippet. Thanks!