The request is well-formed but fails validation.
When to use it
Valid JSON with invalid values, like an end date before the start date.
Common causes and fixes
422 means the server understood the syntax, but the content fails validation: a required field is empty, an email is malformed, a date range is reversed, or a referenced ID doesn’t exist. FastAPI returns it for every Pydantic validation error, and Rails and Laravel use it for failed model validation. Rails also returns 422 for an invalid CSRF token, which surprises people.
Return field-level errors in the body so the client can show them next to the right inputs, ideally in a consistent shape such as RFC 9457 problem details. Don’t retry a 422 without changing the data. Teams disagree on 400 versus 422; pick one rule, for example 400 for unparseable input and 422 for well-formed but invalid input, and apply it everywhere.
Client error (4xx)
4xx codes are client errors: the request itself is wrong, unauthorised or points at something that isn’t there. Retrying the same request won’t help.
What it looks like
HTTP/1.1 422 Unprocessable ContentHow to send it
| Node.js / Express | res.status(422).end() |
|---|---|
| Python / Flask | return '', 422 |
| nginx | return 422; |
How to check it
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/