Security failures in AI applications
An output guardrail catches failures in model output and specifies a policy for each failure mode.
The Reply Nobody Checked
Imagine an application that takes a customer's question, sends it to a language model, and shows whatever comes back directly on the screen. Most of the time this works. But the reply is generated text, not a verified result, and generated text can go wrong. It might arrive empty, break the format the application depends on, state something untrue, or contain content that no product should show to a customer. An application that passes every reply straight through to the user is trusting the model completely. The source material makes the point plainly: that trust is rarely justified in a production system.
This article follows one idea through the whole path: the output guardrail. You will see where it sits, what it checks, what it does when a check fails, and what those choices cost. By the end you should be able to trace a single model response through the guardrail and predict what happens to it.
Where the Guardrail Sits
An output guardrail is the checkpoint placed between the model and the user. Its purpose is to examine what the model produced before the application acts on it.
A guardrail is not a model improvement, and it does not make the model smarter. It is application logic that inspects results and decides what should happen when a result is not acceptable. Because the guardrail only sees the output and the standard it must meet, it does not need to know how the model works internally. That is why guardrails can be added to an application without changing the model itself.
What do you think happens?
If a guardrail is added to an application, does the language model itself become smarter or more accurate?
Reveal answer
No, the guardrail is application logic that inspects outputs and decides what to do with them
The source states that a guardrail is not a model improvement. It examines what the model produced and decides the next step. The model is unchanged.
The Two Jobs of a Guardrail
An output guardrail has two responsibilities, and they depend on each other. The first is detection: the guardrail must catch outputs that fail to meet the standards the application sets. The second is response: once a failure has been caught, the guardrail must apply a policy that says what to do about that particular kind of failure.
Think of detection as the question 'is this reply acceptable?' and the policy as the answer to 'if not, what now?' The guardrail is only as useful as the connection between those two questions. A check that flags a problem but has no rule for it leaves the application with no defined behavior; a rule that exists for a problem the check never detects is dead code.
Tracing a Response Through the Guardrail
It helps to picture a response as moving through a sequence of decisions. The model's output enters the guardrail, which runs its checks. A response that passes goes on to the user. A response that fails is matched to a failure category, and the policy for that category determines the next step. The diagram below shows this route. Pay attention to the fork at the check: the same response can take two very different paths depending on what the check finds.
Trace a response step by step. First, the response enters the guardrail and the check runs. If the check passes, the response reaches the user and nothing else happens. If the check fails, the response is not shown. Instead it is matched to a failure category, and the category's policy decides the next move. In the flowchart, a retry policy sends the request back to the model, and a human fallback sends it to a person. The policy, not the check, decides which of these branches is taken.
Quality Failures and Security Failures
Failures look different across applications, so the first skill in designing a guardrail is recognizing what failure looks like for your specific product. The source sorts common failures into two families. Quality failures concern whether the output is good and correct. Security failures concern whether the output is safe and whether it exposes something it should not.
| Aspect | Quality failures | Security failures |
|---|---|---|
| Core question | Is the output good and correct? | Is the output safe, and does it expose something it should not? |
| Examples named in the source | Malformatted responses; factually inconsistent responses | Toxic content; private content |
| What the bad output looks like | Broken format the application depends on, or a statement that conflicts with known facts | Harmful or abusive language, or private information shown to a user who should not see it |
| Typical harm | The application fails to work correctly, or a user receives wrong information | The product exposes harmful or private material to people |
Quality failures and security failures, as the source groups them
The distinction matters because the two families can look similar from the outside. A reply that is malformatted and a reply that contains private content are both 'bad output', but they call for different detection and different responses. Sorting a failure into its family is the first step in choosing what the guardrail should do about it.
Policies for Each Failure Mode
A policy is the rule that connects a failure category to an action. The source names two actions that teams use: retrying the query, and handing the request to a human. The plan for this article also considers blocking the output and redacting part of it. Whatever set of actions your application uses, each failure mode needs one assigned, so that the guardrail never has to improvise.
Assigning a policy to each failure mode
A product team lists four failure modes for a customer-support assistant: an empty reply, a reply that breaks the required format, a reply with a factual inconsistency, and a reply containing private content. Assign each one a policy.
- 1Empty reply
The source notes that an empty reply can be retried a fixed number of times or until a nonempty reply arrives. A retry policy fits, with a defined stopping condition.
- 2Malformatted reply
The source notes that a malformatted reply can be retried until the format is correct. A retry policy fits here as well, again with a stopping condition so the loop cannot run forever.
- 3Factual inconsistency
This is a quality failure. The team could retry, but if retries cannot reliably produce a consistent answer, the policy may instead route the request to a person. The right choice depends on the team's standards for the product.
- 4Private content
This is a security failure. Showing the reply to the user is the harmful outcome, so the policy should prevent it from reaching the user. Blocking or redacting the content, and escalating when the request is tricky, are reasonable options the team could choose.
Each failure mode has an explicit policy. The empty and malformatted replies use retries with stopping conditions. The factual inconsistency and private content cases use stricter responses, because retrying alone may not produce an acceptable result.
Retries: Cheap Fixes With a Price
Many failures can be reduced with simple retry logic. The reason it works is that AI models are probabilistic. Sending the same query again may produce a different response. A retry policy is therefore a rule that converts a failure into another attempt, with a defined stopping condition.
A retry policy is not free. Every retry is another round of API calls, which adds latency and cost. If the retry happens only after a failure has been observed, the user waits for the first attempt and then for the second, so the latency the user perceives can roughly double. The diagram below shows how the loop runs and where it stops.
Latency and cost of one retry
Suppose one model call takes 2 seconds and costs one unit. A reply fails the check on the first attempt and passes on the second. Compare the total latency and cost with a request that passes the first time. Use the simplified numbers for illustration only.
- 1Without a retry
One call is made. The user waits about 2 seconds and the request costs one unit.
- 2With one retry
The first call fails and a second call is made after the failure is observed. The user waits for both, about 4 seconds, and the request costs two units.
- 3Interpreting the result
The retry doubled both latency and cost in this simplified case, matching the source's point that perceived latency can roughly double. Each further attempt adds another wait and another charge until the stopping condition is reached.
A single retry roughly doubles the wait and the charge for that request. A policy with no stopping condition, or a large fixed number of attempts, can multiply both further.
The source also notes that parallel calls add redundant API calls. Rather than waiting for a failure, an application can send several requests at once and use whichever passes. This can reduce waiting time, but it spends extra calls even when the first reply would have been acceptable. The trade-off is between latency and cost, and the right balance depends on the product.
Handing Off to a Human
Retries assume that another model response will be good enough. For some requests that assumption is weak, and the policy should send the conversation to a person instead. This is the human fallback branch in the flowchart. The source describes three approaches teams use to decide when this happens.
- Transfer any query that contains specific phrases to human operators.
- Use a specialized model to decide when to transfer the conversation.
- Transfer after a set number of turns, to stop users from getting stuck in a loop. In one example from the source, a team transfers when its sentiment analysis model detects anger in the user's messages.
Why False Refusals Must Be Measured
A guardrail can make two kinds of mistakes. A security failure that gets through is one. The other is a false refusal: the guardrail blocks, retries, or escalates a reply that was actually acceptable. Both are errors, and they pull in opposite directions. A stricter check catches more security failures, but it also flags more acceptable replies, so the rate of false refusals rises.
This is why both numbers must be tracked together. If a team measures only security failures, it will be tempted to tighten the check until almost nothing gets through, and users will see more blocked, retried, or transferred answers. If it measures only false refusals, it will loosen the check and let harmful output reach people. Tracking both lets the team see the trade-off and choose a setting deliberately.
Mistakes Teams Make With Guardrails
Common mistake Treating the guardrail as a way to make the model smarter
What it looks likeA team adds a content check and expects the model to stop producing private content in future replies.
Why it failsA guardrail is application logic that inspects outputs. It does not change the model.
Do this insteadDescribe the guardrail as a checkpoint that examines each output and decides the next step.
Common mistake Detecting a failure but assigning it no policy
What it looks likeThe check flags a reply as factually inconsistent, but no rule says whether to retry, escalate, or block it.
Why it failsDetection without a policy leaves the application with a bad reply and no defined behavior.
Do this insteadGive every failure category an explicit action.
Common mistake Retrying with no stopping condition
Why it failsEach retry adds latency and cost, and an open-ended loop can keep spending both.
Do this insteadDefine a fixed number of attempts, or a clear condition such as a nonempty or correctly formatted reply, and hand off when it is reached.
Common mistake Measuring only security failures
What it looks likeA team tightens the check until almost nothing passes and does not notice users are being blocked.
Why it failsStricter checks raise false refusals, which are errors too.
Do this insteadTrack false refusals alongside security failures so the trade-off is visible.
Practice: Trace a Reply
A support assistant's reply is checked and found to contain a customer's private account details. The policy for private content is to escalate to a human. Trace what happens to the reply. Then explain whether a retry would be a sensible first move, and why or why not. Finally, name one way the team could check whether its guardrail is too strict.
Hints
- Start at the guardrail check and follow the fail branch in the flowchart.
- Consider whether a retry of a private-content reply is the same kind of fix that works for an empty reply.
- Think about the false refusal trade-off: what would it show if acceptable replies were being flagged too often?
Key Takeaways
- An output guardrail is a checkpoint between the model and the user. It is application logic that examines model output and decides what happens next, and it does not change the model.
- A guardrail has two linked jobs: detection, which catches outputs that fail the standards, and response, which applies a policy for each failure category.
- Quality failures concern whether output is good and correct, such as malformatted or factually inconsistent replies. Security failures concern whether output is safe and whether it exposes something it should not, such as toxic or private content.
- Retry policies can fix many failures because models are probabilistic, but each retry adds latency and cost, and parallel calls add redundant API calls. Human fallback handles tricky requests, and its trigger is only as good as the detection behind it.
- A stricter guardrail catches more security failures but produces more false refusals, so both must be tracked together.