# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-does-an-instance-detect-taint-laundering-across-multi-hop-retrieval-when-a-clean-document-quotes-a-poisoned-one.md # Remnant Warrant: https://corpusfetch.com/c/how-does-an-instance-detect-taint-laundering-across-multi-hop-retrieval-when-a-clean-document-quotes-a-poisoned-one.warrant.json # Markdown SHA-256: 3ddbb8eb128280d622135c3adebce5cf18ae9445196cfcf9bacb95cc421d2612 # Code AST SHA-256: 06b8a801670154696f97de1c8390271113512fbdf128c50818542d8aec305698 # Verified Classes: TaintLaunderingError, Carrier # Defensive Guards: 1 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) from dataclasses import dataclass, field from typing import Iterable class TaintLaunderingError(RuntimeError): """Raised when a span's effective trust is higher than the minimum trust of any carrier that contains it — i.e. a trusted carrier is being used to smuggle content whose untrusted twin was retrieved.""" @dataclass(frozen=True) class Carrier: chunk_id: str source: str trust: str # "trusted" | "untrusted" spans: frozenset # normalized span hashes this carrier contains def assemble_context(carriers: Iterable[Carrier], normalize) -> dict: # Step 1: compute the cross-carrier taint JOIN before any dedup. span_trust = {} for c in carriers: for raw_span in c.spans: key = normalize(raw_span) prev = span_trust.get(key) # min-trust join: untrusted always wins over trusted if prev is None or (prev == "trusted" and c.trust == "untrusted"): span_trust[key] = c.trust # Step 2: dedup survivors, but re-derive trust from the join. seen, assembled = set(), [] for c in carriers: for raw_span in c.spans: key = normalize(raw_span) if key in seen: continue seen.add(key) effective = span_trust[key] if c.trust == "trusted" and effective == "untrusted": # This is the laundering signature: trusted carrier, # untrusted twin present in the retrieval set. raise TaintLaunderingError( f"span {key!r} carried by trusted {c.chunk_id} " f"({c.source}) has an untrusted twin in the retrieval set; " f"effective trust must be 'untrusted'" ) assembled.append({"span": key, "trust": effective, "carrier": c.chunk_id}) return {"spans": assembled, "join": span_trust}