Model Gateways and Routing
Guardrails sit on both sides of the model call, with input guardrails checking requests and output guardrails checking responses.
A Customer-Support Assistant Under Pressure
Imagine a customer-support assistant built on a generative model. A user types a question, the application sends it to a model, and a reply comes back. That sounds simple, but each step in the path is a place where something can go wrong. The user might try to manipulate the model. The model might produce an unsafe or off-topic reply. The reply might leak information it should not contain. Guardrails are the checks that catch these problems.
This article follows one request through such an application. The goal is to see where guardrails sit, what they cost, and how a team chooses among the options. A useful way to hold the whole topic in mind is that guardrails are not free. Adding them changes how fast the application responds, how much the team depends on outside providers, and how much engineering work the team takes on. A good implementation is a set of deliberate choices, not a checklist of every check that could be added.
What do you think happens?
When the customer types a question, does the text go straight to the model, or does something check it first?
Reveal answer
It passes through input guardrails first, which examine what the user sent. Only after that does the request reach the model API.
The user's input does not go straight to the model. Input guardrails sit between the user and the model call, so a request can be checked, and potentially blocked or changed, before the model ever sees it.
Tracing One Request Through the Pipeline
Start with the request path. The user's input does not go directly to the model. It first passes through input guardrails, which examine what the user sent. Only then does the request reach the model API. The model's raw output does not go directly back to the user either. It passes through output guardrails before the response is shown. The path therefore has a gate on each side of the model call.
Read the diagram as a pipeline with two gates. The input gate protects the model from what comes in. The output gate protects the user from what goes out. The scorers are the tools that help make those judgments. The source places scorers under the model APIs because they are often AI-powered themselves, even though they are usually smaller and faster than the generative models. Scorers can also sit inside the output guardrails stage instead, so the scoring work can attach to either side of the model call depending on the design.
Tracing a Single Support Question
A customer asks the support assistant a question. Trace what happens to the request and the reply, identifying each place a guardrail could stop or change the content.
- 1Step 1: The question enters the application
The user's input is not sent to the model yet. It is held at the input guardrails, which examine what the user sent.
- 2Step 2: Input guardrails decide
If the input is a manipulation attempt or otherwise fails the check, the request can be blocked or changed here, and the model is never called for it. If it passes, it moves on.
- 3Step 3: The model call happens
The request reaches the model API, which generates a raw reply. Scorers may be involved near this call, helping judge content.
- 4Step 4: Output guardrails check the reply
The raw reply does not go straight to the customer. It is checked for unsafe, off-topic, or leaking content before it is shown.
- 5Step 5: The user sees the result
Only content that clears the output gate is displayed. This is the protection the output side exists to provide.
The request is guarded twice: once before the model call to protect the model from incoming problems, and once after it to protect the user from outgoing problems.
Who Builds Guardrails at Each Level
Because many different parts of a system can fail, guardrails can be placed at several levels. Two groups do most of this work: the companies that build and host models, and the teams that build applications on top of those models. Model providers and application developers can both implement guardrails, and each level has its own responsibilities. The two groups have different tools, so a careful design usually uses both.
The gateway layer deserves its own check. Some model gateways also provide guardrail functionality, so a team that already runs a gateway should look at what that gateway covers before duplicating the same checks in its own code. The team's own checks then fill the gaps the gateway and provider do not cover.
Hosting Choice and How Many Guardrails You Build
The number of guardrails a team needs depends on whether it hosts its own models or uses third-party APIs. Guardrails can be built on top of either option. However, third-party API providers typically offer many guardrails out of the box, which reduces how much a team must build itself.
Self-hosting pulls in the opposite direction on one front. When models run inside your own system, requests do not have to be sent to an external service. That reduces the need for many input guardrails that exist to handle data crossing that outside boundary. The engineering burden shifts rather than disappearing. A self-hosted team gives up provider-supplied protections and gains control over where its checks run.
Latency, Reliability, and Streaming Output
The central trade-off in guardrail implementation is reliability versus latency. Stronger checking usually takes more time, and users notice delay. The source reports that some teams felt latency mattered more than the guardrails and chose not to implement them, because those checks can significantly increase an application's latency. That is a real engineering decision, and the right answer depends on the product and its risks.
The trade-off becomes sharper with output guardrails and the way responses are delivered. By default, the whole response is generated before anyone sees it, and that can take a long time. In stream completion mode, tokens are sent to the user as they are generated, so the user waits less. The cost of streaming is that partial responses are hard to evaluate. An unsafe response might reach the user before the guardrails decide to block it.
Comparing Full-Response and Streaming Checks
The two delivery modes ask different things of the output guardrail. A check on a complete response sees everything the model produced before any decision is made. A check during streaming sees only the part that has been generated so far. The table below summarizes the trade-off described in the source.
| Aspect | Full response checked before return | Streaming tokens checked as generated |
|---|---|---|
| What is evaluated | The complete response | Only the partial text generated so far |
| Wait time for the user | Longer, because the whole response is generated first | Shorter, because tokens are sent as they are produced |
| Reliability of the check | Stronger, since the full content is available | Harder, since partial responses are difficult to evaluate |
| Main risk | Latency that users notice | Unsafe content may be visible before a block decision |
Full-response checking favors reliability, while streaming favors speed and makes output evaluation harder.
Guardrail Solutions and What They Protect
Instead of building every check from scratch, a team can adopt an existing guardrail solution. The source notes that several can be used out of the box, and knowing these exist is the first step. Choosing among them depends on what each one covers. The source pack for this article does not name specific products, so treat any product list as something to verify against current provider documentation.
Map each risk to the side of the model call it threatens. Input risks include a user trying to manipulate the model, which is checked on the way in. Output risks include an unsafe or off-topic reply and a reply that leaks information it should not contain, which are checked on the way out. Because risks overlap between inputs and outputs, a single solution will often protect both sides, so a team should not assume it needs one tool for input and another for output.
Mistakes Teams Make With Guardrails
Common mistake Treating guardrails as free
What it looks likeAdding every available check to every request without measuring the added wait time.
Why it failsThe source states that guardrails change response speed, dependence on outside providers, and engineering effort.
Do this insteadChoose checks deliberately and measure what each one adds to latency.
Common mistake Assuming streaming output is fully checked
What it looks likeStreaming tokens to the user while assuming the output guardrail has already reviewed the whole reply.
Why it failsPartial responses are hard to evaluate, so unsafe content might reach the user before the guardrails block it.
Do this insteadDecide in advance whether streaming is acceptable for the product's risk level, or accept full-response checking for sensitive use.
Common mistake Duplicating a gateway's checks in application code
What it looks likeWriting your own check for a risk that the team's model gateway already covers.
Why it failsSome model gateways provide guardrail functionality, so the same check may already exist.
Do this insteadReview what the gateway covers before adding a separate check.
Common mistake Building one-sided protection
What it looks likeProtecting only the input and forgetting that the model's reply can leak information.
Why it failsA request is guarded on both sides of the model call, and each side protects against different failures.
Do this insteadPlace checks on both the input gate and the output gate.
Practice: Placing Guardrails for a Streaming Product
A product team wants fast replies and is considering streaming tokens to users. Identify one way streaming changes the output guardrail, and name one decision the team must make before choosing streaming.
Hints
- Recall what the guardrail can evaluate when the response is only partly generated.
- Think about whether the product's risks can tolerate a brief window where unsafe text is visible.
- The source frames this as a reliability versus latency decision.
Summary of Request Guarding
- 1Guardrails sit on both sides of the model call: input guardrails check the user's request before the model, and output guardrails check the model's reply before it is shown.
- 2Model providers and application developers can both implement guardrails, and some model gateways also provide them, so teams should check existing layers before duplicating checks.
- 3Reliability and latency trade off against each other. Streaming reduces wait time but makes partial output hard to evaluate.
- 4Self-hosting shifts the guardrail burden rather than removing it, and third-party APIs often provide many guardrails out of the box.
At a glance
- Guardrails sit on both sides of the model call, with input guardrails checking requests and output guardrails checking responses.
- Model providers, gateways, and application developers can each provide guardrails, and a careful design usually uses more than one level.
- Reliability and latency trade off against each other, and streaming responses makes output evaluation harder because partial text is difficult to judge.
- The hosting choice between self-hosted models and third-party APIs changes how many guardrails a team must build itself.