422 🌐 HTTP

HTTP 422 Unprocessable Content

The request is well-formed, but the data fails validation (e.g. invalid email, missing required field).

Seen on: PHP Python JavaScript

Meaning

422 means “I understood your request, but the content doesn’t make sense.” It’s the standard validation-error status in Laravel, Rails and FastAPI. The response body almost always lists the failing fields.

Common causes

  • Required fields missing or empty
  • Values in the wrong format (email, date, enum)
  • Business rule violations (duplicate username, end date before start date)
  • Field names don’t match what the API expects (camelCase vs snake_case)
  • FastAPI/Pydantic: body schema mismatch or wrong types

⚡ Quick fix

  1. Read the errors object in the response body — it names each failing field
  2. Compare your payload field names and types with the API schema
  3. Log the exact payload you send

Detailed fix by platform

PHP

  1. Laravel returns 422 from $request->validate(); send Accept: application/json to get JSON errors instead of a redirect.

Python

  1. FastAPI: the detail array shows loc (field path) and msg. Check that you send JSON, not form data, for Pydantic body models.

JavaScript

  1. Display server validation errors:
    javascript
    if (res.status === 422) {
      const { errors } = await res.json();   // { email: ["The email must be valid."] }
      Object.entries(errors).forEach(([field, msgs]) => showFieldError(field, msgs[0]));
    }

How to diagnose

  1. Response body — Which fields failed and why?
  2. Payload — Do names and types match the schema?
  3. Rules — Any uniqueness or cross-field rules?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.