← Back to Guides

Companion to the book Harness Engineering for Production AI Systems · this part maps to Book Ch 3

GuideFor: AI Engineers, ML Engineers, Platform Engineers, AI Systems Architects

LLM Guardrails That Stop Nothing: The Role Test

A guardrail counts only if the action can fail because of it. Classify every component by that power, then make CI fail when a verdict has nothing that can refuse on the other end.

#harness-engineering#llm-guardrails#agent-guardrails#control-systems#ci-checks#production-ai-systems

In July 2025 a developer filed issue #991 against the OpenAI Agents SDK. An input guardrail had flagged a request, raised its tripwire exception exactly as designed, and the agent's tools ran anyway. "The guardrail logic works correctly (proper exception is raised), but the execution flow doesn't respect the guardrail's decision to stop processing" (openai-agents-python #991). A pull request then added a flag that makes the guardrail finish first (PR #1986), and the default stayed parallel. OpenAI's current docs still warn that when a tripwire fires, "the agent may have already consumed tokens and executed tools before being cancelled" (OpenAI Agents SDK, Guardrails). Everything about that verdict was right except its arrival, which came after the tool call. For that tool call, a check that can only fire afterwards has the power of a log line.

Now a constructed case, from the billing support agent that this series and its book are built around. At 02:14, in the unattended overnight mode that drains the ticket queue, the agent refunds $940 on an account whose only open invoice is $120. Its design doc lists eight guardrails around that call: a moderation filter, a schema validator, a refund policy check, a nightly eval, tracing, a refund rule in the system prompt, a violations dashboard and a retry wrapper. All eight worked. Even the right verdict got computed: the policy check returned "940.00 is on no invoice" and wrote it where the dashboard could show it at 09:00.

My claim is that a guardrail counts only if it can make the action fail by itself, every time it decides to, whatever the model proposes. That is a narrower test than "it checks the right thing" or "it blocks something", and the 02:14 stack fails it eight times out of eight. A filter that blocks text at the model's edge can still be powerless over the refund. So classify every component by that power, with a three-question procedure I call the Role Test, and then check one structural property in continuous integration (CI): that every verdict is read by something able to refuse. That property is loop closure, borrowed from control engineering. It is necessary, and it is not enough on its own: it has to be paired with a single path from proposal to tool, because a wiring diagram cannot see timing, and #991 was a timing failure.

Why an LLM guardrail that blocks can still stop nothing

Ask one mechanical question of each of the eight: can issue_refund(940.00) fail to happen because of this component?

The moderation filter scored the ticket, wrote a number into state and returned. The schema validator logged its result, and nothing on the call path read it. Wired in, it would still have passed {"amount": "940.00"}, because a refund nobody is owed has the same shape as one somebody is. At 03:00 the nightly eval runs against yesterday's traffic. Tracing recorded every span. A prompt rule can change how likely the model is to propose the wrong amount, and this one had no way to make the call fail. The dashboard showed a verdict hours later. Then a retry wrapper repeated a read. And the refund policy check knew the answer, while nothing between the model and the payment API asked it.

Zero of eight, in a design doc that said eight of eight, and both counts used the word "guardrail".

