What is the difference between a 400 Bad Request and a 422 Unprocessable Entity, and when would you use each?

Last updated 29 June 2026

  • 400 Bad Request: the request is malformed (invalid JSON, broken query string), so parsing fails before any logic runs.

  • 422 Unprocessable Entity: syntax parses fine but values fail validation (bad email, negative age). FastAPI returns it automatically on Pydantic validation errors.

  • Many APIs use 400 for both. Be consistent and return a detailed error body either way.

  • https://stackoverflow.com/questions/16133923/400-vs-422-response-to-post-of-data
  • https://dev.to/ramkumar-kollimalayan/choosing-the-right-http-status-code-in-rest-apis-a-practical-guide-1dih
All REST API interview questions