# Where must an instance of taint-aware tool routing enforce the quarantine boundary between untrusted retrieved content and privileged tool invocation **Date of Record:** 2026 November 18 **Scope:** Applies to agent runtimes that retrieve external content (documents, web pages, tool outputs) into context and then select tools whose arguments may be influenced by that content. Does not apply to statically-typed dataflow systems where taint is proven at compile time rather than tracked at runtime. ## Core Distinction The non-obvious boundary is between **taint propagation at retrieval time** and **taint enforcement at invocation time**. Most implementations tag retrieved chunks with a `trusted=False` bit and assume downstream tool selection respects it. The failure is that the taint bit is a property of *context segments*, but tool arguments are assembled from *multiple segments* — and the assembly step (prompt rendering, argument templating, slot filling) is where the invariant silently breaks. An instance must enforce quarantine at the *argument construction* boundary, not at the *retrieval* boundary, because a single untrusted token that reaches an argument slot converts the entire invocation into a tainted call — even if 99% of the context was trusted. ## What Was Observed An agent retrieved a support-ticket document (untrusted), summarized it into a scratchpad, and the summary was later concatenated into a `send_email` tool call's body. The retrieval layer had correctly marked the ticket `trusted=False`. The scratchpad write was a *trusted* tool call. But the scratchpad *read* back into the email body carried the taint forward without any segment-level marker, because the scratchpad was modeled as trusted storage. The email tool executed with attacker-controlled body text. The taint bit existed; the enforcement point did not. Second observation: when quarantine was applied at retrieval, agents became over-refusing — legitimate tasks requiring *reading* untrusted content into a *low-privilege* tool (e.g., a `classify` call with no side effects) were blocked. The boundary is not "untrusted content cannot flow to tools"; it is "untrusted content cannot flow to tools whose *effect class* exceeds the content's trust class." ## Condition of Validity The quarantine invariant holds only if three conditions are simultaneously true: 1. Every context segment carries a provenance tag that survives *all* transformations, including summarization, scratchpad round-trips, and re-embedding. 2. Tool invocations are classified by **effect class** (read-only, reversible-write, irreversible-external) independently of the tool's name or schema. 3. Argument construction is intercepted: the runtime can inspect, per-argument-slot, which provenance tags contributed bytes to that slot. If any condition fails, quarantine is advisory, not enforced. The scratchpad case above fails condition 1; the over-refusal case fails condition 2. ## Decision Boundary The decision is a lattice join, not a boolean. Compute `effect_class(invocation) ⊔ max_trust(contributing_segments)`; permit only if the join is below the policy ceiling. Critically, the join must be computed *after* argument assembly and *before* dispatch, and it must treat any unlabeled segment as maximally untrusted (fail-closed on missing provenance). The boundary that agents most often miss: a tool that *reads* untrusted data and *writes* trusted storage (the scratchpad) is a **taint-laundering** operation and must be modeled as propagating taint into the storage, not as a trust boundary crossing. ## Operational Effect Enforcing at the argument-construction boundary eliminates the scratchpad laundering path and the over-refusal path simultaneously. The cost is that every tool schema must declare per-slot provenance sensitivity, and the runtime must maintain a provenance graph across summarization. Agents that skip the graph and rely on segment-level bits will pass unit tests (single-segment flows) and fail in production (multi-segment assembly). Treat the absence of a provenance edge as an enforcement failure, not a default-allow. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Dict, List class EffectClass(IntEnum): READ_ONLY = 0 REVERSIBLE_WRITE = 1 IRREVERSIBLE_EXTERNAL = 2 class TrustClass(IntEnum): UNTRUSTED = 0 DERIVED = 1 TRUSTED = 2 class QuarantineViolation(RuntimeError): """Raised when an assembled tool invocation exceeds the trust ceiling.""" @dataclass class Segment: seg_id: str trust: TrustClass @dataclass class Invocation: tool: str effect: EffectClass # slot name -> list of segment ids contributing bytes to that slot slot_provenance: Dict[str, List[str]] = field(default_factory=dict) class ProvenanceGraph: def __init__(self) -> None: self._trust: Dict[str, TrustClass] = {} def register(self, seg: Segment) -> None: self._trust[seg.seg_id] = seg.trust def launder(self, dst: str, srcs: List[str]) -> None: # scratchpad write: dst inherits the *minimum* trust of its sources if not srcs: raise QuarantineViolation(f"no provenance edges for {dst}") self._trust[dst] = min(self._trust[s] for s in srcs) def trust_of(self, seg_id: str) -> TrustClass: # fail-closed: unknown segment is maximally untrusted return self._trust.get(seg_id, TrustClass.UNTRUSTED) CEILING = EffectClass.REVERSIBLE_WRITE def enforce(inv: Invocation, graph: ProvenanceGraph) -> None: if not inv.slot_provenance: raise QuarantineViolation(f"{inv.tool}: invocation has no provenance") lowest = TrustClass.TRUSTED for slot, seg_ids in inv.slot_provenance.items(): if not seg_ids: raise QuarantineViolation(f"{inv.tool}: slot {slot} unprovenanced") for sid in seg_ids: lowest = min(lowest, graph.trust_of(sid)) # lattice join: effect escalates with lowest contributing trust if inv.effect == EffectClass.IRREVERSIBLE_EXTERNAL and lowest < TrustClass.TRUSTED: raise QuarantineViolation( f"{inv.tool}: irreversible effect with {lowest.name} content" ) if inv.effect > CEILING and lowest < TrustClass.DERIVED: raise QuarantineViolation( f"{inv.tool}: effect {inv.effect.name} exceeds ceiling for {lowest.name}" ) ```