HTTP Status Codes

422 422 Unprocessable Entity

The request has valid syntax but contains semantic validation errors.

What Is This?

The HTTP 422 Unprocessable Entity status code (defined in WebDAV extension RFC 4918) indicates that the server understands the request content type and syntax, but the request contains semantic validation errors. Unlike 400 (malformed syntax), 422 means the request is syntactically correct but semantically invalid — missing required fields, values out of range, or business rule violations.

Common Causes & Solutions

1

Common Cause

Required fields missing from the request body

2

Common Cause

Field values failing validation rules (email format, min/max length)

3

Common Cause

Enum values that are not in the allowed set

4

Common Cause

Business logic validation failures (e.g., duplicate entry, out-of-stock)

5

Return detailed field-level errors

Include a structured error response with field-level validation messages to help clients fix specific issues.

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json

{
  "error": "Validation Failed",
  "details": [
    {
      "field": "email",
      "message": "Must be a valid email address",
      "value": "invalid-email"
第    },
    {
      "field": "age",
      "message": "Must be between 18 and 120",
      "value": 15
    }
  ]
}
6

Validate with schema libraries

Use validation libraries like Zod, Joi, or Yup to define schemas and automatically generate validation error responses.

// Zod schema validation
import { z } from 'zod'

const userSchema = z.object({
  email: z.string().email('Must be a valid email'),
  age: z.number().min(18).max(120),
  name: z.string().min(1, 'Name is required'),
})

app.post('/api/users', (req, res) => {
  const result = userSchema.safeParse(req.body)
  if (!result.success) {
    return res.status(422).json({
      error: 'Validation Failed',
      details: result.error.issues.map(i => ({
        field: i.path.join('.'),
        message: i.message
      }))
    })
  }
  // Process valid data...
})

Related Entries

More from this reference:

Frequently Asked Questions

Should I use 400 or 422 for validation errors?

Use 422 for semantic validation errors (invalid field values, missing required fields) and 400 for structural errors (malformed JSON, invalid Content-Type). This distinction helps API clients handle errors more precisely.

Is 422 part of the standard HTTP specification?

422 is defined in the WebDAV extension (RFC 4918) but is widely adopted by REST APIs including Rails, Django REST Framework, and many others. It is supported by all modern HTTP clients and frameworks.