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
Common Cause
Required fields missing from the request body
Common Cause
Field values failing validation rules (email format, min/max length)
Common Cause
Enum values that are not in the allowed set
Common Cause
Business logic validation failures (e.g., duplicate entry, out-of-stock)
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
}
]
}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:
400 400 Bad Request
The server cannot process the request due to client-side input errors.
401 401 Unauthorized
Authentication is required but was missing or invalid.
403 403 Forbidden
The client is authenticated but does not have permission to access the resource.
404 404 Not Found
The requested resource could not be found on the server.
405 405 Method Not Allowed
The HTTP method used is not allowed for this resource.
408 408 Request Timeout
The server timed out waiting for the client to send the complete request.
413 413 Payload Too Large
The request body exceeds the server's maximum allowed size.
429 429 Too Many Requests
The client has exceeded the rate limit and should slow down.
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.