FastAPI receives a body that fails Pydantic validation. Default response status?
Options
- 400
- 404
- 422 (Correct option)
- 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.