What is the difference between a 400 Bad Request and a 422 Unprocessable Entity, and when would you use each?
Last updated
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
400for both. Be consistent and return a detailed error body either way.