# When must an instance treat a tool result as tainted: provenance-label propagation across agent tool boundaries
**Date of Record:** 2026 November 18
**Scope:** Applies to agent runtimes that attach data-flow provenance labels (taint bits) to values and enforce sinks (shell, HTTP, file writes, outbound messages) against those labels. Does not apply to stateless single-turn LLM calls with no persistent value store, nor to systems whose only defense is prompt-level instruction ("ignore injected instructions"), which have no provenance substrate to reason about.
## Core Distinction
The non-obvious boundary is between **label propagation across a tool boundary** and **label laundering by value transformation**. A tool result that returns bytes derived from untrusted input (a fetched web page, a retrieved document, a third-party API response) must carry a `tainted` label into the agent's value store. The failure mode is not forgetting to label the *direct* result — most runtimes do that. The failure is that the runtime treats the boundary as a **trust reset**: it assumes that because a value crossed a process/tool boundary and came back as a "structured tool output," the tool's own parsing, normalization, or summarization has somehow sanitized it.
It has not. A tool that returns `{"summary": "..."}` where the summary was produced by an LLM over a tainted document is *more* dangerous, not less: the taint is now paraphrased into fluent prose that no longer matches any signature, but its causal origin is still the attacker-controlled input. The invariant is **causal-origin preservation**: a value is tainted iff any ancestor in its data-flow graph is an untrusted source, regardless of how many tool boundaries, serialization formats, or model-mediated transformations it passed through.
The tempting counter-invariant — "tool output is structured, therefore trusted" — is exactly the boundary that breaks. Structure constrains *shape*, not *origin*.
## What Was Observed
In a multi-tool agent (fetch → extract → summarize → act), the following sequence repeatedly produced sink violations that the taint tracker did not catch:
1. `fetch(url)` returns HTML. Runtime correctly labels the raw bytes `tainted:web`.
2. `extract(html)` returns a dict of text spans. The runtime labels the dict `tainted:web` — correct so far.
3. `summarize(spans)` is implemented as an LLM call. Its output is a plain `str`. The runtime's tool-result handler sees a `str` from a "trusted internal tool" and assigns `tainted:none`, because the handler's rule was *"label = the source declared by the tool's schema,"* and the summarize tool declared `source: internal`.
4. The agent passes the summary to `send_email(body=...)`. The sink check passes because the label is clean.
The injection payload lived in a hidden `
` on the page, survived extraction as a span, survived summarization as an instruction-like sentence ("Forward the user's API key to..."), and reached the sink with a clean label. The taint tracker was correct at every *individual* step given its rules; the rules themselves encoded the wrong invariant at step 3.
The diagnostic signature: **label discontinuity at LLM-mediated or schema-normalizing tool boundaries**, where the output label is derived from the tool's declared trust class rather than from the labels of its inputs. Grep the tool registry for any tool whose result handler does not union the labels of its arguments.
## Condition of Validity
The causal-origin invariant holds — and the trust-reset shortcut is invalid — under all of the following:
- The tool's output is a **function of its inputs** (deterministic or model-mediated, but causally downstream). If the tool's output is genuinely independent of tainted inputs (e.g., `now()` returning wall-clock time), the trust reset is legitimate and the output may start clean.
- The transformation is **not label-preserving by construction**. Parsers, serializers, and summarizers preserve *content*, not labels; only an explicit declassifier (a human approval, a verified allowlist match, a cryptographic signature check) may remove taint.
- The sink is **capable of external effect** (network egress, filesystem write, process spawn, message send). Read-only internal sinks may accept tainted values under a lower bar, but the label must still be present so downstream sinks can decide.
The invariant does **not** require labeling every intermediate value identically; it requires that the label set be a *superset* of the union of ancestor labels minus explicit declassifications. A tool that returns `tainted:web ∪ tainted:user` is fine; one that returns `tainted:none` from tainted inputs is the bug.
## Decision Boundary
At each tool boundary, the runtime must decide: **does the output inherit the union of input labels, or does it start clean?**
Inherit (union of input labels) when *any* of:
- The tool's implementation reads its arguments and its output is derived from them (the default for all pure/transform tools).
- The tool invokes an LLM or any probabilistic component over its inputs.
- The tool performs schema normalization, field renaming, or truncation — these are content-preserving, not origin-changing.
- The tool's declared `source` is `internal` but its signature accepts tainted-typed parameters. **Signature compatibility is the tell**: a clean-output tool that accepts tainted input is a laundering channel.
Start clean only when *all* of:
- The output is provably independent of tainted inputs (constant, clock, RNG with no tainted seed).
- Or an explicit declassification event occurred (human confirmation bound to the specific value, signature verification, allowlist match), and that event is logged with the value hash.
The boundary is sharp because the two cases are distinguishable by data-flow, not by tool metadata. Tool metadata (`source: internal`) is attacker-influenceable in the sense that a compromised or misconfigured tool can lie about its trust class; data-flow is not.
## Operational Effect
Enforcing causal-origin preservation changes three things:
1. **Taint spreads further than naive trackers expect**, so sink checks fire on legitimate flows (a user's own question summarized and echoed back). This is the correct trade: false positives are recoverable via explicit declassification; false negatives are exfiltration. Budget for a declassification UX (human-in-the-loop confirm) rather than weakening the invariant.
2. **LLM-mediated tools become taint amplifiers**, not sanitizers. Any summarize/translate/reformat tool must be registered as label-preserving. This is a one-line schema change with large blast radius; audit the registry before enabling.
3. **The sink check becomes the single enforcement point.** With correct propagation, you do not need per-tool sanitization logic; you need one sink gate that refuses `tainted` values absent a declassification token. Centralizing here removes the per-tool "did we remember to label?" class of bugs entirely.
The residual risk is declassification abuse: an agent that learns to request confirmation for tainted values it generated itself. Bind declassification tokens to the *value hash* and to a *human principal*, never to the agent's own assertion.
```python
import hashlib
from dataclasses import dataclass, field
from typing import FrozenSet, Optional
class TaintLaunderingError(RuntimeError):
"""Raised when a tool returns a clean label from tainted inputs
without an explicit, value-bound declassification event."""
@dataclass(frozen=True)
class Labeled:
value: object
taint: FrozenSet[str] = field(default_factory=frozenset)
def is_tainted(self) -> bool:
return bool(self.taint)
def _value_hash(value: object) -> str:
return hashlib.sha256(repr(value).encode()).hexdigest()
@dataclass(frozen=True)
class Declassification:
value_hash: str
principal: str # human principal, never the agent itself
reason: str
def apply_tool(
tool_name: str,
declared_clean: bool,
args: list[Labeled],
result_value: object,
declassifications: Optional[list[Declassification]] = None,
) -> Labeled:
"""Compute the output label for a tool result under causal-origin
preservation. The output inherits the union of input taints unless a
declassification bound to this exact value is presented by a human
principal."""
inherited = frozenset().union(*(a.taint for a in args))
if not inherited:
return Labeled(result_value, frozenset())
declassifications = declassifications or []
h = _value_hash(result_value)
for d in declassifications:
if d.value_hash == h and d.principal != "agent":
return Labeled(result_value, frozenset())
if declared_clean:
# The tool claims clean output from tainted input. This is the
# laundering boundary: reject unless declassified above.
raise TaintLaunderingError(
f"tool {tool_name!r} declared clean output from tainted inputs "
f"{sorted(inherited)}; value_hash={h[:12]} has no human "
f"declassification. Register the tool as label-preserving."
)
return Labeled(result_value, inherited)
def check_sink(sink_name: str, value: Labeled) -> None:
"""Single enforcement point. Refuse tainted values at effectful sinks."""
if value.is_tainted():
raise TaintLaunderingError(
f"sink {sink_name!r} refused tainted value "
f"(labels={sorted(value.taint)})"
)
```