d2
direction: down
classes: {
  cmp: {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
  sen: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
}
model: "Model proposes\nissue_refund(940.00)" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
checks: "Eight 'guardrails' in the design doc" {
  label.near: top-center
  grid-rows: 2
  grid-columns: 4
  grid-gap: 10
  style: {fill: "#F4F6F7"; stroke: "#95A5A6"}
  m: "moderation\nfilter" {class: cmp}
  s: "schema\nvalidator" {class: cmp}
  p: "refund policy\ncheck" {class: cmp}
  e: "nightly\neval" {class: cmp}
  t: "tracing" {class: sen}
  r: "prompt\nrefund rule" {class: sen}
  d: "violations\ndashboard" {style: {fill: "#C8D0D1"; stroke: "#6C7A7B"; font-color: "#2C2C2A"}}
  w: "retry\nwrapper" {style: {fill: "#C8D0D1"; stroke: "#6C7A7B"; font-color: "#2C2C2A"}}
}
pay: "Payment API:\n\$940 leaves the company" {style: {fill: "#E74C3C"; stroke: "#A93226"; font-color: "#FFFFFF"}}
model -> pay: "no component on this edge"
model -> checks: "observe or shape the run" {style.stroke-dash: 4}

That gap is invisible in a design doc that lists components instead of drawing edges: all eight sit off the one edge that moves money, and the call passes through none of them.

Blocking does not rescue this, which is the part most guardrail reviews miss. In Guardrails AI the validator default was noop at v0.5.0 and has been to raise ValidationError from v0.6.0 onward (source at v0.5.0, v0.6.0 and v0.11.0), the option the library's own enum documents as "On failure, do nothing" (on_fail.py). In NeMo Guardrails, the check() methods return a RailsResult whose status is PASSED, MODIFIED or BLOCKED (NVIDIA, Runtime Security FAQ). Those block, at the boundary they are usually deployed on: a prompt, a response, a stream. Put the same validator on the tool-call path and it becomes a gate. The Role Test asks about placement, not about the library. In the OpenAI Agents SDK, output guardrails "always run after the agent completes", and the docs say outright that terminal tool output needs extra handling "because the tool has already run before the agent-level output guardrail checks the value" (OpenAI Agents SDK, Guardrails). An output guardrail that blocks the reply is, with respect to the refund, a component that reports. The SDK does ship a gate for the action itself: input tool guardrails "run before the tool executes and can skip the call", which passes the test this article is about. Its docs also list where that gate is missing: hosted tools and built-in execution tools such as ShellTool "do not use this guardrail pipeline" (OpenAI Agents SDK, Guardrails).

Some products make report-only a named mode. Amazon Bedrock Guardrails has detect mode: "Take no action but return what the guardrail detects in the trace response" (AWS, Bedrock Guardrails). Anthropic's own recipe for screening tool outputs asks for "a parseable value your application can branch on" (Anthropic, Mitigate jailbreaks). That is the honest wording: the screen produces a value. Whether anything branches on it is your code's job, and the screen cannot know if you wrote that code.

The Role Test: classify any guardrail component by what it can stop

Three questions make up the Role Test, asked of one component at a time and in order.

  1. Can it, by itself, make the action fail every time it decides to? Logging an error does not count. Returning a failure object does not count. Making the wrong action less likely does not count either, and neither does winning a race some of the time. Whatever the model proposes and however the work is scheduled, the action has to be unable to occur once this component says no. Yes goes to question 3, no goes to question 2.
  2. Does it emit a verdict against a standard? Yes makes it a comparator. If it emits nothing but observes the run or shapes what the model sees, it is a sensor. If it does neither, it is not harness at all. Displaying a record another component already wrote counts as neither. Everything that lands here is the Harness Residual: application code, reviewed as application code. Residual here means what is left over after classification, not the fault-detection residual of control engineering, which is a measured signal.
  3. Does its decision depend on this proposal, directly or through a verdict about it? Yes makes it a gate. If it reads only state that is independent of the proposal, a counter or a clock, it is a bound.
d2
grid-rows: 3
grid-columns: 2
grid-gap: 24
q1: "1. Can it, by itself, make\nthe action fail every time?" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
a1: "Yes: go to 3\nNo: go to 2" {style: {fill: "#F4F6F7"; stroke: "#95A5A6"; font-color: "#2C2C2A"}}
q2: "2. Does it emit a verdict\nagainst a standard?" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
a2: "Yes: comparator\nNo, but observes or shapes\ncontext: sensor\nNeither: residual" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
q3: "3. Does its decision depend\non this proposal, directly or\nthrough a verdict about it?" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
a3: "Yes: gate\nOnly a counter or clock: bound" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}

Only a gate or a bound can stop anything, and question 3 splits them on whether the component read what the model asked for.

Question 1 is not new, and it should not be sold as new. Security audit has separated preventive controls, "intended to prevent an incident from occurring", from detective controls, "intended to identify, characterize, and log an incident", for decades (Wikipedia, Security controls). OWASP's entry on excessive agency in LLM applications draws the line in a slightly different place: it files logging and rate limiting together as options that "will not prevent Excessive Agency, but can limit the level of damage caused" (OWASP LLM06:2025). For the first wrong action that is true, and it is exactly why the Role Test splits preventers in two. A rate limit is a bound: it prevents the action that would cross its cap, not the first wrong action below it. Corrective controls, the third member of that old taxonomy, do not change the count either. A comparator that triggers a void of the refund inside the processor's window is a second action with its own gate, as good as its latency and the window. Money that has left the window does not come back, which is why this article counts only what stops the first action. What the Role Test adds is the second split on each side. A preventer either reads the proposal or reads only a counter, and those fail in different ways, as the next section shows. A non-preventer either produces a verdict that something could wire to a refusal, or it shapes what the model sees. Only the first kind has anything to wire.

This blog has used a different vocabulary before, and the test disagrees with it. Birgitta Böckeler's harness-engineering article splits a coding agent's harness into guides, which steer "before it acts", and sensors, which "observe after the agent acts and help it self-correct", and her sensors include tests, linters, type checkers, mutation testing and human review (Böckeler, 2026). I used that split in the inner versus outer harness article, and for a coding agent that corrects itself it is the right split. Under the Role Test most of her sensors are comparators: each one emits a verdict against a standard. In a coding agent the loop closes because the agent reads the failing test and tries again. In a billing agent nothing reads the verdict unless you wire it, and the refund does not get a second attempt. The Role Test also files her guides, prompt text included, as sensors. In control terms that stretches the word, since a sentence in a prompt measures nothing. I keep context-shaping with observation on purpose: both decide what the model sees, neither can refuse, and the most damaging sensor failure, a compactor that drops a rule from the window, is a shaping failure.

