Ethics & Responsible Use
Why You Shouldn't Use LLMs to Write API Error Messages (And the Honest Way to Explain Failure)
It is tempting to let Claude or GPT-4o draft your system's error messages, but outsourcing human frustration to an LLM results in polite, useless, and sometimes dangerous API responses.
Updated 11/19/2026
The Temptation of the Generative Safety Net
We have all been there. It is 11:00 PM on a Thursday, the deployment pipeline is green, but you have a dozen edge cases that need proper validation errors. Writing error messages is tedious. It requires you to step out of your flow state, put on your empathy hat, and carefully articulate exactly why a request failed.
So, you open up a scratchpad, fire up Claude or OpenAI, paste in your raw validation schema, and ask the model to "generate friendly, professional error messages for these failure states."
It feels like a massive win. Within three seconds, you have a beautiful list of polite, grammatically perfect strings. You copy-paste them into your codebase, push to main, and call it a day.
But you have just committed a quiet, systemic crime against your API’s developer experience.
While LLMs are brilliant at writing boilerplate or helping you prototype complex structures, outsourcing your error boundaries to generative AI is a shortcut that actively degrades your software. When things break—and they always do—your users do not need a polite, robotic apology. They need deterministic, structural truth.
Set up your AI once so you repeat yourself less.
Tickd is independent and not affiliated with any AI company.
The "Polite but Useless" Trap
If you ask a model like GPT-4o to write an error message for a missing database record, it will almost certainly output something like this:
"We're sorry, but we couldn't find the requested resource. Please double-check your ID and try again. If the issue persists, feel free to contact our support team."
This looks fine on the surface. It is polite, helpful, and formatted beautifully. It is also an absolute nightmare to debug.
Large language models are trained to be agreeable pleasers. They want to smooth over friction. But in software engineering, friction is information. An API error message should not read like a customer service email. When a developer's script fails, they want to know exactly what made your system tick—or, more accurately, what caused it to stop ticking.
Generic, polite fluff masks the underlying system state. It wastes screen real estate in terminal outputs and forces developers to write parser wrappers just to figure out if the error was a 404, a 422, or a temporary rate limit.
The Engineering Cost of Vagueness
Good error design is deterministic. If a request fails because a field was too long, the error must programmatically tell the developer: 1. Which field failed. 2. The exact validation rule that was breached. 3. The raw value received versus the expected threshold.
When you use an LLM to draft these messages, you inevitably lose this structural metadata in favour of prose. LLMs write for humans reading a UI; they do not write for client-side codebases that need to catch specific exceptions and handle them gracefully.
If you try to bypass this by prompting the LLM to write structured JSON errors, you run into an even larger issue: consistency. Unless you are feeding the model an incredibly rigid schema every single time, it will invent new keys, phrase similar issues differently across various endpoints, and slowly erode the predictability of your API.
The Runtime Gamble: Dynamic Generation is a Security Hazard
If pre-generating error messages with LLMs is bad, generating them dynamically at runtime is an absolute disaster. Yet, we are starting to see teams pass raw exception stacks to an LLM API inside their global error handler to "translate" complex system failures into user-friendly explanations.
This introduces three massive liabilities:
1. Latency Bloat Why add 800 milliseconds of LLM API latency to an already failing request? If your database is struggling under heavy load, the absolute worst thing you can do is fire off an external HTTP request to an AI provider just to explain why your query timed out.
2. Information Leakage If an unhandled exception occurs deep within your PostgreSQL driver, passing that raw traceback to an LLM to make it "user-friendly" is incredibly risky. LLMs are notorious for over-sharing. It takes very little for a model to decide that explaining a database constraint error requires printing your internal table names, column structures, or worse, a snippet of raw SQL containing sensitive environment variables.
3. Prompt Injection inside Errors If your API accepts user input, and that user input causes an error, that input is now part of the context sent to the LLM generating the error message. If a malicious actor passes a prompt injection string into your payload, they can manipulate the returned error message to output whatever they want—including phishing links or fake system notices.
The Honest Way to Write Error Messages
Writing excellent error messages does not require a creative writer, nor does it require a neural network. It requires a simple, disciplined structural formula. Every error your API returns should follow the Rule of Three:
- The Code: A unique, machine-readable string identifier (e.g.,
INVALID_RESOURCE_ID,RATE_LIMIT_EXCEEDED). This allows client code to handle the failure programmatically without parsing strings. - The Context: The raw, unfiltered facts of the failure. Tell them what was expected, what was received, and which resource was affected.
- The Cure: A direct, actionable instruction on how to resolve the issue. No apologies, no "please try again later" fluff. Just the facts.
Instead of a generic paragraph, a robust error response looks like this:
`json
{
"error": {
"code": "field_too_long",
"message": "The 'username' field exceeds the maximum limit of 30 characters.",
"details": {
"field": "username",
"provided_length": 42,
"maximum_length": 30
},
"documentation_url": "https://api.example.com/docs/errors/field_too_long"
}
}
`
This message is honest. It does not pretend to be your friend, it does not apologise for things it cannot control, and it gives the integrating developer every single piece of data they need to fix their payload in under five seconds.
Where LLMs Actually Belong in Your Error Stack
This is not to say LLMs have no place near your API design. They are fantastic tools for analysis, not generation.
If you want to use AI to improve your API’s developer experience, write your error messages by hand, but use models to audit your error catalog. Feed your system's error schema to Claude and ask it to find inconsistencies in your naming conventions or point out where your documentation links are missing.
Let the machine handle the high-level structural analysis, but when it comes to telling a human developer why their code just broke, keep the AI out of the loop. Speak to them directly, programmatically, and honestly.
Keep going
Build something with the prompt generator, decode the jargon in the glossary, or compare the tools on our platform deep-dives.