Repaso
Español
Backend & APIsIntermediateAPI-05

FastAPI receives a body that fails Pydantic validation. Default response status?

Options

  1. 400
  2. 404
  3. 422 (Correct option)
  4. 500

Answer

422

Why

FastAPI validates the request body with Pydantic models. If a field is missing or has the wrong type, it automatically returns 422 Unprocessable Entity, with a list explaining which field failed and why.

Your endpoint code never runs. 400 is a more generic 'bad request'.

Remember

FastAPI validation error → 422.

Key terms

Practice this question in Repaso