Aarunya AppsAarunya Apps
422
Unprocessable Entity
Client Error

HTTP 422 Unprocessable Entity — Semantic Validation vs 400

The request is well-formed (correct syntax, valid Content-Type) but contains semantic errors that prevent processing. The server understands the content type and the request structure but was unable to process the contained instructions.

When to Return 422

Use 422 for business-logic validation failures distinct from format errors: a valid JSON body where the values fail domain rules (e.g., start date after end date, negative price). Use 400 for structural/format errors.

Common Causes

  • Start date is after end date
  • Requested quantity exceeds available stock
  • Age below minimum required (must be 18+)
  • Password does not meet complexity requirements
  • Circular reference in hierarchical data

HTTP Response Example

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

{"error": "Unprocessable Entity", "message": "startDate must be before endDate"}

Code Examples

Express.js
app.post('/bookings', async (req, res) => {
  const { startDate, endDate, roomId } = req.body

  // Structural validation (400)
  if (!startDate || !endDate) {
    return res.status(400).json({ error: 'startDate and endDate are required' })
  }

  // Semantic validation (422)
  if (new Date(startDate) >= new Date(endDate)) {
    return res.status(422).json({
      error: 'Unprocessable Entity',
      message: 'startDate must be before endDate',
    })
  }
  // proceed
})
Next.js App Router
export async function POST(request: Request) {
  const { startDate, endDate } = await request.json()
  if (new Date(startDate) >= new Date(endDate)) {
    return Response.json(
      { error: 'Unprocessable Entity', message: 'startDate must be before endDate' },
      { status: 422 }
    )
  }
}

Related Status Codes

All HTTP status codes

Browse the complete HTTP status code reference.

All Status Codes

Frequently Asked Questions

What does HTTP 422 Unprocessable Entity mean?

The request is well-formed (correct syntax, valid Content-Type) but contains semantic errors that prevent processing. The server understands the content type and the request structure but was unable to process the contained instructions.

When should an API return 422?

Use 422 for business-logic validation failures distinct from format errors: a valid JSON body where the values fail domain rules (e.g., start date after end date, negative price). Use 400 for structural/format errors.

What causes an HTTP 422 error?

Common causes: Start date is after end date; Requested quantity exceeds available stock; Age below minimum required (must be 18+); Password does not meet complexity requirements; Circular reference in hierarchical data.