API-18Recommended
Name every field that failed
When input fails validation, return every failing field at once, with where it is and why it failed.
How to do it
Add an errors array to the problem details. Give each entry a JSON Pointer to the field and a plain reason. RFC 9457 shows this pattern. For query and path parameters, name the parameter in a parameter field instead. Answer 422 for a body that breaks the schema and 400 for a bad parameter, as the status codes table sets. See also put server errors on their fields.
Examples
JSON example
{
"type": "https://api.example.com/problems/invalid-input",
"title": "The request has invalid fields",
"status": 422,
"detail": "2 fields are invalid.",
"errors": [
{ "pointer": "#/items/0/quantity", "detail": "Must be 1 or more." },
{ "pointer": "#/email", "detail": "Must be an email address." }
]
}
How to check
Send a body with two invalid fields. The answer lists both, with pointers such as #/items/0/quantity.
Sources
Related rules
- ARC-53 Parse input once at the boundary in Clean code and architecture
- API-3 Answer with the right status code in API design
- APP-18 Put server errors on their fields in Web app interface
- API-90 Answer with the standard gRPC status codes in API design
- APP-17 Check every field on the server too in Web app interface
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/errors/validation-errors">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.