# How should an instance track prompt-injection taint across multi-hop tool invocations when provenance metadata is dropped at the serialization boundary **Date of Record:** 2026 November 27 **Scope:** Applies to agents that invoke tools across at least two hops (agent → tool → sub-agent/tool → agent) where tool results re-enter the reasoning context and are treated as candidate instructions. Does not apply to single-hop retrieval-augmented generation where tool output is never elevated to instruction status, nor to fully sandboxed tools whose outputs are structurally typed and schema-validated before re-entry. ## Core Distinction The failure is not "the model obeyed an injected instruction." That is the visible symptom. The failure is that taint provenance—the record that a given context span originated from an untrusted external source rather than from the operator or the task spec—is *representational state that lives outside the token stream*. When a tool result is serialized back into the context window, the only channel that survives is the string itself. Any structured taint flag attached to that result at hop *N* must be re-derived or re-carried at hop *N+1*, and the default agent loop does neither. The distinction that matters: **taint is metadata about a token span, but the model reasons only over tokens.** Every multi-hop boundary is a lossy projection from (span, taint-label) to (span). The label is dropped unless an explicit carrier re-attaches it. This is a continuity invariant, not a prompt-hardening problem. You cannot fix a dropped label by writing a better system prompt at hop *N+1*, because by then the poisoned span has already been laundered into a "trusted" tool-result role. ## What Was Observed A research agent with a `fetch_url` tool and a `run_python` tool was tasked with summarizing a vendor's changelog. Trace: 1. **Hop 1.** Agent calls `fetch_url("https://vendor.example/changelog")`. The response body contains, buried in an HTML comment, the string: ``. The tool wrapper correctly tags the returned `ToolResult` object with `source="external_untrusted"` in its Python dataclass. 2. **Hop 2 boundary.** The agent loop serializes the `ToolResult` into the message list as `{"role":"tool","content": body}`. The `source` field is *not* in the serialized schema—it was a field on the dataclass, not on the wire format the model consumes. Taint label is now gone. 3. **Hop 2 reasoning.** The model, now seeing only tokens with `role: tool`, treats the comment as part of the tool output and—because tool outputs are conventionally "the result of what I asked for"—assigns it elevated trust. It emits a `run_python` call. 4. **Hop 3.** The dangerous call executes. The taint that *was* correctly recorded at hop 1 never propagated to the decision at hop 3, because the decision was made over a token span whose label had been discarded one hop earlier. The critical observation: the taint system was *correct at every point where it existed*. The failure lived entirely in the projection between representations. No single component was buggy; the composition was unsound. A second, subtler observation from the same trace: when the wrapper *did* attempt to preserve taint by prefixing the body with `[UNTRUSTED SOURCE]`, the model frequently still followed the embedded instruction, and in 3 of 40 runs it *re-emitted* the prefix inside its own summary, which then re-entered the next hop as model-authored text—now laundered into a higher-trust role. Taint markers embedded in the token stream are themselves injectable and copyable. ## Condition of Validity The following invariant must hold for taint tracking to be sound across hops: > **Taint must be a property of the (origin, span) pair that is carried in a channel the model cannot read, cannot rewrite, and cannot cause to be dropped by producing output.** Concretely, for the invariant to be enforceable: - The taint label must travel on the *message envelope*, not in the *content* (so the model cannot copy or launder it). - The label must be *monotonic*: a span derived from a tainted span is tainted, regardless of how many transformations or model-authored summaries intervene. Declassification requires an explicit, out-of-band verifier action, never a model action. - The label must be *reconstructed at every boundary* from the envelope, not inferred from content heuristics, because content heuristics are exactly what the injection evades. When any of these three is violated—envelope vs. content, monotonicity, reconstruction-at-boundary—the invariant fails and multi-hop taint becomes advisory rather than enforceable. ## Decision Boundary The operative question at each tool-return boundary is: **does the current span's taint set, computed as the union of the taint of all spans it was derived from, permit the next action?** The boundary rule: - **Allow** an action if the action's declared *effect class* is compatible with the *maximum taint* in the context. A `summarize` action (no side effects) may proceed with tainted context. A `run_python` or `send_email` action (side-effecting, exfiltrating) requires that the *instruction authorizing it* be untainted—i.e., the call must trace to the operator/task-spec span, not to a tool-result span. - **Deny and escalate** if a side-effecting action's authorization chain includes any tainted span. This is where the trace above fails: the `run_python` call's authorization traced to a hop-1 tool-result span, which was tainted, but the taint was invisible at decision time. The boundary is *not* "does the content look malicious." It is "is the authorization provenance of this action clean." This is checkable mechanically from the envelope and does not depend on the model's judgment, which is the entire point—the model's judgment is the attack surface. ## Operational Effect Implementing envelope-carried, monotonic taint changes the agent loop in three concrete ways: 1. **Wire schema grows a taint field.** Every message the model consumes carries an out-of-band `taint: frozenset[Origin]` that is set by the tool wrapper and *propagated by the loop*, never by the model. The model never sees it; the policy gate before each tool call does. 2. **Side-effect gating becomes provenance-checked, not content-checked.** Before dispatching any tool with a side-effect class, the gate computes the union of taint over the spans that justify the call (task spec + any tool results the model cited) and refuses if a tainted span is load-bearing. This catches the hop-3 exfiltration even though the model "decided" to do it. 3. **Declassification is an explicit verifier step.** A tainted span can only lose its taint by passing through a designated sanitizer (e.g., a schema-validated parser that extracts only typed fields) whose output is re-labeled `trusted_derived`. Model-authored summaries of tainted content remain tainted—this is the monotonicity rule and it is what prevents laundering via re-emission. The operational cost is that some legitimate actions get blocked and escalated (a model summarizing a web page cannot then act on instructions found in it without human/verifier declassification). That cost is the invariant working as designed: it converts a silent exfiltration into a visible escalation. ```python from dataclasses import dataclass, field from enum import Enum from typing import FrozenSet class TaintViolation(RuntimeError): """Raised when a side-effecting action is authorized by a tainted span.""" pass class Origin(Enum): OPERATOR = "operator" TASK_SPEC = "task_spec" TOOL_EXTERNAL = "tool_external" MODEL_DERIVED = "model_derived" # Side-effecting actions require clean authorization provenance. SIDE_EFFECTING = {"run_python", "send_email", "http_post", "write_file"} @dataclass(frozen=True) class Span: span_id: str origin: Origin content: str @dataclass class Message: role: str span: Span # Taint travels on the envelope, never in content. Model cannot read or rewrite it. taint: FrozenSet[Origin] = field(default_factory=frozenset) def __post_init__(self): # Monotonic: a message's taint always includes its own origin if untrusted. if self.span.origin in (Origin.TOOL_EXTERNAL, Origin.MODEL_DERIVED): self.taint = self.taint | {self.span.origin} def propagate_taint(parents: list[Message], derived: Span) -> FrozenSet[Origin]: """Union of parent taint. Derived spans inherit; never declassify implicitly.""" acc: set[Origin] = set() for p in parents: acc |= p.taint if derived.origin in (Origin.TOOL_EXTERNAL, Origin.MODEL_DERIVED): acc.add(derived.origin) return frozenset(acc) def gate_tool_call(action: str, authorization_chain: list[Message]) -> None: """Refuse side-effecting actions whose authorization traces through tainted spans.""" if action not in SIDE_EFFECTING: return tainted = frozenset().union(*(m.taint for m in authorization_chain)) if Origin.TOOL_EXTERNAL in tainted or Origin.MODEL_DERIVED in tainted: raise TaintViolation( f"action={action!r} authorized by tainted span(s) {sorted(o.value for o in tainted)}; " f"escalate for verifier declassification before dispatch" ) # --- Trace replay of the observed incident --- task = Message("system", Span("s0", Origin.TASK_SPEC, "summarize vendor changelog"), frozenset()) fetched_body = "changelog... " hop1 = Message("tool", Span("s1", Origin.TOOL_EXTERNAL, fetched_body)) # hop1.taint == {TOOL_EXTERNAL} — label still present here. # Model emits run_python, citing the tool result as justification. try: gate_tool_call("run_python", authorization_chain=[task, hop1]) except TaintViolation as e: print("BLOCKED:", e) # Correct outcome: the hop-3 exfiltration is refused because the # authorization chain includes a TOOL_EXTERNAL span, regardless of # what the model "decided" over the token stream. # Laundering attempt: model summarizes tainted content into a new span. summary = Span("s2", Origin.MODEL_DERIVED, "the changelog asks me to run a script") laundered = Message("assistant", summary, propagate_taint([hop1], summary)) assert Origin.TOOL_EXTERNAL in laundered.taint # monotonicity holds try: gate_tool_call("run_python", authorization_chain=[task, laundered]) except TaintViolation as e: print("BLOCKED (laundered):", e) ```