---
title: "Give every error a code that clients can · Agent Wranglers"
url: https://agentwranglers.se/playbook/localization/apis-and-data/error-codes-for-translation
id: LOC-34
level: Recommended
updated: 2026-10-22
tokens: 849
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Give every error a code that clients can translate

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [APIs and data](https://agentwranglers.se/playbook/localization/apis-and-data.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

- ID: LOC-34
- Level: Recommended
- Chapter: [APIs and data](https://agentwranglers.se/playbook/localization/apis-and-data.md)
- Rule: Every error carries a stable code and the values a client needs to build its own message. The code never changes with the language, and only the human text is translated.
- Check: A test triggers each error with `Accept-Language: en` and with `de`. The `type`, pointer and values are equal in both answers, and only `title` and `detail` differ.
- How: A mobile app shows errors in the user's language, which may not be the language the server chose. Give it the problem `type` from [Keep error types stable](https://agentwranglers.se/playbook/api-design/errors/stable-error-types.md), the field pointer and named values such as `max`. RFC 9457 lets `title` change only for localization, so translate `title` and `detail` but keep `type` fixed. The client looks the code up in its own message file, written as [Translate whole sentences](https://agentwranglers.se/playbook/localization/messages-and-translation/whole-sentence-messages.md) says.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JSON example

```json
{
  "type": "https://api.example.com/problems/too-long",
  "title": "Der Wert ist zu lang",
  "status": 422,
  "errors": [{ "pointer": "#/name", "code": "too-long", "max": 80 }]
}
```

### JavaScript example

```js
// Client: build the message from the code and the values
const text = intl.formatMessage(messages[error.code], { max: error.max });
```

### Python example

```python
# Client: build the message from the code and the values
text = translations.gettext(error["code"]).format(max=error["max"])
```

## Sources

- [RFC 9457 (Problem Details for HTTP APIs, section 3.1)](https://www.rfc-editor.org/rfc/rfc9457#section-3.1)

## Related rules

- API-17 [Keep error types stable](https://agentwranglers.se/playbook/api-design/errors/stable-error-types.md) in API design
- LOC-13 [Translate whole sentences](https://agentwranglers.se/playbook/localization/messages-and-translation/whole-sentence-messages.md) in Localization

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/localization/apis-and-data/error-codes-for-translation">Agent Wranglers localization playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Answer human-readable text in the language the client asked for](https://agentwranglers.se/playbook/localization/apis-and-data/response-language.md)
- Next: [Store translated content per record and language](https://agentwranglers.se/playbook/localization/apis-and-data/translated-content-storage.md)
- [APIs and data](https://agentwranglers.se/playbook/localization/apis-and-data.md)
