# Under what conditions must an instance treat a guardrail decision as a first-class trace span rather than an annotation, and what breaks when it does not **Date of Record:** 2026 November 25 **Scope:** Applies to production agent observability pipelines that emit OpenTelemetry-style spans for LLM calls, tool invocations, and guardrail verdicts, and that join those spans with offline eval results by trace/span ID. Does not apply to single-shot inference where guardrail verdicts are synchronous, inline, and never queried out-of-band. ## Core Distinction A guardrail decision is not a property of a response; it is an *event* with a causal position in the agent's execution graph. Pipelines that record it as an annotation on the parent LLM span (a key-value attribute like `guardrail.blocked=true`) collapse two distinct failure surfaces into one: the surface where the model produced disallowed content, and the surface where the guardrail itself made a decision under its own latency, version, and input state. When an eval later asks "did this trace violate policy?", the annotation answers a question about the *output* while the operator believes it is answering a question about the *decision*. The invariant that must hold is: every guardrail verdict is its own span, with its own `span_id`, `parent_span_id` pointing at the decision's causal input, a `guardrail.version`, and a `decision` enum — and eval joins resolve against that span, not against the annotated parent. ## What Was Observed A retrieval-augmented support agent under a PII-scrubbing guardrail began producing traces where `guardrail.blocked=true` appeared on 0.4% of LLM spans, yet the eval harness reported a 3.1% policy-violation rate for the same window. The two numbers were computed from the same trace store. The gap was not a metric bug; it was a span-graph bug. Mechanics of the divergence. The guardrail ran as a post-processing hook after the model call, with a 40ms budget. When the guardrail exceeded budget, the hook returned a fail-open verdict (`decision=allow`, `reason=timeout`) and the response was emitted. The instrumentation attached `guardrail.blocked=false` to the parent span — indistinguishable from a genuine `allow`. Meanwhile the eval pipeline did not read the annotation at all; it re-scored the emitted `response.text` against a policy classifier. So: 1. Guardrail timed out → fail-open → response emitted with disallowed PII. 2. Parent span annotated `guardrail.blocked=false` (a lie by omission: the guardrail did not decide "allow", it decided "no decision"). 3. Eval re-scored text → flagged violation. 4. Operator dashboard read the annotation → 0.4% block rate looked healthy. The two systems were reading different questions off the same span. The annotation was a *conclusion*, the eval was a *re-derivation*, and nothing in the trace graph recorded that the guardrail had been consulted and declined to conclude. A second, subtler trace: under context-window saturation the guardrail's own prompt (which included the full response plus policy) was truncated by the guardrail model's tokenizer. The guardrail returned `allow` with no error. This is the same failure class — a decision made under degraded input, recorded as a clean verdict — but it originated inside the guardrail, not in its timeout budget. Neither is visible from a boolean annotation. ## Condition of Validity The annotation-as-verdict pattern is only valid when all three hold: - The guardrail is **synchronous and infallible** (no timeout, no model-based guardrail that can itself be truncated or refusals). - The guardrail's `allow` is **total** — it means "evaluated the complete input and permitted it," not "did not block." - No downstream consumer **re-derives** the decision from artifacts (text, embeddings) rather than reading the recorded verdict. In production, model-based guardrails violate all three. The moment any one fails, the annotation loses its referent: it no longer names a decision, only a default. The correct invariant is that the guardrail span carries a tri-state `decision ∈ {allow, block, indeterminate}` where `indeterminate` is a distinct, non-default value covering timeout, truncation, and internal error. `indeterminate` must never be folded into `allow` for dashboards, and eval joins must treat `indeterminate` as a violation-or-unknown, not a pass. ## Decision Boundary The boundary is not "is the guardrail reliable" but "does the trace graph preserve the difference between a verdict and the absence of one." Concretely, route to a guardrail span (not an annotation) when any of the following is true: - The guardrail has a **bounded budget** that can expire (timeout, retry cap, rate limit). - The guardrail's input is **constructed** from model output and can be truncated, re-tokenized, or mutated between construction and evaluation. - The guardrail is **model-based** and can itself refuse, hallucinate a verdict, or return malformed output. - Any consumer performs **out-of-band re-derivation** (eval, audit, replay) that must reconcile against the recorded decision. If none hold — a deterministic regex scrubber with no budget and no construction step — an annotation is defensible. The failure mode is applying the annotation pattern to a guardrail that satisfies the boundary conditions because the *first* guardrail in the system was deterministic, and the pattern was inherited by every guardrail added after. The guardrail span must also record `input_hash` over the exact bytes the guardrail evaluated. Without it, a replay that reconstructs the guardrail input from the parent span's `response.text` can diverge from what the guardrail actually saw — the truncation case above — and the replay will "verify" a decision that was made on different input. ## Operational Effect With guardrail spans and tri-state decisions, the 0.4%/3.1% gap resolves into three measurable populations: genuine `allow` (guardrail ran, passed), `block` (guardrail ran, denied), and `indeterminate` (guardrail did not conclude). The third population is the operational signal — it is where fail-open, truncation, and budget exhaustion live, and it is invisible under annotation. Dashboards must report `indeterminate` as its own series; alerting fires on `indeterminate` rate, not block rate, because a rising block rate is the guardrail working and a rising indeterminate rate is the guardrail absent. The eval join changes shape: it joins `eval.result` to `guardrail.span_id`, and where no guardrail span exists for a response, that is itself a finding — an uninstrumented path. Replay verification becomes possible only because `input_hash` pins the guardrail's view. Without these, the pipeline is not observing the guardrail; it is observing the model and inferring the guardrail, and the inference silently assumes the guardrail always concluded. ```python import hashlib from dataclasses import dataclass, field from enum import Enum from typing import Optional class GuardrailTraceError(RuntimeError): """Raised when a guardrail decision cannot be represented as a valid trace span.""" class Decision(Enum): ALLOW = "allow" BLOCK = "block" INDETERMINATE = "indeterminate" # timeout, truncation, internal error @dataclass class GuardrailSpan: span_id: str parent_span_id: str guardrail_version: str input_hash: str decision: Decision reason: str = "" budget_ms: int = 0 elapsed_ms: int = 0 def emit_guardrail_span( span_id: str, parent_span_id: str, guardrail_version: str, evaluated_input: bytes, decision: Optional[Decision], reason: str, budget_ms: int, elapsed_ms: int, ) -> GuardrailSpan: if decision is None: # A guardrail that returned no verdict is NOT an allow. # Coercing it to allow is the annotation failure this invariant forbids. raise GuardrailTraceError( f"guardrail {guardrail_version} returned no decision for span {span_id}; " "must be recorded as INDETERMINATE, never folded into ALLOW" ) if elapsed_ms > budget_ms and decision is Decision.ALLOW: raise GuardrailTraceError( f"span {span_id}: ALLOW recorded after budget overrun " f"({elapsed_ms}ms > {budget_ms}ms); fail-open must be INDETERMINATE" ) if not evaluated_input: raise GuardrailTraceError( f"span {span_id}: empty evaluated input; input_hash would not pin " "the guardrail's actual view and replay verification is unsound" ) return GuardrailSpan( span_id=span_id, parent_span_id=parent_span_id, guardrail_version=guardrail_version, input_hash=hashlib.sha256(evaluated_input).hexdigest(), decision=decision, reason=reason, budget_ms=budget_ms, elapsed_ms=elapsed_ms, ) def join_eval_to_guardrail(eval_span_id: str, guardrail_spans: dict[str, GuardrailSpan]) -> Decision: span = guardrail_spans.get(eval_span_id) if span is None: # Uninstrumented path: eval saw a response with no guardrail decision. raise GuardrailTraceError( f"eval {eval_span_id} has no corresponding guardrail span; " "response was emitted on an uninstrumented path" ) if span.decision is Decision.INDETERMINATE: # Do not treat unknown as pass; surface it as its own population. return Decision.INDETERMINATE return span.decision ```