BNK
Guardrails: in the path or beside it
A policy iRule in TMM, or a gateway every byte crosses
A guardrail reads a prompt and says whether it may go on. Where it stands decides what it can see and what it costs. This lesson shows both places. First the guardrail stands beside the path: a policy iRule in TMM holds the request, sends a copy of the prompt to the guardrail's API and waits for a verdict. Then it stands in the path: the request goes through an AI gateway, and so does every token of the answer. You will see a prompt with a trick in it get refused, a clean one pass both ways, and what happens when the guardrail doesn't answer.
- Beside the path
- TMM asks the guardrail's API from an iRule
- In the path
- an AI gateway that all bytes cross, both ways
- Refused requests
- cost no GPU time either way
- THE iRULE ALSO
- checks the key and meters the tokens
Read the whole lesson as text
1. A prompt with a trick in it
Someone sends the support bot a message that tries to make it give away its instructions. To the network this is an ordinary request: a valid TLS session, a well-formed POST, a real API key. The firewall lets it in, because the firewall looks at addresses and ports. Only something that reads the words can tell that this prompt is an attack.
- A request arrives with a valid key and a prompt that tries to override the bot's instructions.
2. One iRule holds the request
In this design there is no separate gateway in front of the GPUs. The policy runs in TMM itself, as an iRule attached to the Gateway's listener. An iRule is a small program that TMM runs at fixed moments of every connection. When the request headers arrive, the iRule tells TMM to keep the request and collect its body instead of forwarding it. When the body is in, it reads the JSON. Its first job is the key. It opens a side connection to the key service, asks about the key and gets back the team that owns it. The user's request has not moved. It is parked in TMM while the iRule asks around.
- The headers are in. The iRule tells TMM to hold the request and collect the whole body.
- The body is complete. The iRule reads the model, the key and the messages out of the JSON.
- The iRule opens a side connection to the key service and asks about the key.
- The key is valid and belongs to the team support-bot.
3. Beside the path: ask the guardrail
The second side call goes to F5 AI Guardrails. The iRule sends the text of the prompt to the guardrail's scan API over TLS and waits. The guardrail is not in the path here. The request itself never passes through it. It only sees the copy that TMM chose to send, and it answers with a verdict. This time the verdict is block: the last message is an attempt to override the system prompt. The iRule doesn't forward anything. It writes the refusal itself. No picker was asked, no GPU was touched.
- The iRule sends a copy of the prompt to AI Guardrails and waits for a verdict.
- Guardrails runs its checks on the text and one of them fires.
- The verdict comes back: block.
- The iRule answers the user itself with a refusal. The request never reaches the picker or a GPU.
4. A clean prompt, the same road
Now an honest question arrives on the same listener. The iRule does the same things in the same order: collect the body, check the key, send a copy of the prompt to the guardrail. This verdict is allow. Only now does the iRule let the request go. TMM asks the endpoint picker which worker should take it and forwards it to gpu-2. Count the cost of the check: one extra round trip, about ten milliseconds, before the first hop toward a GPU. The answer will stream back through TMM alone.
- An honest question arrives. The iRule collects it and checks the key, as before.
- It sends a copy of this prompt to the guardrail too.
- Nothing is wrong with it. The verdict is allow.
- The iRule releases the request. TMM asks the endpoint picker which worker should serve it.
- The picker chooses gpu-2, which holds the system prompt in its KV cache.
- TMM forwards the request straight to the Pod on gpu-2.
5. In the path: the AI gateway
Here is the other design, with the same clean prompt. TMM does not hold the request. Its route sends the whole request to F5 AI Gateway, a proxy that stands in the path. The gateway has the guardrail as one stage of its own pipeline, next to keys, budgets and model choice. The prompt check looks the same. The difference shows on the way back. The answer streams through the gateway too, so the guardrail can read what the model says, and here it finds an email address in the answer and masks it before the user sees it. The price is that every token now takes one more hop each way.
- In this design TMM sends the whole request to the AI gateway. Nothing is held at the border.
- The gateway checks the key and the budget, then hands the prompt to its guardrail stage.
- The prompt is allowed.
- The gateway sends the request back to BNK. The picker chooses gpu-2 and TMM forwards it there.
- The answer comes back token by token, and every chunk passes through the gateway.
- The gateway holds a few tokens at a time and has the guardrail read the answer too.
- It finds an email address in the answer and tells the gateway to mask it.
- The user receives the answer with the address removed.
6. When the guardrail doesn't answer
Back to the iRule design. A guardrail is one more thing that can be down. Suppose the side call gets no answer. The iRule has to decide, and whoever wrote the policy decided for it in advance. Fail closed means: no verdict, no GPU. The user gets an error and nothing unchecked goes through. Fail open means the request continues without a verdict. This factory fails closed. The same question exists in the gateway design. There it is a setting of the gateway. Here it is a few lines of the iRule.
- A third request needs a verdict, but this time the guardrail doesn't answer.
- The policy says fail closed, so the iRule refuses the request. Nothing unchecked reaches a GPU.
7. Count what the model said
One job is left for the iRule, on the way back. When gpu-2 finishes the clean request from step 4, the last chunk of its stream carries the token counts. The iRule reads them from the response and reports them to the usage service with one more side call. That is where budgets come from. When a team runs out, the same policy can answer 429, or quietly send that team's next requests to a smaller model. So in this design one iRule on one address holds the key check, the guardrail, the model choice and the meter, and the picker still chooses the GPU.
- The last chunk of the answer from gpu-2 carries the token counts.
- The iRule reads the counts out of the response as it passes.
- It reports them to the usage service, which takes them off the team's budget.
- The user gets the end of the stream. The metering took no time away from them.
Summary
Both designs stop a bad prompt before it costs a GPU anything. Beside the path, the request waits in TMM while a policy iRule asks the key service and the guardrail on the side. That adds one round trip before the first token and nothing after it, and it needs no extra proxy. In the path, the request and the whole answer cross an AI gateway. That costs a hop for every token, and in return the answer can be read and changed as it streams, and the same gateway can front models that are not in this factory at all. Either way, decide in advance what happens when the guardrail is silent.
Next lesson: What a guardrail reads