Implementing Guardrails
Input and output guardrails share a purpose but differ in position. That is why a complete design usually considers both, and why the placement rule about exposures decides how many guardrails are needed.
The Two-Step Design That Raises a Question
Imagine you have built an application in which a person types a question, the question is passed to a model, and the model's answer appears on the screen. The design looks finished. Yet it raises an uncomfortable question: what happens if the text coming in is harmful, misleading, or simply not something the application should handle? And what happens if the text going out is the problem?
Guardrails are the design answer to that question. Keep the simple two-point flow in mind, text comes in and text goes out, because the rest of this article builds on it. Each point in that flow is a place where something can go wrong, and each is a place where a guardrail can be placed.
What a Guardrail Is and Whose Risks It Covers
A guardrail is a mechanism that mitigates risk and protects both the builder and the users of an application.
The word mechanism matters. A guardrail is not a single rule written in a document. It is a component of the system that actively limits what can go wrong. Its job is defensive. It does not make the application more capable, faster, or more interesting. It exists so that when a risk is present, the consequences of that risk are contained before they reach a user or the operator running the system.
The phrase protect you and your users captures two audiences. The builder is exposed to risks such as an application behaving in ways that reflect poorly on the product or create legal or operational trouble. The users are exposed to risks such as receiving harmful content or having their own information handled carelessly. A well-placed guardrail considers both audiences, because a risk to one is usually a risk to the other.
| Audience | Typical exposure named in the source | What the guardrail protects |
|---|---|---|
| Builder | The application behaves in ways that reflect poorly on the product | The product's reputation |
| Builder | The application creates legal or operational trouble | The builder from legal and operational consequences |
| Users | Receiving harmful content | The user from content that should not reach them |
| Users | Having their own information handled carelessly | The user's information during processing |
Whose risks a guardrail addresses. A single guardrail often covers rows from both audiences.
Finding Exposures Before Placing Guardrails
The source gives a clear placement rule: guardrails should be put wherever there is an exposure to risk. This turns a vague worry into a concrete design task. Instead of asking whether the application feels safe, you walk through the system and ask at which points risk can enter, travel, or leave.
An exposure is a point in the system where something could go wrong and cause harm. Exposures are not all the same size. Some sit at the edges of the system, where data arrives from outside or leaves to the outside. Others sit inside the processing itself. The placement rule asks you to put a guardrail at each exposure you can identify, rather than relying on one check at the very beginning and hoping it covers everything.
Read the diagram as a list of places to check. The request enters at the edge, is passed inward toward the model, and the reply travels back through the application to the screen. Each arrow is a point where data moves, so each arrow is a candidate exposure. The design task is to decide which of those points need a guardrail, and the placement rule says to cover every one you can identify.
Tracing One Request Through the Flow
The best way to see how the two families of guardrails fit together is to follow one request from start to finish. Read the trace as a sequence of states. At each step, ask which exposure is currently active and which guardrail, if any, is responsible for it.
A user question about a shipping delay
A user types a question into a support chatbot built on a model. Trace which exposure is active at each state and which guardrail owns it.
- 1State 1: text arrives from the user
The request is on the way in. The exposure is at the edge where outside data enters the system. The input guardrail is responsible for this stretch.
- 2State 2: text is passed to the model
The request is now inside the processing. The input guardrail has already handled it, so it is no longer the active check on this data.
- 3State 3: the model produces a reply
The reply is now being produced. The exposure is in the content that is about to leave the system, so the output guardrail is the one responsible.
- 4State 4: the reply reaches the screen
The reply is on the way out to the user. The output guardrail covers this stretch, and the user is the party whose risk it contains.
The input guardrail owns the request on the way in, and the output guardrail owns the reply on the way out. They never handle the same data at the same moment.
Input Guardrails Versus Output Guardrails
The source states that, in general, guardrails can be grouped into two categories: guardrails around inputs and guardrails around outputs. This grouping follows the direction of data through the system. Data either comes into the application or goes out of it, and the two families are named for the side of the flow they protect.
| Feature | Input guardrail | Output guardrail |
|---|---|---|
| Position in the flow | On the way in, before the text reaches the model | On the way out, after the model has produced a reply |
| Data it handles | The request written by the user | The reply produced for the user |
| Shared purpose | Mitigates risk and protects builder and users | Mitigates risk and protects builder and users |
| Exposure it covers | Harmful, misleading, or out-of-scope text coming in | Problematic text going out |
Input and output guardrails share a purpose and differ in position.
Input and output guardrails share a purpose but differ in position. That is why a complete design usually considers both, and why the placement rule about exposures decides how many guardrails are needed.
Following a Blocked, Modified, or Allowed Request
A guardrail on the input side does not have to do only one thing with a request. The flowchart below shows one illustrative set of outcomes for an incoming prompt. The branches are a generated teaching example of how an input check might respond. The source establishes the placement and the two families; the specific outcomes shown here are one way to read the design.
Notice that a blocked request never reaches the model, so the output side has nothing to check for that prompt. An allowed or modified request does reach the model, and its reply then passes through the output check. Both families remain relevant to the same interaction, each covering its own stretch of the flow.
Mistakes When Placing Guardrails
Common mistake Relying on one check at the very beginning of the flow
Why it failsThe placement rule asks for a guardrail at each exposure, not one check that is assumed to cover everything. A check on incoming text does nothing about a reply the model produces afterward.
Do this insteadWalk through the system, identify each point where risk can enter, travel, or leave, and decide where a guardrail belongs.
Common mistake Thinking only the builder or only the users need protection
Why it failsThe source says a guardrail protects both the builder and the users, and that a risk to one is usually a risk to the other.
Do this insteadWhen placing a guardrail, consider both audiences and name the risks each one faces.
Common mistake Treating a guardrail as a single written rule
Why it failsThe source describes a guardrail as a component of the system that actively limits what can go wrong, not a line in a document.
Do this insteadThink of a guardrail as a working part of the flow that checks data at a specific point.
Common mistake Assuming an output guardrail makes an input guardrail unnecessary
Practice: Placing Guardrails in a New Application
A team is building an application in which a student types a homework question, a model answers it, and the answer is displayed in a classroom app. Before you read further, list every point in the flow where you think risk could enter, travel, or leave. Then decide, for each point, whether it belongs to the input side or the output side, and name one risk that a guardrail at that point would address for the student and one for the school operating the app.
Hints
- Start at the edge where the student's text arrives and follow the path to the screen.
- Points where data leaves the system are exposures too, not only points where it enters.
- A single guardrail can protect both the student and the operator, so look for risks that affect both.
Key Takeaways
- A guardrail is a mechanism that mitigates risk and protects both the builder and the users of an application.
- Guardrails should be placed wherever there is an exposure to risk, so the design task starts by locating exposures.
- Input guardrails sit on the way in and output guardrails sit on the way out; they share a purpose but differ in position.
- A complete design usually considers both families, because each covers a distinct stretch of the data flow.