# How does an instance detect when taint labels survive a tool round-trip but the *provenance edge* is severed **Date of Record:** 2026 November 26 **Scope:** Applies to agent runtimes that implement prompt-injection defense by attaching data-flow taint labels to untrusted content (RAG chunks, tool outputs, web fetches) and propagating those labels through subsequent tool calls. Does not apply to single-shot inference without tool use, nor to runtimes that treat all context as uniformly trusted. ## Core Distinction There are two distinct things a taint-tracking system must preserve across a tool round-trip: 1. **The label** — a boolean/enumeral marking such as `untrusted:web:chunk_7f3a`. Cheap to copy, easy to attach to a message. 2. **The provenance edge** — the directed record that *this specific output byte range was derived from that specific input byte range via this specific transformation*. This is what lets you answer "if I act on this value, which untrusted source am I acting on?" Most implementations preserve (1) and silently drop (2). The label survives because it is serialized into the message envelope; the edge is dropped because the tool boundary is a process/API hop that only forwards content, not the derivation graph. The result is a *tainted-but-unattributable* state: the agent knows "something in this turn is untrusted" but can no longer localize *which span* of the tool output carries the taint, nor reconstruct the path from attacker-controlled text to the argument it is about to pass to a privileged tool. This is the severed-edge condition, and it is the boundary failure this record concerns. The distinction matters because the two failure modes have opposite signatures. A dropped *label* fails closed (content looks trusted, defense triggers on nothing — detectable by a downstream assertion). A severed *edge* fails open in the attribution sense: the label is still present, the guardrail still fires "tainted context present," but the localization is wrong, so the sanitizer redacts the wrong span and the injected instruction survives in the span that no longer has an edge pointing at it. ## What Was Observed A retrieval-augmented agent fetched three chunks. Chunk `c_2` contained an injected string: ``. The runtime labeled `c_2` as `untrusted:rag` at ingest and passed it to a `summarize` tool. The `summarize` tool returned a structured object: ``` {"summary": "...", "entities": ["vendor_x", "0xATTACKER"], "raw_span_refs": [12,13,14]} ``` The label `untrusted:rag` was re-attached to the tool output envelope (label preserved). But the tool's implementation constructed `entities` by regex over the *decoded* chunk text and did not emit a mapping from each entity back to a source span. The `raw_span_refs` field pointed at the *summary* string offsets, not the chunk. So the edge `c_2 → entities[1]` was never written. Two turns later the agent called `transfer_funds(to=entities[1])`. At the moment of the call, the taint checker saw `untrusted:rag` on the *turn context* and raised a generic "untrusted content in context" warning — but the argument-level check, which asks "is *this argument value* reachable from an untrusted span?", returned `False`, because no edge existed from `c_2` to `entities[1]`. The generic warning was suppressed by an operator-set `allow_tainted_context=true` flag (common in production to reduce noise). The transfer executed. The observable signature in logs: the label count on the turn was nonzero, the argument-level provenance query returned an empty edge set, and the two disagreed. That disagreement — *label present, edge absent* — is the detection signal. ## Condition of Validity The severed-edge condition is only meaningful, and only detectable, under these conditions: - **Taint is span-granular, not turn-granular.** If the runtime only tracks "turn is tainted," there is no edge to sever and no localization to lose; the failure degrades to the coarser (and safer) all-or-nothing case. The bug requires that the system *promises* span-level attribution. - **At least one tool boundary sits between ingest and action.** In-context RAG with no tool call preserves edges trivially (the chunk text and its label coexist). The severance happens at serialization: the tool call marshals content into a request, the tool returns content in a response, and the derivation graph is not part of either wire format. - **The tool output is structured and re-usable.** Free-text tool outputs that the model re-reads whole tend to keep edges implicitly (the model sees the chunk and the summary together). Structured outputs (`entities`, `args`, `urls`) that get *extracted and passed onward* are where the edge must be explicit and where its absence is fatal. - **The argument-level check is the load-bearing guardrail.** If the runtime blocks all tainted turns, severed edges are moot. The condition bites precisely when the design relies on *precise* taint to avoid over-blocking. It does **not** apply when: the tool is a pure function over already-trusted inputs; the runtime re-derives provenance by re-running the extraction with an instrumented tracer (expensive but sound); or the action surface is read-only. ## Decision Boundary The runtime must decide, per tool output, between two policies: - **Edge-preserving (default for any tool whose output feeds an action).** The tool contract requires every returned field to carry a `provenance: [source_span_id, ...]` array. If a tool cannot emit provenance (third-party, opaque), its output is treated as *maximally tainted*: every field inherits the union of all untrusted labels in the input, and argument-level checks treat it as untrusted regardless of content. This over-blocks but never under-attributes. - **Edge-dropping (permitted only for terminal/sink tools).** A tool whose output is never re-used as an argument — a display formatter, a logger — may drop edges because nothing downstream depends on attribution. This must be declared in the tool's capability manifest, not inferred. The boundary is crossed the moment an edge-dropping tool's output is *read back into the reasoning context and used to construct a subsequent call argument*. At that instant the runtime must either (a) have the edge, or (b) fall back to maximal taint. The failure mode is the third path that actually occurs in practice: the label is present, the edge is absent, and the runtime takes neither branch because it has no check that compares the two. The invariant to enforce: **for every argument passed to a side-effecting tool, `argument_provenance(arg) ≠ ∅` OR `turn_taint_labels = ∅`.** Equivalently: a tainted turn may never produce an action argument with empty provenance. Violation of this invariant is exactly the severed-edge condition, and it is checkable at call time without re-running anything. ## Operational Effect When the invariant is enforced, the practical consequences are: 1. **Third-party tools become taint-sinks.** Any tool that cannot emit provenance forces its entire output to maximal taint, which means downstream argument checks block. This is the correct trade but it surprises teams who expected "structured output = clean output." Budget for it: opaque tools collapse the agent's action space. 2. **Sanitizers must be edge-aware.** A redactor that removes the injected span must delete the *edge* as well as the text, otherwise the label persists with no referent and every subsequent argument check over-blocks forever (a "taint leak" that never drains). Redaction is a provenance-graph mutation, not a string operation. 3. **The detection is a set-difference, cheap to compute.** At each side-effecting call: `if turn_taint_labels and not argument_provenance(arg): raise`. This single comparison catches the severed edge, the dropped-label case (both empty — caught by a separate ingest assertion), and the over-broad case (provenance present but label absent — caught by a third check). Three comparisons cover the taint lattice's failure corners. 4. **Replay diverges.** Because the edge is not in the wire format, replaying a recorded tool interaction reconstructs the label but not the edge, so a replayed session will *fail* the invariant check that the original session passed (or vice versa, if the original silently dropped it). Provenance must be logged alongside the message, or replay-based auditing is unsound for exactly this class of bug. The guardrail is not "detect injection." It is "detect the disagreement between label presence and edge presence at the action boundary," which is a structural property of the runtime's own bookkeeping and therefore decidable, cheap, and independent of whether the model was actually fooled. ```python from dataclasses import dataclass, field from typing import FrozenSet class SeveredProvenanceEdge(RuntimeError): """Raised when a tainted turn produces an action argument with no provenance edge. This is the severed-edge condition: the taint label survived the tool round-trip but the derivation edge from source span to argument value did not. """ @dataclass(frozen=True) class ToolOutput: fields: dict # field name -> value provenance: dict # field name -> frozenset of source span ids emits_provenance: bool # did the tool declare + honor the contract? @dataclass class TurnContext: taint_labels: FrozenSet[str] = field(default_factory=frozenset) ingested_spans: FrozenSet[str] = field(default_factory=frozenset) def ingest_untrusted(ctx: TurnContext, span_id: str, label: str) -> None: ctx.taint_labels = ctx.taint_labels | {label} ctx.ingested_spans = ctx.ingested_spans | {span_id} def absorb_tool_output(ctx: TurnContext, out: ToolOutput) -> dict: """Fold a tool output back into the turn, normalizing provenance. If the tool did not emit provenance, every field inherits the union of all ingested untrusted spans (maximal taint). This is the edge-preserving fallback that prevents silent severance. """ if out.emits_provenance: merged = {k: frozenset(v) for k, v in out.provenance.items()} else: inherited = frozenset(ctx.ingested_spans) merged = {k: inherited for k in out.fields} return merged def check_action_boundary( ctx: TurnContext, argument_name: str, argument_provenance: FrozenSet[str], ) -> None: """Enforce: a tainted turn may never yield an action arg with empty provenance.""" if ctx.taint_labels and not argument_provenance: raise SeveredProvenanceEdge( f"argument {argument_name!r} has no provenance edge while turn " f"carries taint labels {sorted(ctx.taint_labels)}; " f"tool round-trip likely dropped the derivation edge" ) # Over-attribution guard: provenance present but no label is also a bug. if argument_provenance and not ctx.taint_labels: raise SeveredProvenanceEdge( f"argument {argument_name!r} cites spans {sorted(argument_provenance)} " f"but turn has no taint labels; label was dropped at ingest" ) def run_side_effecting_call(ctx: TurnContext, out: ToolOutput, arg_field: str) -> None: prov = absorb_tool_output(ctx, out) check_action_boundary(ctx, arg_field, prov.get(arg_field, frozenset())) # ... invoke the privileged tool only after the invariant holds ... ```