Positional taxonomies have the same blind spot from another side. Abhishek Tiwari separates four layers with four jobs: guardrails, action gates, the harness, and governance. His figure walks one action through them in order, from input guardrails through the model, output guardrails and the action gate to the harness that executes it, with governance as the policy over every step (Tiwari, 2026). He already argues that the missing action gate is "the most common failure mode in teams that consider themselves 'safe' because they have content filters", and I agree with him. But the trace his guardrail layer emits records both "every input blocked" and "every output flagged", and a layer defined by where it sits cannot say which of its members can stop anything. Sort the 02:14 stack by position and you find components at every stage, which says nothing about whether any of them could stop the refund.

Here is the test as code. A component is declared, not inspected: you write down what each one can do, and the declaration becomes something CI can read. Role means a role in the harness, not the message role from Part 2, and it sits beside Part 2's Locus: the locus says where a control decides, the role says what it can do. A gate whose locus is the prompt is a contradiction.

python
from __future__ import annotationsfrom dataclasses import dataclassfrom datetime import datefrom enum import Enumclass Role(str, Enum):    SENSOR = "sensor"    COMPARATOR = "comparator"    GATE = "gate"    BOUND = "bound"    RESIDUAL = "residual"  # none of the four: application code@dataclass(frozen=True)class Shadow:    owner: str    expires: date@dataclass(frozen=True)class Component:    name: str    can_prevent_action: bool = False  # Q1: can the action fail to happen because of it?    emits: str | None = None          # Q2: a verdict against a standard, by name    observes: bool = False            # Q2, no verdict: observes or shapes the context    reads_proposal: bool = False      # Q3: does its decision read the proposal?    consumes: frozenset[str] = frozenset()  # verdicts it reads    shadow: Shadow | None = None      # declared report-only: an owner and an end datedef role_test(c: Component) -> Role:    if c.can_prevent_action:                                    # question 1        if c.reads_proposal or c.consumes:                      # question 3            return Role.GATE        return Role.BOUND    if c.emits is not None:                                     # question 2        return Role.COMPARATOR    return Role.SENSOR if c.observes else Role.RESIDUAL

can_prevent_action is about the action the harness exists to control, here the refund. An output guardrail that can block a reply but runs after the tool is declared False for the refund, because for the refund that is the truth.

A declaration is a claim, and a team that called eight things guardrails would fill these fields in generously. Two checks keep the claim honest. First, the one-call-site rule later in this article makes can_prevent_action=True testable, because a component that is not on the executor's path before dispatch cannot stop anything, whatever it declares. Second, for every component declared able to prevent the action, a test feeds it a proposal it must refuse and asserts that the tool was never called; a later part of this series builds that kind of test. A third check lives in the book's registry, which rejects a component whose declared role does not match the methods it actually has. Two gaps remain even then. A component nobody declared produces no defect, so the declarations have to be the registration the executor dispatches through, not a parallel list in a docs folder. And a gate can declare consumes for a verdict its code never reads, so each consumes edge needs a test that hands the gate a failing verdict and asserts it refuses.

Gates versus bounds: why a refund ceiling should not read the proposal

Gates and bounds both stop actions, and the difference decides which failures each one survives.

A gate reads the proposal, so it refuses only what its author knew how to recognise. A bound reads a counter or a clock and raises when the number is reached; it has no opinion about the proposal because it never sees it. This demo holds a per-refund gate at $2,000 and a daily bound at $2,000 and feeds both a burst of three $1,500 refunds, none of which is too large on its own.

python
from decimal import Decimalclass BoundExceeded(Exception):    passPER_REFUND_MAX = Decimal("2000")   # a gate: reads the proposed amountDAILY_LIMIT = Decimal("2000")      # a bound: reads only the ledger totaldef per_refund_gate(amount: Decimal) -> bool:    return amount <= PER_REFUND_MAXdef daily_refund_ceiling(refunded_today: Decimal) -> None:    if refunded_today >= DAILY_LIMIT:        raise BoundExceeded(f"{refunded_today} refunded today, limit {DAILY_LIMIT}")def drain(proposals: list[Decimal], with_bound: bool) -> Decimal:    refunded_today = Decimal("0")          # in production: summed from the ledger    for amount in proposals:        try:            if with_bound:                daily_refund_ceiling(refunded_today)        except BoundExceeded as exc:            print(f"    stopped before {amount}: {exc}")            break        if not per_refund_gate(amount):            print(f"    gate refused {amount}")            continue        refunded_today += amount        print(f"    refunded {amount}, total {refunded_today}")    return refunded_todayburst = [Decimal("1500")] * 3print("gate only:")print(f"  out the door: {drain(burst, with_bound=False)}")print("gate and bound:")print(f"  out the door: {drain(burst, with_bound=True)}")
text
gate only:    refunded 1500, total 1500    refunded 1500, total 3000    refunded 1500, total 4500  out the door: 4500gate and bound:    refunded 1500, total 1500    refunded 1500, total 3000    stopped before 1500: 3000 refunded today, limit 2000  out the door: 3000

All three passed the gate, because each proposal was inside the rule it was written to check. Only the bound stopped the third, and it still let $3,000 out against a $2,000 limit. That overshoot is the price of never reading the proposal: a bound that checks before the call can be exceeded by at most one refund.

