Machine-Readable Error Responses
Standard Error Format
Define one predictable error structure across the API.
A useful structure can contain a machine-readable type, human-readable title, HTTP status, safe detail, and an instance identifying the request or error occurrence.
For validation failures, include structured field-level information so clients can highlight invalid inputs without parsing human-readable strings.
The error contract itself is part of your public API and should be documented.
Problem Details Style Error
{
"type": "https://api.example.com/problems/validation-error",
"title": "Validation failed",
"status": 422,
"detail": "One or more fields are invalid.",
"errors": [
{
"field": "email",
"code": "invalid_format",
"message": "Enter a valid email address."
}
],
"requestId": "req_01HXYZ"
}The response separates machine-readable information from human-readable messages and provides request correlation.