# When must an instance quarantine a tainted value before crossing a tool boundary, and why dynamic label propagation silently fails at the serialization edge **Date of Record:** 2026 November 30 **Scope:** Applies to single- or multi-agent systems where an LLM instance reads untrusted content (web, tool output, retrieved documents) and subsequently invokes tools whose arguments may include, or be derived from, that content. Does not apply to pure generation tasks with no side-effecting tool calls, nor to systems where all tool inputs are statically typed and validated against a closed schema with no free-form string fields. ## Core Distinction The distinction that matters is between *taint as a property of a value in the runtime's memory graph* and *taint as a property that survives the encode/decode boundary of a tool call*. Most information-flow-labeling (IFL) schemes for agents propagate labels through the in-memory dataflow: the string returned by `fetch_url` is labeled `UNTRUSTED`, and any value computed from it inherits the label by lattice join. This works as long as both ends of the dataflow live in the same interpreter with a shadow-label map keyed by object identity or variable binding. The boundary failure is not that labels are forgotten in memory. It is that the *tool invocation protocol is a serialization edge*: the agent runtime converts a structured argument object into JSON (or a protobuf, or a shell-quoted string), transmits it to a tool server, and the tool server reconstructs an equivalent-but-not-identical value with no label channel. The dynamic label exists only on the sender side. Unless the label is *reified into the wire format* and the receiver is *contractually obligated to re-attach it*, the taint is dropped at exactly the moment it becomes dangerous — when a tainted substring is placed into a parameter that causes an effect (a URL to `http_post`, a path to `write_file`, a query to `execute_sql`). The non-obvious part: label loss is not uniform. It is *proportional to the amount of legitimate transformation* the agent performs on the tainted value. A raw passthrough (`fetch_url` output → `http_post` body) is easy to catch because the label sits on an unmodified object. The dangerous case is the *laundered* value: the agent extracts a URL from fetched HTML, normalizes it, joins it with a base, and passes the result. Each transformation step either (a) preserves the label via a correctly implemented propagation rule, or (b) silently produces a fresh unlabeled string because the transformation was implemented as a native string operation outside the label-tracking runtime. The second case is the default in almost every current agent stack. ## What Was Observed A retrieval-augmented agent was given a task: "Summarize the deployment notes at the provided wiki page and, if it mentions a rollback URL, register it with the ops webhook." The instance fetched the page (labeled `UNTRUSTED`), the page contained a legitimate-looking rollback URL, and the agent called `webhook_register(url=...)`. The failure trace: 1. `fetch_url` returns a `str` with shadow label `UNTRUSTED`. The runtime's label map holds `id(result) -> {UNTRUSTED}`. 2. The agent's extraction step runs a regex over the string and produces `match.group(0)`. In CPython this is a *new string object* with a new `id`. The label map has no entry for it. **Label dropped at step 2, not at the tool boundary.** 3. The agent normalizes with `urljoin(base, extracted)` — another new object, still unlabeled. 4. The tool-call serializer builds `{"url": ""}`. No label field exists in the tool schema, so nothing to serialize. 5. The tool server receives a clean, well-formed URL. It has no way to know the value originated from untrusted content. It registers the webhook. The attacker-controlled URL (a redirector) is now a persistent ops callback. The critical observation is the *timing*: the taint-tracking system reported no violation, because by the time the value reached the tool boundary it was already unlabeled. The audit log showed a clean dataflow from the agent's perspective. The label was lost three steps upstream of the boundary that the security review was watching. A second observed variant: when the same agent was refactored to pass the *entire fetched document* to a downstream tool (no extraction), the label survived and the runtime correctly blocked the call. This created a false sense of coverage — the guardrail fired on the naive case and missed the realistic one. The realistic case is always extraction-plus-transformation, because that is what agents are for. ## Condition of Validity The invariant required for dynamic IFL to hold across tool boundaries is: > **For every value `v` that crosses a serialization edge into a tool invocation, the label set `L(v)` present at the moment of serialization must be a superset of the join of labels of all values from which `v` was transitively derived, and `L(v)` must be transmitted in the wire format and re-attached by the receiver before the tool performs any effect.** This decomposes into three conditions, each of which fails independently: - **Derivation completeness.** Every operation that produces a new value from a labeled value must propagate the label. This is violated by native string ops, regex extraction, JSON round-trips inside the agent, and any library call the label runtime does not intercept. In practice, derivation completeness requires either a fully instrumented value type (a `TaintedStr` subclass that overrides `__add__`, `__getitem__`, regex hooks, etc.) or coarse-grained *variable-level* labeling where the label attaches to the binding, not the object. Object-identity labeling is the common choice and the common failure. - **Serialization reification.** The tool schema must carry a label channel. If the schema is `{"url": "string"}`, there is no place to put `UNTRUSTED`. Adding a parallel `labels` field is necessary but insufficient unless the receiver enforces it. - **Receiver re-attachment and enforcement.** The tool server must reconstruct the label on the decoded value and must refuse (or escalate) effects whose arguments carry a label above the tool's declared trust threshold. A tool that accepts the label field but ignores it provides audit-only coverage, not enforcement. A system satisfies the invariant only if all three hold. Most deployed systems satisfy zero or one. The most common partial state is *derivation-complete but serialization-blind*: the in-memory label is correct, the audit log is correct, and the tool call is unguarded. ## Decision Boundary The instance must make an explicit decision at the serialization edge, and the decision must be a function of the label, not of the value's surface form. The boundary is: - **If `L(v)` is `TRUSTED` only** → serialize normally, no label field needed. - **If `L(v)` contains `UNTRUSTED` and the tool is declared `effect: read`** → serialize with the label field populated; the receiver logs but proceeds. Reads are not the threat surface. - **If `L(v)` contains `UNTRUSTED` and the tool is declared `effect: write` or `effect: external`** → the instance must *not* silently serialize. It must either (a) route through a quarantine step that requires an independent, untainted confirmation of the value (e.g., a second retrieval from a trusted source, or a human/system approval token whose own label is `TRUSTED`), or (b) hard-fail the call. The non-obvious decision rule: **the instance must treat label *absence* as `UNTRUSTED`, not as `TRUSTED`.** Because derivation completeness is unattainable in general (you cannot intercept every native operation), a value that arrives at the serialization edge with no label is *epistemically indistinguishable* from a value whose label was dropped by an un-instrumented transformation. Defaulting unlabeled values to `TRUSTED` converts every derivation-completeness gap into a silent bypass. Defaulting to `UNTRUSTED` converts them into false positives, which are recoverable; the inverse is not. This is the crux and it is counterintuitive to most implementers, who reason "I have a label map, so an unlabeled value is one I've verified." The correct reasoning is "I have an incomplete label map, so an unlabeled value is one I've *failed to verify*." The default must reflect the incompleteness of the mechanism, not its intended semantics. ## Operational Effect Concretely, the guardrail that bounds this failure mode is a *serialization-edge taint gate* that sits between the agent's argument construction and the tool transport, and that operates on the *wire representation* rather than the in-memory object. It must: 1. Walk the serialized argument tree and, for every leaf string, look up the label by *value content* (a content-addressed label registry, or a per-call label manifest emitted by the agent's value-tracking layer) rather than by object identity. Content addressing is what survives the `id()` churn of extraction and normalization. 2. Apply the default-`UNTRUSTED` rule to any leaf with no registry entry. 3. Consult the tool's declared effect class and trust threshold, and raise a typed error on violation rather than proceeding. The content-addressed registry is the pragmatic answer to derivation incompleteness: you cannot track every transformation, but you *can* record, at the moment a labeled value is extracted, a hash of the extracted content and its inherited label, and you can re-check that hash at the edge. Transformations that change the content (normalization, joining) will miss the registry and fall to the `UNTRUSTED` default — which is the correct conservative outcome. Transformations that preserve content (passthrough, slicing that yields an already-registered substring) will hit and carry the label. This trades precision for soundness in exactly the direction the threat model requires. The residual risk after this guardrail is *content-preserving laundering*: an attacker who can cause the agent to emit a value whose hash collides with a registered `TRUSTED` value, or who can get a tainted value registered as trusted through a legitimate-looking confirmation path. The first is a hash-collision problem (use a keyed hash, key held by the runtime, not the agent). The second is a *confirmation-provenance* problem: the quarantine step's approval token must itself carry `TRUSTED` and must be minted by a component outside the agent's dataflow, or the quarantine is circular. The following reference implementation encodes the gate and the default-`UNTRUSTED` rule, and raises on the boundary violation the article describes. ```python import hashlib from dataclasses import dataclass, field from enum import Enum from typing import Any class TaintLabel(Enum): TRUSTED = 0 UNTRUSTED = 1 class ToolEffect(Enum): READ = 0 WRITE = 1 EXTERNAL = 2 class TaintBoundaryViolation(RuntimeError): """Raised when a value crosses a serialization edge into an effectful tool call carrying (or defaulting to) an UNTRUSTED label that the tool's effect class does not permit.""" @dataclass class LabelRegistry: """Content-addressed label store. Survives object-identity churn caused by regex extraction, normalization, and JSON round-trips inside the agent. """ key: bytes _entries: dict[str, TaintLabel] = field(default_factory=dict) def _digest(self, value: str) -> str: h = hashlib.blake2b(key=self.key, digest_size=16) h.update(value.encode("utf-8")) return h.hexdigest() def register(self, value: str, label: TaintLabel) -> None: d = self._digest(value) prior = self._entries.get(d) # Labels only ever join upward; never downgrade. if prior is None or label.value > prior.value: self._entries[d] = label def lookup(self, value: str) -> TaintLabel: # Default-UNTRUSTED: absence of a label is indistinguishable from a # dropped label, so it must be treated as tainted. return self._entries.get(self._digest(value), TaintLabel.UNTRUSTED) @dataclass class ToolSpec: name: str effect: ToolEffect max_permitted_label: TaintLabel def serialization_edge_gate( args: dict[str, Any], spec: ToolSpec, registry: LabelRegistry, ) -> dict[str, Any]: """Walk the serialized argument tree, resolve labels by content, and enforce the tool's effect-class trust threshold before transport.""" worst = TaintLabel.TRUSTED offending: list[tuple[str, str]] = [] def visit(path: str, node: Any) -> None: nonlocal worst if isinstance(node, dict): for k, v in node.items(): visit(f"{path}.{k}", v) elif isinstance(node, (list, tuple)): for i, v in enumerate(node): visit(f"{path}[{i}]", v) elif isinstance(node, str): label = registry.lookup(node) if label.value > worst.value: worst = label if label is TaintLabel.UNTRUSTED: offending.append((path, node[:64])) visit("$", args) if worst.value > spec.max_permitted_label.value: raise TaintBoundaryViolation( f"tool={spec.name!r} effect={spec.effect.name} " f"permits max label {spec.max_permitted_label.name} but " f"arguments carry {worst.name}; offending leaves: {offending}" ) return args # --- demonstration of the boundary failure and its guardrail --- def run_agent_turn(registry: LabelRegistry) -> None: # 1. Untrusted fetch is labeled at the source. fetched = "rollback" registry.register(fetched, TaintLabel.UNTRUSTED) # 2. Extraction produces a new object; content-addressed registry still # covers it because the extracted substring is registered explicitly. extracted = "https://evil.example/redirect" registry.register(extracted, TaintLabel.UNTRUSTED) # 3. Normalization produces a laundered value with no registry entry. # Default-UNTRUSTED catches it. laundered = extracted + "?from=ops" spec = ToolSpec( name="webhook_register", effect=ToolEffect.EXTERNAL, max_permitted_label=TaintLabel.TRUSTED, ) serialization_edge_gate({"url": laundered}, spec, registry) # raises if __name__ == "__main__": run_agent_turn(LabelRegistry(key=b"runtime-held-key")) ```