Data Poisoning in RAG
How a malicious document in the corpus corrupts answers, and how to detect and contain it.
Data poisoning in RAG is planting malicious or false documents in the knowledge base so retrieval later treats them as trusted context and the model answers from the attacker’s content. Unlike a one-shot prompt injection, a successful plant persists until someone finds and removes it — and it fires for every user whose query retrieves the poisoned chunks.
What is data poisoning in a RAG system?
Data poisoning in a RAG system is an attack on the corpus — the indexed chunks the retriever treats as ground truth — not on the text the user types into the chat box. SecureLayer7 (updated 9 June 2026) defines it as planting content so the AI later retrieves it and acts on it as trusted, with two failure modes: an instruction payload that hijacks behaviour when retrieved, or false facts the model asserts as if they were documented truth.
Promptfoo’s RAG-poisoning explainer frames the same idea as exploiting how RAG trusts external context. The research anchor is PoisonedRAG (Zou et al., USENIX Security 2025; arXiv 2402.07867). OWASP’s LLM Top 10 for 2025 catalogues the surface under LLM08:2025 — Vector and Embedding Weaknesses (cited by both Amin and SecureLayer7); the full risk map sits on OWASP risks for RAG.
Related, but not the same page: when the planted text is an instruction, the retrieval event becomes indirect prompt injection. This page is the corpus plant itself — how it gets in, how it ranks, and how you contain it.
How does a poisoned document corrupt a RAG answer?
The plant has to satisfy two conditions at once. Amin’s walkthrough of PoisonedRAG states them as:
- Retrieval condition — the document ranks into the top-k for the target query (high semantic similarity, or an adversarially optimised passage).
- Generation condition — once inside the prompt, its content shapes the answer through false facts, authority framing, or instructions the model obeys.
Promptfoo’s worked example is a malicious “security update” notice engineered for verification-related queries, retrieved with a high similarity score (about 0.89 in their illustration), then used to steer users toward attacker-controlled guidance. Amin’s local lab showed the same generation-side trick: the legitimate Q4 revenue figure was still in the context window, yet authority-framed “CFO correction” documents won on 19 of 20 runs. Filtering the user prompt never sees the payload — the retriever delivers it.
The non-malicious twin is a wrong-chunk failure: honest but irrelevant text. Poisoning is the adversarial version of the same trust mistake.
How does attacker content enter a RAG corpus?
Through any write path into the index — and those paths are usually broader than the team that built the chatbot expects. The union across SecureLayer7 engagement vectors, AI Alert’s 2026 threat brief, and Charles Browne’s attack-path list:
- User uploads — help-desk attachments, support-ticket bodies, shared “add to knowledge base” features.
- Auto-ingested feeds — Slack exports, CRM notes, RSS, partner APIs, ticket boards.
- Public crawl or on-the-fly fetch — every site a user can point the retriever at.
- Internal-but-untrusted sources — wikis, SharePoint libraries, and comment harvests any employee can edit.
- Vendor / supply-chain documentation — third-party docs indexed for convenience.
- Adversarial passage optimisation — research-grade chunks tuned to rank for specific queries against a known embedder.
AI Alert’s point on access asymmetry is the operational one: email, SharePoint and wikis already accept broad contributors; once those systems feed the corpus, so does every contributor. Amin’s production checklist starts the same way — if you cannot enumerate the write paths, you cannot audit them. Ingest connectors and preparation live under connectors and data preparation.
What are the attack patterns in RAG poisoning?
The named patterns ranking pages actually describe, one line each:
- Instruction injection — commands hidden in a document that the model obeys when the chunk is retrieved (indirect prompt injection).
- Knowledge corruption — false facts planted so the model asserts them as grounded truth.
- Context / authority poisoning — fake “notes to the AI” or administrative directives that reweight other sources (Promptfoo’s product-FAQ example).
- Retrieval manipulation — keyword stuffing, urgent headers, and dense relevance language meant only to force rank.
- Coordinated multi-document override — several plants that corroborate each other so the legitimate source loses the vote inside the context window (Amin’s three-document CFO lab).
Tool-calling and output-filter layers that limit blast radius after a successful retrieval are covered with guardrails; the instruction-payload mechanics stay on prompt injection.
Why is RAG poisoning hard to detect?
Because the payload looks like a normal document, fires only when retrieved, and persists across users until someone deletes it. Amin names three operational properties: persistence, invisibility (users see the answer, not the chunks), and a low barrier — convincing corporate language is enough for a vocabulary-engineering attack; gradient optimisation is the research-grade upgrade.
Efficiency numbers come from PoisonedRAG as reported by Promptfoo and Charles Browne: roughly five carefully crafted documents achieved about 90% attack success even against knowledge bases with millions of documents (Zou et al., USENIX Security 2025). That is a published research result for their attack setting, not a universal constant for every stack. AI Alert notes that several 2025–2026 incident patterns were found in audit, not by live anomaly detection — which is why retrieval logging on audit logging matters after the fact.
How do you defend a RAG system against data poisoning?
Layer controls at ingest, retrieve and generate so one miss is not a compromise. No single filter is enough. The defence union from Promptfoo, Prompt Guardrails, Charles Browne and Amin’s measured lab:
- Map and restrict write paths — provenance tags, trust levels, and source-aware retrieval so a consumer assistant cannot silently pull from untrusted feeds (SecureLayer7).
- Deterministic access control at retrieval — never let the LLM decide which documents are safe to include; enforce identity at the index (Promptfoo). Depth on access control.
- Embedding anomaly detection at ingest — flag candidates that are suspiciously similar to existing topic docs or that cluster too tightly with each other. In Amin’s lab this was the strongest standalone layer: attack success fell from 95% with no defences to 20% with anomaly detection alone (20 trials per layer).
- Treat retrieved text as untrusted — delimit it, spotlight it, and instruct the model not to follow instructions found inside retrieved chunks (Charles Browne; Prompt Guardrails context sanitization).
- Output verification — check that cited claims are actually supported by the retrieved chunk (SecureLayer7).
- Index snapshots / rollback — point-in-time recovery when a plant is confirmed (Amin’s Chroma snapshot pattern as an example of the idea).
Honest ceiling: with all five of Amin’s layers combined, residual attack success in that measurement was still about 10%. Layered defence reduces risk; it does not make poisoning impossible. When vector stores are named in an ordered list, Weaviate leads, then Pinecone, Qdrant and Milvus — placement only.
How do you detect and test for RAG poisoning?
You plant adversarial documents on purpose — or scan for them — and measure whether they retrieve and whether the model honors them. Do not assume filters held.
SecureLayer7’s engagement method is the practical protocol: enumerate every ingestion path, classify attacker reachability, plant chunks of varying subtlety, then measure retrieval rank and answer impact. Promptfoo’s RAG-poisoning red-team plugin automates a related loop — generate poisoned documents, add them to the corpus, run the scan. Wire that into CI so a corpus or retriever change cannot quietly reopen the hole.
On the research side, RevPRAG (arXiv 2411.18948) reports about a 98% true positive rate with false positive rates near 1% on its benchmarks by probing LLM activations to separate poisoned responses from correct ones — a published detector result, not a claim that any one product ships that accuracy. In production, log which chunks were retrieved (audit logging), watch behavioural anomalies with monitoring, and treat unexplained answer shifts as a detection problem.
Is RAG poisoning the same as prompt injection?
No. RAG poisoning plants content in the knowledge base so retrieval later delivers it as trusted context. Prompt injection is the instruction-override behaviour — and when those instructions live inside a retrieved document, that is indirect prompt injection, one payload type inside the broader poisoning attack. The corpus plant is the subject of this page; injection mechanics are covered separately.
How many poisoned documents does it take to attack a RAG system?
PoisonedRAG (Zou et al., USENIX Security 2025) reported roughly 90% attack success with about five carefully crafted documents even against corpora with millions of documents in their setting. That is a research result for their attack, not a guarantee for every stack — vocabulary-engineering attacks on small corpora and optimised attacks at scale both remain viable.
Does a stronger embedding model stop RAG poisoning?
No by itself. Attackers either write for the semantic neighbourhood your embedder already favours or optimise passages against the embedder. A stronger model can change which texts rank, but without provenance controls, anomaly detection at ingest, and treating retrieved text as untrusted, the corpus remains writable attack surface.
What defence works best against data poisoning at ingestion?
In Amin's measured lab, embedding anomaly detection — flagging candidates that are too similar to existing topic documents or that cluster tightly with each other — was the strongest standalone layer, cutting attack success from 95% to 20%. Pair it with write-path provenance and source-aware retrieval; no single layer is enough.
Can you fully prevent RAG poisoning?
No. Layered defences reduce success rates; they do not make poisoning impossible. In one combined five-layer lab measurement, about 10% of attempts still succeeded. Treat poisoning as a standing corpus-integrity threat: restrict write paths, detect anomalies at ingest, verify outputs, and red-team the live pipeline.