HTTP 422 Unprocessable Entity means the request body is syntactically valid but semantically incorrect — the server understands the content type and syntax but cannot process the contained instructions. Originally a WebDAV status (RFC 4918), it's been adopted widely in REST APIs: valid JSON that fails business validation returns 422. FastAPI and many modern frameworks default to 422 for validation errors instead of 400.
Response includes the status code, standard headers (including Content-Type), and a small diagnostic JSON body describing the request and returned status.
Simulator URL (copy in the app after load — not a normal link):
https://httpstatus.com/api/status/422
Example request:
curl -i "https://httpstatus.com/api/status/422"The request was well-formed but semantically invalid (e.g., validation errors). Used when the syntax is correct but the content violates business rules.
On this code, Inspector focuses on semantics, headers, and correctness warnings that commonly affect clients and caches.
HTTP 422 Unprocessable Entity has specific technical implications for API design, caching, and client behavior. Understanding the precise semantics helps distinguish it from similar status codes and implement correct error handling. The response should include a descriptive body following a consistent error schema (like RFC 7807 Problem Details) so clients can programmatically handle the error.
// Handle 422 Unprocessable Entity in Express
app.use((err, req, res, next) => {
if (err.status === 422) {
return res.status(422).json({
type: 'https://api.example.com/errors/unprocessable-entity',
title: 'Unprocessable Entity',
status: 422,
detail: err.message
});
}
next(err);
});from fastapi import HTTPException
# Raise 422 Unprocessable Entity
raise HTTPException(
status_code=422,
detail={
'type': 'unprocessable_entity',
'message': 'Descriptive error for 422 Unprocessable Entity'
}
)// Spring Boot 422 Unprocessable Entity handling
@ExceptionHandler(CustomUnprocessableEntityException.class)
public ResponseEntity<ErrorResponse> handleUnprocessableEntity(
CustomUnprocessableEntityException ex) {
return ResponseEntity.status(422)
.body(new ErrorResponse("Unprocessable Entity", ex.getMessage()));
}// Return 422 Unprocessable Entity
func errorHandler(w http.ResponseWriter, message string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(422)
json.NewEncoder(w).Encode(map[string]any{
"status": 422,
"error": "Unprocessable Entity",
"message": message,
})
}