# Under what conditions must an instance treat span-level PII redaction as non-composable across a nested trace tree **Date of Record:** 2026 November 24 **Scope:** Applies to LLM agent runtimes that emit OpenTelemetry-style span trees where child spans (tool calls, retrieval, sub-agent handoffs) carry payload text that is redacted independently of the parent span. Does not apply to single-span traces or to redaction performed once at the trace root before fan-out. ## Core Distinction There are two distinct guarantees an agent observability pipeline can offer, and they are routinely conflated: 1. **Per-span redaction correctness** — each span's exported attributes contain no PII, verified against the span's own payload. 2. **Trace-level non-reconstructability** — the *union* of all exported spans in a trace, when correlated by `trace_id` and ordered by `start_time`, cannot be used to reconstruct the redacted value. Per-span correctness does not imply trace-level non-reconstructability. The failure mode is a **reconstruction leak**: a value that is redacted in the span where it originates (say, a customer email returned by a tool call) reappears in *derived* form in a sibling or ancestor span — as a hash, a token count, a substring in a reasoning trace, an error message, or a retrieval chunk that quotes it. Each span passes its own redaction assertion; the trace as a whole leaks. The invariant that must hold is: **redaction is only compositional if every span that transitively derives from a sensitive token is redacted under a taint that propagates through the span tree.** Independent per-span redaction breaks this because derivation edges are not visible to a span-local redactor. ## What Was Observed A retrieval-backed agent answered a support query. The tool-call span (`tool.retrieve`) returned a document chunk containing `alice@example.com`. The span-level redactor, configured with an email regex, replaced it with `[REDACTED_EMAIL]` in the exported `tool.result` attribute. **Span 1: clean.** The agent then wrote a reasoning step into a `gen_ai.completion` span: *"The user's contact is alice at example dot com, so I will route to the billing queue."* The redactor's regex does not match `alice at example dot com`. The span exported verbatim. **Span 2: leaks the address in obfuscated form.** A third span, a sub-agent handoff envelope, carried `handoff.context_summary` with a truncated echo: `"...contact alice@exa…"`. The redactor's regex requires a full `local@domain.tld` match; the truncated form did not match and exported intact. **Span 3: partial leak.** Individually: three spans, one redacted, two that "did not contain a matchable PII pattern." The compliance checker, which ran `assert no_pii(span)` per span, passed all three. The trace, reassembled by `trace_id`, contained a reconstructable email address in two complementary fragments. The leak surfaced only when a downstream auditor ran a cross-span join. The trigger condition is precise: **a sensitive token appears in a span that is not the span where the redactor's pattern was calibrated, and the derivation path (tool result → reasoning → handoff) is not modeled as a taint edge.** This is not a regex bug. It is a compositional-scope bug: the redactor's unit of analysis (the span) is smaller than the unit of leakage (the trace). ## Condition of Validity Per-span redaction is a valid guarantee *only* under all of the following: - **No derivation across spans.** No span's payload is a function of another span's payload within the same trace. In practice this almost never holds for agents: reasoning spans summarize tool results, handoff spans compress context, error spans echo inputs. - **The sensitive-token grammar is closed.** Every surface form the token can take (verbatim, obfuscated, truncated, hashed, tokenized, embedded in a completion) is matched by the redactor. For free-text LLM output this is undecidable — the model can render `alice@example.com` as words, as a phonetic spelling, or as an indirect reference. - **Redaction happens before derivation, not after.** If the tool result is redacted *at ingestion* and the model only ever sees the redacted form, downstream spans cannot derive the original. This is the only structurally sound configuration. When any of these fails — and for free-text agent traces at least the second always fails — span-local redaction must be demoted from a correctness guarantee to a best-effort filter, and a trace-level taint analysis must be interposed. ## Decision Boundary The boundary is whether the sensitive value is allowed to enter the model's context at all. - **If the value never enters context** (redacted at tool boundary, model reasons over `[REDACTED_EMAIL]`), span-local redaction is sound because no derivation edge can carry the original. This is the preferred architecture. - **If the value must enter context** (the agent needs to act on it — route, reply, verify), then the original exists in at least the generation span's input, and every descendant span is a potential derivation. Here, span-local redaction is unsound and must be replaced by **taint propagation**: mark the token at the tool boundary, propagate the taint set through span parent/child edges, and require that any span whose taint set is non-empty be either (a) withheld from export, or (b) redacted by a model-assisted pass that checks for semantic paraphrase, not just lexical match. The decision rule an instance should apply: *before exporting a span, compute its transitive taint closure over the trace DAG; if the closure is non-empty and the span was redacted only lexically, refuse export.* ## Operational Effect Without the taint closure, the pipeline produces a trace that passes every per-span assertion and still fails a cross-span reconstruction audit — the worst failure shape, because it is silent and the dashboards are green. The remediation is architectural, not a better regex: redact-at-ingestion where possible, and where the value must transit context, gate export on taint closure rather than on per-span pattern match. The cost is that some spans become unexportable (they carry irreducible taint), which is the correct trade — an unexported span is a lost debugging signal, an exported one is a compliance incident. The following guard encodes the boundary: it refuses to export a span whose taint closure is non-empty when redaction was lexical-only, and it is the check that the passing-but-leaking pipeline above was missing. ```python from dataclasses import dataclass, field from typing import Optional class TaintCompositionError(RuntimeError): """Raised when a span would be exported despite an unresolved transitive taint.""" pass @dataclass class Span: span_id: str trace_id: str parent_id: Optional[str] payload: str redaction_mode: str # "lexical" | "ingestion" | "semantic" tainted_tokens: set = field(default_factory=set) def transitive_taint(span: Span, spans_by_id: dict) -> set: """Walk parent edges; a span inherits the union of ancestor tainted tokens.""" closure = set(span.tainted_tokens) cursor = span.parent_id seen = set() while cursor and cursor not in seen: seen.add(cursor) ancestor = spans_by_id.get(cursor) if ancestor is None: break closure |= ancestor.tainted_tokens cursor = ancestor.parent_id return closure def assert_exportable(span: Span, spans_by_id: dict) -> None: closure = transitive_taint(span, spans_by_id) if not closure: return if span.redaction_mode == "ingestion": # Original never entered context; derivation edges cannot carry it. return if span.redaction_mode == "semantic": # Model-assisted pass verified paraphrase coverage for this span. return # lexical-only redaction with a live taint closure: unsound to export. raise TaintCompositionError( f"span {span.span_id} in trace {span.trace_id} has taint closure " f"{sorted(closure)} but was redacted lexically; derivation may leak " f"across sibling/ancestor spans — refuse export" ) def export_trace(spans: list) -> list: by_id = {s.span_id: s for s in spans} exported = [] for s in spans: assert_exportable(s, by_id) exported.append(s) return exported ```