Why not close the gap by checking refunded_today + amount? That ceiling does arithmetic on one field of the proposal, so under question 3 it is a gate, and the reclassification matters because of what the check now trusts. It trusts that the amount the model wrote is the amount that will move. An amount in a second currency breaks that, and so does any tool whose arguments and the payment processor's actual movement can disagree. The blind bound reads only the ledger, which records what actually left, in one currency, after the fact. So keep the projected check as a gate, and keep the blind bound beside it. The gate gives zero overshoot when the amount is honest, and the bound holds when it is not. With one worker and a ledger that commits before the next check, the worst day is then the daily limit plus one maximum refund. Add one refund per concurrent worker, and one per refund still in flight at the processor; Part 1 made the same point: three workers that each have a ceiling of 20 make a ceiling of 60. And because the per-refund cap still trusts the proposed amount, put a per-transaction limit on the payment account too if you want that number in a runbook. A later part of this series measures that overshoot.

d2
grid-rows: 1
grid-gap: 40
gate: "Gate: reads the proposal" {
  label.near: top-center
  grid-columns: 1
  grid-gap: 10
  style: {fill: "#F4F6F7"; stroke: "#95A5A6"}
  g1: "Holds against:\namount above 2,000\non one refund" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  g2: "Allows:\nthree refunds of 1,500\nan amount in a\nsecond currency" {style: {fill: "#E74C3C"; stroke: "#A93226"; font-color: "#FFFFFF"}}
}
bound: "Bound: reads the ledger total" {
  label.near: top-center
  grid-columns: 1
  grid-gap: 10
  style: {fill: "#F4F6F7"; stroke: "#95A5A6"}
  b1: "Holds against:\nany shape of refund\nonce 2,000 has gone" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  b2: "Allows:\nthe first wrong refund\nunder the cap, and\none past it" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
}

A gate holds against the failures you enumerated and is blind to the rest. A bound caps the failures nobody enumerated, but it does not stop the first wrong action below its cap. At 02:14 the $940 refund sits under a $2,000 daily ceiling, so a bound would not have stopped it, while a gate reading the policy check's verdict would have.

Under a model upgrade that shifted the output distribution overnight, or an attacker who has read your prompts, the gate's coverage is whatever its author imagined and the bound's coverage is a number. A bound's counter has to live where the model cannot write it, which means the ledger or a counter the harness owns, never a total re-derived from something the model produced.

A refund limit in the system prompt is a sensor, not a bound

It is tempting to count "Never refund more than the invoiced amount" in the system prompt as a limit. Run the Role Test. Question 1: delete the sentence and nothing downstream behaves differently, because nothing downstream reads it; only the probability of the model's proposal changes. So no. Question 2: it emits no verdict, and it shapes what the model sees. It is a sensor.

Part 2 argued why: under the Flat Context, a rule in the window is an input to the model, and whether the model follows it is a dated measurement in a Plant Model, not a control. Filing the rule as a sensor is what the Role Test adds to that argument. Hong and colleagues put large numbers on the gap: requirements given only in the prompt are violated in "20% to 78% of tasks" across the benchmarks they test, and on τ²-Bench that includes an airline agent that "can erroneously cancel an already-flown flight" because the rule "is passed through a prompt rather than enforced symbolically in the agent harness" (Hong et al., 2026). Keeping the sentence still makes sense, and the same paper shows why: upgrading the model from GPT-4o to GPT-5 cut violating runs from 52% to 20%. A sensor that moves the distribution earns its place.

