Contaminated by Design: Treating Prompt Injection as an Input Integrity Failure
Photo: Joël van der Loo, CC BY-SA 4.0, via Wikimedia Commons
Prompt injection is often described as a model behavior problem. A hidden instruction appears in a retrieved page, the assistant follows it, and the team adds another sentence to the system prompt. That response treats the symptom. In production NLP systems, injection is more accurately an input integrity failure. The instruction entered through a retrieval result, a tool response, an uploaded file, or a stored memory item. By the time the model sees it, the organization has already lost control of provenance, trust level, and intent. System prompts can reduce some symptoms, but they cannot substitute for pipeline controls.
The Model Is Not the Trust Boundary
A model cannot reliably distinguish between data and instruction when both arrive as text. That is not a prompt engineering defect; it is a consequence of how language models process context. The trust boundary must therefore sit before the model. Every input channel needs a declared trust level, an owner, and a policy for what the model may do with it. Retrieved web content, third-party API responses, customer emails, and agent memory should not share the same implicit authority as an operator-authored instruction. In 2026, mature teams are moving from prompt-level defenses to context assembly controls because the latter can be tested, audited, and versioned.
Provenance Tagging Starts at Ingestion
Provenance tagging should begin when content enters the system, not when it reaches the prompt builder. Each document or message should carry metadata for source, ingestion time, author or system identity, trust tier, retention class, and transformation history. A retrieved passage from an internal policy repository is not equivalent to a snippet from an open web page. A tool response from a billing system is not equivalent to a user-supplied note. The prompt assembler should preserve these tags, and the policy layer should use them to decide what content can influence tool use, memory writes, or final answers. Without provenance, sanitization becomes guesswork.
Retrieval Sanitization Is Not Content Moderation
Sanitizing retrieval results is often confused with filtering offensive or irrelevant text. The harder task is removing instruction-like content that has no business acting as a command. That means normalizing markup, stripping hidden text and metadata, isolating quoted material, and marking external content as untrusted data. It also means limiting how retrieved text can affect control flow. A retrieved document may inform an answer, but it should not be able to request a tool call, alter a recipient list, or write a new memory. Teams should maintain sanitization rules per source class and test them against adversarial documents that mimic ordinary business content.
Tool Permissions Need Explicit Capability Boundaries
Tool calls turn a text problem into an operational one. If a model can send email, issue refunds, query customer records, or modify tickets, then injected text that reaches the model may become an action. The correct control is not a stronger instruction to ignore malicious content. It is a capability boundary. Each tool should have a narrow permission set, an allowlisted parameter schema, and a confirmation rule for high-impact operations. Read and write capabilities should be separated. Tool responses should be treated as untrusted input on return, not as trusted instructions. Audit logs should record which context items influenced each invocation, even if the causal chain is approximate.
Memory Writes Deserve a Policy Engine
Agent memory is a persistence layer, and persistence turns a transient injection into a durable one. A bad instruction that is written into memory can resurface in later sessions, potentially after the original conversation is forgotten. Memory writes should therefore pass through a policy engine with rules for source trust, content type, expiration, and review. Low-trust content should not be promoted to long-term memory without explicit approval. Memory items should retain provenance and be revocable. Teams also need a way to query which memories derived from a given source so that a contaminated document can be traced and removed.
Red-Team Harnesses Should Test Pipelines, Not Prompts
A prompt-only red-team suite misses the actual attack surface. The harness should exercise the full path: ingestion, chunking, retrieval, reranking, prompt assembly, tool invocation, and memory update. Test cases should include indirect injection in PDFs, HTML comments, spreadsheet cells, API error messages, calendar invites, and support tickets. The harness should assert not only that the model refuses a request, but that the pipeline blocks unauthorized tool calls, prevents low-trust memory writes, and preserves provenance in logs. These tests belong in continuous integration, with regression cases added after every incident.
Incident Response for Contaminated Context
When contamination is suspected, the team needs a response plan that is specific to context, not just model output. That plan should identify affected sources, freeze or quarantine retrieval collections, invalidate derived memories, review tool-call logs, and notify data owners. It should also include a customer-impact assessment and a rollback path for prompt or policy changes. Post-incident review should distinguish between detection, containment, and root cause. A system that can answer the question of which inputs reached a decision is far easier to repair than one that can only show the final prompt.
Governance Metrics That Matter
Useful metrics include the percentage of retrieved content with verified provenance, the number of tool calls blocked by capability policy, the rate of memory writes rejected for trust reasons, and the time required to trace an output back to its inputs. These measures reflect pipeline health rather than model politeness. Prompt injection will remain a live risk because language is flexible and attackers are inventive. The defensible position is to treat context as governed data: tagged at entry, sanitized by source, constrained by capability, and auditable at exit.