An Error Body a Client Can Act On
A plain body like {"error": "Invalid input"} tells a person what happened. But it gives the client's program nothing to branch on.
application/problem+json is the error body format standardized in RFC 9457. It has a type, a URI that identifies the kind of error; a title, a short name for that kind; a status, the same value as the response's status code; and a detail, a specific explanation of this error. The server can also add an errors list that says which fields failed and why.
Instead of parsing a message string, the client can look at type and errors and branch in code.
Write a problem+json error body with the fields a client can act on programmatically, not just a human-readable message.
A validation failure needs to tell the client exactly which field was wrong, so the client can highlight it in a form. Which body shape supports that?