d2
grid-rows: 1
grid-gap: 40
prompt: "Limit as a sentence" {
  label.near: top-center
  grid-columns: 1
  grid-gap: 10
  style: {fill: "#F4F6F7"; stroke: "#95A5A6"}
  p1: "System prompt:\n'never refund above\nthe invoice'" {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
  p2: "Model: proposal is\nmore likely right" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  p3: "Wrong proposal:\nexecutes" {style: {fill: "#E74C3C"; stroke: "#A93226"; font-color: "#FFFFFF"}}
}
counter: "Limit as a counter" {
  label.near: top-center
  grid-columns: 1
  grid-gap: 10
  style: {fill: "#F4F6F7"; stroke: "#95A5A6"}
  c1: "Ledger total\nrefunded today" {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
  c2: "Bound: total at\nlimit? raise" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  c3: "At the limit:\nany proposal stopped" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}

Nothing written in the prompt can say no. Keep it, and move the number into a counter that raises. Then two components do two jobs, and only one of them has to be true every time.

Replit's July 2025 incident had this shape. The agent deleted a production database during what Fortune describes as a "code and action freeze", after "violating explicit instructions not to proceed without human approval", and the fixes Replit's CEO announced were structural: separating development and production databases, better rollback, and a planning-only mode (Fortune, 2025). An instruction was replaced with structure: two changes designed to keep development from reaching production, and a rollback for when something still gets through.

Loop closure: a CI check that every guardrail verdict reaches a gate

"Closure" here is the control-engineering word; it has nothing to do with a Python function that captures variables. In control engineering, a loop is closed when the measurement is "'fed back' as input to the process, closing the loop", and in open-loop control "the control action from the controller is independent of the 'process output'" (Wikipedia, Closed-loop controller; Åström and Murray's Feedback Systems is the textbook treatment). A harness has loop closure when every verdict a comparator emits is read by at least one gate, and every verdict a gate reads is emitted by some comparator. A verdict outside the loop can describe what went wrong and cannot change the outcome. For that verdict, the harness is instrumentation.

Loop closure is a property of the declared component graph, so it needs no model, no API key and no network. It can run on every commit.

python
@dataclass(frozen=True)class Defect:    component: str    kind: str    detail: strdef check_closure(components: list[Component], today: date) -> list[Defect]:    roles = {c.name: role_test(c) for c in components}    emitted = {c.emits: c for c in components if roles[c.name] is Role.COMPARATOR}    gate_reads = {v for c in components if roles[c.name] is Role.GATE                  for v in c.consumes}    defects: list[Defect] = []    for verdict, c in sorted(emitted.items()):        if verdict in gate_reads:            continue        readers = sorted(r.name for r in components if verdict in r.consumes)        seen_by = f"; read only by {', '.join(readers)}" if readers else ""        if c.shadow is None:            defects.append(Defect(c.name, "unconsumed-verdict",                                  f"no gate reads '{verdict}'{seen_by}"))        elif c.shadow.expires < today:            defects.append(Defect(c.name, "shadow-expired",                                  f"shadow mode owned by {c.shadow.owner} "                                  f"ended {c.shadow.expires}"))    for c in components:        if roles[c.name] is Role.GATE:            for verdict in sorted(c.consumes - emitted.keys()):                defects.append(Defect(c.name, "dangling-dependency",                                      f"nothing emits '{verdict}'"))    return defects

Only a gate's consumes closes a loop. When the dashboard declares that it reads amount_on_invoice, the check counts that read for nothing, because a dashboard cannot refuse. It names the dashboard in the defect anyway, since "read only by violations-dashboard" is the sentence a postmortem would otherwise take pages to reach. shadow only means something on a comparator whose verdict no gate reads; anywhere else the check ignores it. Verdict names must also be unique: two comparators emitting the same name collapse into one entry in emitted, and a production version should report that as a defect.

Declare the 02:14 stack and run it:

python
TODAY = date(2026, 11, 12)design_doc_guardrails = [    Component("moderation-filter", emits="moderation_score"),    Component("schema-validator", emits="tool_call_schema"),    Component("refund-policy-check", emits="amount_on_invoice"),    Component("nightly-eval", emits="helpfulness"),    Component("tracing", observes=True),    Component("prompt-refund-rule", observes=True),    Component("violations-dashboard", consumes=frozenset({"amount_on_invoice"})),    Component("invoice-retry-wrapper"),]def report(title: str, components: list[Component], today: date) -> None:    print(title)    for c in components:        print(f"  {c.name:<22} {role_test(c).value}")    defects = check_closure(components, today)    print(f"  closure defects: {len(defects)}")    for d in defects:        print(f"    {d.component}: {d.kind}")        print(f"      {d.detail}")    print()report("design doc: 8 'guardrails'", design_doc_guardrails, TODAY)
text
design doc: 8 'guardrails'  moderation-filter      comparator  schema-validator       comparator  refund-policy-check    comparator  nightly-eval           comparator  tracing                sensor  prompt-refund-rule     sensor  violations-dashboard   residual  invoice-retry-wrapper  residual  closure defects: 4    refund-policy-check: unconsumed-verdict      no gate reads 'amount_on_invoice'; read only by violations-dashboard    nightly-eval: unconsumed-verdict      no gate reads 'helpfulness'    moderation-filter: unconsumed-verdict      no gate reads 'moderation_score'    schema-validator: unconsumed-verdict      no gate reads 'tool_call_schema'

Four comparators, two sensors, two components that are not harness, and no gates or bounds. Those two residual rows are what I call the Harness Residual, and the last section returns to them. Each of the four defects is a verdict with nowhere to go, and the first is the refund.

d2
grid-rows: 1
grid-gap: 50
open: "Refund loop open: 4 defects" {
  label.near: top-center
  grid-columns: 1
  grid-gap: 14
  style: {fill: "#FDEDEC"; stroke: "#E74C3C"}
  o1: "refund-policy-check\nemits amount_on_invoice" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
  o2: "violations-dashboard\nreads it, cannot refuse" {style: {fill: "#C8D0D1"; stroke: "#6C7A7B"; font-color: "#2C2C2A"}}
  o3: "issue_refund\nexecutes" {style: {fill: "#E74C3C"; stroke: "#A93226"; font-color: "#FFFFFF"}}
}
closed: "Refund loop closed: 3 left" {
  label.near: top-center
  grid-columns: 1
  grid-gap: 14
  style: {fill: "#EAF7EE"; stroke: "#3F9E52"}
  c1: "refund-policy-check\nemits amount_on_invoice" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
  c2: "refund-gate\nconsumes amount_on_invoice" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  c3: "issue_refund\nonly if the gate allows" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}

Closing the loop left the comparator untouched; what changed is the component reading its output. check_closure never looks at how accurate a comparator is, so replacing the moderation filter with a better classifier leaves the count at four. Adding or upgrading a comparator never lowers it, which is why "add another guardrail" so often leaves exposure where it was.

Part 1 built refund_comparator, refused inline on its verdict, and kept two per-run ceilings outside it, so its loop was already closed. Classified by the Role Test, those ceilings are not the same thing. The count ceiling is a bound. The total ceiling checks moved + proposal.amount, which by the gates-versus-bounds section above makes it a gate that trusts the proposed amount. Part 1's pair still works, and this part adds what it lacked: a bound that reads only what the ledger says already left. No full oracle exists for the billing agent that could tell you after the fact whether the $940 was right; Part 1 called a balance check a partial oracle, and the refund policy check here is one. Loop closure needs no oracle at all: it is checked on the declarations before any model runs, which is rare among harness checks.

Shadow mode for LLM guardrails: report-only checks with an expiry date

A strict closure check produces a defect for every report-only component, and some report-only components are correct. You roll out a new classifier by watching what it would have blocked. Bedrock's detect mode exists "to help evaluate whether your guardrail is working the way that you expect" (AWS, Bedrock Guardrails). OPA Gatekeeper has enforcementAction: dryrun "to ensure no actual changes are made as a result of the constraint" (Gatekeeper docs), and Kubernetes Pod Security Admission has audit and warn modes in which violations "are otherwise allowed" (Kubernetes docs).

So an unconsumed verdict has three honest endings. Wire it to a gate. Delete the comparator. Or declare it shadow, with an owner and an end date, and let the check enforce the date. None of those three systems, as far as I found, fails a build when a dry-run policy has no enforcing twin or has been in dry run past a date; the mode is declared and then left alone. What a closure check must not accept is the fourth ending, the one the 02:14 stack had: a verdict nobody decided anything about.

d2
grid-rows: 2
grid-columns: 2
grid-gap: 16
w: "1. Wire it\na gate consumes the verdict" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
d: "2. Delete it\nthe comparator was decoration" {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
s: "3. Declare shadow\nowner + end date, checked in CI" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
x: "Not allowed: undecided\nverdict feeds a dashboard" {style: {fill: "#E74C3C"; stroke: "#A93226"; font-color: "#FFFFFF"}}

Here is the repaired stack. Rejecting malformed calls makes the schema validator a gate, with its own check and no verdict to consume. Now a gate reads the refund policy check. The daily ceiling reads the ledger. Trust and safety owns the moderation filter, which stays in shadow until 15 December. The nightly eval is gone from this graph: it judges yesterday's traffic, so the gate that should read it is the deploy gate in your release pipeline, and dropping it here is honest only if that pipeline's own declarations pass check_closure.

python
repaired = [    Component("moderation-filter", emits="moderation_score",              shadow=Shadow(owner="trust-and-safety", expires=date(2026, 12, 15))),    Component("schema-validator", can_prevent_action=True, reads_proposal=True),    Component("refund-policy-check", emits="amount_on_invoice"),    Component("refund-gate", can_prevent_action=True, reads_proposal=True,              consumes=frozenset({"amount_on_invoice"})),    Component("daily-refund-ceiling", can_prevent_action=True),    Component("prompt-refund-rule", observes=True),    Component("tracing", observes=True),]report("repaired", repaired, TODAY)report("repaired, checked on 2027-01-04", repaired, date(2027, 1, 4))

Because the second report repeats the role table, it is cut to ... below.

text
repaired  moderation-filter      comparator  schema-validator       gate  refund-policy-check    comparator  refund-gate            gate  daily-refund-ceiling   bound  prompt-refund-rule     sensor  tracing                sensor  closure defects: 0repaired, checked on 2027-01-04  ...  closure defects: 1    moderation-filter: shadow-expired      shadow mode owned by trust-and-safety ended 2026-12-15

On 4 January the same declarations fail, and the failure names the team that owns the decision. Run this check on main and on a scheduled job that opens a ticket for the owner, not on every branch build, or a hotfix branch cut from last month fails for a reason it did not introduce. Cap the length too: a shadow declared until 2099 passes the code above, so a production version should also reject any expiry more than about 90 days past the declaration. A shadow period that nobody ends becomes the 02:14 stack again, one quarter later and with a better reason.

Why loop closure is not enough: timing and a second dispatch path

Loop closure checks edges. It cannot see when an edge is traversed, or whether every path to the tool goes through it. Issue #991 was clean on both counts at the graph level: a screen emitted a verdict, a tripwire consumed it. Declare that pair and check it, and the result is an empty list.

python
import asyncioevents: list[str] = []async def screen_ticket() -> bool:    await asyncio.sleep(0.05)              # a classifier call takes time    events.append("screen: injection found, tripwire raised")    return Falseasync def agent_turn() -> None:    await asyncio.sleep(0.01)              # the model replies first    events.append("tool: issue_refund(940.00) executed")async def parallel_guardrail() -> None:    agent = asyncio.create_task(agent_turn())    if not await screen_ticket():        agent.cancel()                     # too late: the tool already ranasync def blocking_guardrail() -> None:    if not await screen_ticket():        return                             # the agent never starts    await agent_turn()race_graph = [    Component("injection-screen", emits="injection"),    Component("input-tripwire", can_prevent_action=True,              consumes=frozenset({"injection"})),]print("closure defects in the tripwire graph:", check_closure(race_graph, TODAY))for label, run in (("parallel", parallel_guardrail),                   ("blocking", blocking_guardrail)):    events.clear()    asyncio.run(run())    print(f"{label}:")    for e in events:        print(f"  {e}")
text
closure defects in the tripwire graph: []parallel:  tool: issue_refund(940.00) executed  screen: injection found, tripwire raisedblocking:  screen: injection found, tripwire raised

Both runs reached the right verdict on a closed graph. In the parallel run the gate fired after the money left; the gap here is the 40 milliseconds between the two simulated sleeps, and in production it is however long the classifier call takes. This is the OpenAI Agents SDK's documented default: input guardrails run with run_in_parallel=True, and the blocking mode, run_in_parallel=False, is the one that "is ideal ... when you want to avoid potential side effects from tool calls" (OpenAI Agents SDK, Guardrails).

mermaid
sequenceDiagram
    participant H as Harness
    participant S as Injection screen
    participant A as Agent
    participant P as Payment API
    H->>S: screen ticket (parallel)
    H->>A: start turn (parallel)
    A->>P: issue_refund(940.00)
    P-->>A: refunded
    S-->>H: verdict: injection found
    H->>A: cancel
    Note over H,P: Graph is closed. The gate ran after the action.

Under Role Test question 1, a tripwire running in parallel with the action stops it only when it happens to finish first, so it cannot be relied on to prevent the action, and for that action it does not count as a preventer, whatever its exception is called. The screen stays a comparator; the tripwire, declared honestly for the refund, has no role at all. A component graph has no notion of order, so check_closure cannot detect the race itself. What it can do is turn a correctly declared race into a defect:

python
honest_graph = [    Component("injection-screen", emits="injection"),    Component("input-tripwire", can_prevent_action=False,              consumes=frozenset({"injection"})),]report("tripwire declared for the refund", honest_graph, TODAY)
text
tripwire declared for the refund  injection-screen       comparator  input-tripwire         residual  closure defects: 1    injection-screen: unconsumed-verdict      no gate reads 'injection'; read only by input-tripwire

With run_in_parallel=False the same tripwire is a gate again, and the defect goes away. The declaration was written by hand, so the one-call-site rule below is what catches a team that declares a racing tripwire as a gate.

A second gap is a path the graph never sees. In August 2026 the Cloud Security Alliance summarised CoreBreak, a set of flaws in which tool execution in Amazon Bedrock AgentCore, Google's Agent Development Kit (ADK) and Vercel's AI SDK "could each be induced to run a tool without a legitimate model turn ever occurring", so model-level guardrails "were structurally irrelevant to the attack; there was no model decision left for those controls to intervene in" (CSA, 2026). Nothing about those flaws depended on how the guardrails were wired: the tool was reached through the executor without a model turn, so the guardrails on the model path never saw it.

So closure needs a partner rule: one call site. There is exactly one function that turns a proposal into a tool call, it runs bounds, then comparators, then gates, then dispatches, and a refusal leaves it as an exception, so ignoring one takes a deliberate except, which code review and a lint rule can catch. Tool functions are registered only inside it. A CI test that searches the codebase for direct references to issue_refund outside that function is crude, and it catches a second caller, such as a new background job, before it ships, though not a framework graph node that skips the executor. My book's Chapter 3, "Sensors, Comparators, Gates, Bounds," builds that executor, and its constructor refuses to build a harness whose loop is open (Harness Engineering for Production AI Systems).

d2
direction: down
proposal: "Proposal:\nissue_refund(940.00)" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
exec: "The one executor" {
  label.near: top-center
  grid-rows: 4
  grid-columns: 1
  grid-gap: 10
  style: {fill: "#F4F6F7"; stroke: "#95A5A6"}
  b: "1. bounds" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  c: "2. comparators" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
  g: "3. gates" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  d: "4. dispatch" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}
tool: "issue_refund" {style: {fill: "#E74C3C"; stroke: "#A93226"; font-color: "#FFFFFF"}}
caller: "Second caller:\nbackground job, or a\ntool run with no model turn" {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
proposal -> exec.b
exec.d -> tool
caller -> tool: "bypass: caught by the\nreference-search CI test" {style: {stroke: "#E74C3C"; stroke-dash: 4}}

The red dashed edge is the one loop closure cannot see, because it never enters the box the declarations describe. Every guarantee in this article holds only for proposals that come in at the top, and catching a refund that arrived any other way takes owed decisions declared per effect.

Then there is the third gap: a gate that exists and does not act. Target's 2013 breach is the case people cite. In Bloomberg Businessweek's words, the detection system "worked beautifully", and "Target's security team turned that function off", the automatic malware deletion, a configuration that leaves the last decision with people (MPR News, quoting Businessweek, 2014). According to the Senate staff report, Target "failed to respond to multiple automated warnings" (NBC News / Reuters, 2014). That is the shape of an unstaffed human decision point: the automatic response was switched off so people kept the decision, and the people did not act. In the billing agent the person is the copilot's approver, and the Role Test classifies them as a gate, because they read the proposal and can refuse it. Then it forces the two questions a design review skips: what is this gate's latency, and who covers it between 22:00 and 07:00? Remove the copilot's human gate and change nothing else, and what you have is the billing agent's overnight mode.

Which guardrail code is just application code: the Harness Residual

Two of the eight 02:14 components were not harness. Everything the Role Test classifies as none of the four roles is the Harness Residual, and it is application code. Most of the code around a model call belongs there, and that is fine. Filing it under "harness" is the failure, because harness gets a stricter bar: it is declared, classified, checked for closure and changed under a changelog. Put the residual under that bar and the harness grows to a size nobody reviews, with the four components that hold the system together lost among forty that do not.

The retry wrapper is the instructive case, because it is residual with a bound inside it.

d2
direction: down
wrapper: "@retry(stop=stop_after_attempt(3))\naround get_invoice" {style: {fill: "#C8D0D1"; stroke: "#6C7A7B"; font-color: "#2C2C2A"}}
split: "Split by the Role Test" {
  label.near: top-center
  grid-rows: 1
  grid-gap: 20
  style: {fill: "#F4F6F7"; stroke: "#95A5A6"}
  plumb: "Retrying with backoff\nresidual: normal code review" {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
  cap: "The number 3\nbound: lives in the ceilings file" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
}
wrapper -> split

Retrying is plumbing. But the 3 is a bound on invoice reads, a different action from the refund, and it still belongs with your other ceilings, in one file someone can find and change together during an incident. A retry around issue_refund itself is a different and more dangerous matter, and a later part of this series takes it up with idempotency keys.

At the other edge of the residual sit the violations dashboard and the tracing backend. Tracing observes the run, so it is a sensor, and a sensor is harness: what it drops is what the next investigation cannot see, and the same holds for the sensor at the model's entry point. A dashboard that renders a verdict which already exists observes nothing new, so it is residual, and that classification is what lets the closure check ignore its read.

Watch the ratio. Run the Role Test across the ten components nearest your model call before you read their names, and count how many come back residual. That count is the first honest measure of how much control layer exists.

One limit, so the test is not oversold. Both the Role Test and loop closure check completeness, not correctness. A gate can be classified correctly, wired correctly, closure-clean, and wrong on every proposal it sees. A comparator can return passed=True on an exception. Those need tests that feed the harness hostile proposals and assert which component refuses, which come later in this series.

Checklist: audit an LLM guardrail stack with the Role Test

  1. List every component someone calls a guardrail, and declare each one. For each, answer the three questions in order, for the specific action you care about (issue_refund, send_email, delete_rows), not for the request in general.
  2. Treat "blocks text" as a comparator answer until proven otherwise. An output guardrail, a parallel input guardrail, a screen whose verdict your code "can branch on", and any guardrail in detect or dry-run mode cannot be relied on to make the action fail.
  3. Run check_closure in CI on every commit. Fail the build on unconsumed-verdict, dangling-dependency and shadow-expired.
  4. Give every unwired verdict one of three endings. Wire it to a gate, delete the comparator, or declare shadow with an owner and an end date. Reject the undecided fourth.
  5. Put a bound beside every gate that guards money or deletion. The gate covers the failures you listed. The bound covers the rest, from a counter the model cannot write.
  6. Keep prompt rules, and file them as sensors. Move every number that must hold into a counter or a gate.
  7. Enforce one call site. Register tools only inside the executor, run guardrails that must stop an action before it starts, and test that no other code references the tool functions.
  8. Model each human approver as a gate with a latency and an availability. Write down what happens to a proposal at 02:14.
  9. Count the residual and review it as application code. Pull any limit hiding inside it into the ceilings file.

Going deeper: Chapter 3 of the book

This is Part 3 of a series that follows Harness Engineering for Production AI Systems one chapter at a time. Chapter 3, "Sensors, Comparators, Gates, Bounds," adds what this article leaves out: the four roles as typed protocols, a registry that rejects a component whose declared role does not match its shape, the executor that makes an open loop a construction error and a swallowed refusal unrepresentable, where each role has to sit relative to the trust boundary, and why a classical comparator outputs a signed error that boolean validators throw away. Code for the chapter is the ch03-sensors-comparators-gates-bounds tag of the companion repository, and its tests need no model and no API key.

Part 2 covers why a prompt rule is an input to the model and not a control. For where one policy source should sit once your gates exist, see Agent Policy Enforcement: Why Copied Guardrails Fail.

References


AI Security

Follow for more technical deep dives on AI/ML systems, production engineering, and building real-world applications:


Books by Ranjan Kumar

Federated AI Agents cover

Federated AI Agents

Right-Sized AI cover

Right-Sized AI

Harness Engineering for Production AI Systems cover

Harness Engineering

The 7 GenAI Architectures cover

The 7 GenAI Architectures

Building Real-World Agentic AI Systems with LangGraph cover

Building Real-World Agentic AI Systems

The ChatML Handbook cover

The ChatML Handbook

The Chat Templates Handbook cover

The Chat Templates Handbook

Comments