Agent Wranglers

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

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.