Concepts / Input Guardrails in Practice

Input Guardrails in Practice

The placement rule, not a fixed count, decides how many guardrails a design needs. Every exposure you identify is a place where a guardrail may belong.

  • Programming

A Design That Looks Finished

Imagine you have built a simple application. A person types a question, the question is passed to a model, and the model's answer appears on the screen. Nothing in the design looks broken. Yet the design 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. This article follows one request through a simple application, explains what a guardrail is and whose risks it covers, and shows how the two broad families of guardrails divide the work between them. Keep the simple two-point flow in mind, text comes in and text goes out, because the rest of the article builds on it.

Following One Request Step by Step

The best way to see how guardrails fit into an application is to follow one request from start to finish. Read the trace below as a sequence of states. At each step, ask which exposure is currently active, meaning which point in the system could let something go wrong, and which guardrail, if any, is responsible for it.

  1. 1
    State 1: The person types a question into the application. Text is now arriving from outside the system, so the entry point is an exposure.
  2. 2
    State 2: The question is passed to the model. The text is now inside the processing, where a risk can travel further.
  3. 3
    State 3: The model produces an answer. The answer is now the content that will leave the system, so the exit point is an exposure.
  4. 4
    State 4: The answer appears on the screen. The person reading it is the one who receives whatever risk survived the earlier stages.

Notice that the trace has two edges that matter most. The first is where text enters the application. The second is where text leaves it. Those two edges are where the two families of guardrails are placed, as the next sections explain.

What a Guardrail Is For

Definition

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.

Because a guardrail is defined by what it prevents rather than what it adds, you can test any proposed guardrail with one question: which specific risk does this contain, and where in the flow does it contain it? If you cannot answer both parts, the proposal is still a wish, not a guardrail.

Whose Risks Guardrails Cover

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.

GuardrailBuilderProduct reflectspoorlyEnd usersLegal or operationaltroubleHarmful contentreceivedOwn informationhandled carelesslyprotectsprotectsexposed toexposed toexposed toexposed to
Which specific risks fall on the builder and which fall on the end user, and what a guardrail is for in each case.

Locating Exposures in the Flow

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.

Key point

The placement rule, not a fixed count, decides how many guardrails a design needs. Every exposure you identify is a place where a guardrail may belong.

Tracing the Request With Guardrails in Place

Now trace the same request again, this time with the two families placed on it. The input guardrail handles the question on its way in, before it reaches the model. The output guardrail handles the reply on its way out, before it reaches the screen. Each guardrail covers a distinct stretch of the flow, so they never handle the same data at the same moment.

User questionInput guardrailModelOutput guardrailScreentext comes inchecked questiondraft answertext goes out
Where an input guardrail sits relative to the user, the model, and the screen, and how that differs from an output guardrail.
FeatureInput guardrailOutput guardrail
Side of the flowData coming into the applicationData going out of the application
PositionBefore the model processes the textAfter the model produces its answer
ProtectsAgainst risk arriving with the requestAgainst risk leaving with the reply
Shared purposeMitigate risk and protect builder and usersMitigate risk and protect builder and users

The two families share a purpose and differ in position.

The table makes a point easy to miss when the two families are studied in isolation. They share a purpose and differ only in position. That is why a complete design usually considers both, and why the placement rule about exposures is what decides how many guardrails are needed.

Placing Guardrails in a Question Answering App

Worked example

Locating exposures in a question answering application

A small application lets a person type a question, sends it to a model, and shows the answer. Where do the exposures sit, and which family of guardrail covers each one?

  1. 1
    Identify the entry point

    The question arrives from outside the system. This is an exposure at the edge, where data comes in.

  2. 2
    Identify the processing

    The question is handed to the model. Risk that got past the entry point can still travel into this processing, so the flow must be considered as a whole.

  3. 3
    Identify the exit point

    The model's answer leaves the system and reaches the screen. This is an exposure at the edge, where data goes out.

  4. 4
    Assign the families

    The entry exposure is covered by an input guardrail. The exit exposure is covered by an output guardrail. Because the two families cover opposite ends of the flow, the design needs both.

Result

Two exposures sit at the edges of the application, so the design calls for an input guardrail on the question and an output guardrail on the answer. Covering only one edge leaves the other exposure unprotected.

Common Mistakes When Placing Guardrails

  • Common mistake

    Treating a guardrail as a single rule written in a document

    Why it fails

    The source describes a guardrail as a mechanism, a component of the system that actively limits what can go wrong.

    Do this instead

    Describe the guardrail by the component that performs the check and the exposure it covers.

  • Common mistake

    Relying on one check at the very beginning of the flow

    Why it fails

    The placement rule asks for a guardrail at each exposure, including exposures inside the processing and at the exit.

    Do this instead

    Walk the flow, list each point where risk can enter, travel, or leave, and decide which of them need a guardrail.

  • Common mistake

    Thinking only about the user, or only about the builder

    Why it fails

    Guardrails protect both audiences, and a risk to one is usually a risk to the other.

    Do this instead

    For each guardrail, name the builder risk and the user risk it addresses.

  • Common mistake

    Assuming an input guardrail also covers the reply

    Why it fails

    Input and output guardrails cover opposite ends of the data flow, so they never handle the same data at the same moment.

    Do this instead

    Check the entry and the exit separately, and place a guardrail on each exposure you find.

Predicting Where Harmful Text Is Caught

What do you think happens?

A person sends a harmful question to the application. Which family of guardrail is positioned to handle that text first, before the model processes it?

  • An output guardrail

  • An input guardrail

  • Neither family, because the model handles all text

Reveal answer
Answer:

An input guardrail

The source places input guardrails on data coming into the application, before it is passed to the model. Output guardrails handle the reply on its way out, so they are not the first point of contact for the question.

MEDIUM

Take a simple application where a user types a question, the question goes to a model, and the answer appears on the screen. List every exposure you can find, then for each one state whether an input guardrail or an output guardrail covers it, and name one builder risk and one user risk that the guardrail addresses.

Hints
  • Start with the two edges of the flow: where text enters and where text leaves.
  • Remember that exposures can also sit inside the processing itself, not only at the edges.

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 cover data coming into the application, and output guardrails cover data going out; both share a purpose but differ in position.
  • A risk to the builder is usually a risk to the user as well, so a well-placed guardrail considers both audiences.

More concepts starting with I