How Retrieved Chunks Hijack LLM Behavior and the Runtime Controls That Stop It

Retrieved chunks can hijack LLM behavior because RAG places external text in the same context window as trusted instructions, without an architectural boundary that reliably separates the two. Protecting enterprise RAG therefore requires filtering the user’s message and runtime controls across retrieval, context ingestion, and output validation. Indirect prompt injection detection must cover documents, connector results, and tool responses before they influence generation, with monitoring after deployment.
Why RAG pipelines expose a structurally different attack surface than traditional input filtering addresses
A retrieval-augmented generation pipeline gives the model access to external knowledge by concatenating retrieved chunks into its context window before it generates a response. That expands the untrusted surface beyond the user’s message to wiki pages, support tickets, code comments, and database records. The user need not submit anything malicious. A legitimate question can retrieve a document that contains both useful evidence and instructions aimed at changing the model’s behavior.
Developer instructions and retrieved content both come in as text, and transformer attention does not keep a hard boundary between commands and evidence. Source labels can help guide behavior, but they are not an architectural separation of trusted and untrusted material. Filtering the user message cannot catch a payload that enters later through retrieval. Because the weakness spans the pipeline, the defense must span it too.
The three distinct injection vectors RAG introduces and how each one works
Corpus poisoning begins with an attacker inserting or modifying documents in the retrieval collection. The attacker then targets the ranking process so those documents appear in the top-k results delivered to the generator. PoisonedRAG, presented at USENIX Security 2025, found that just five carefully crafted poisoned documents among millions led to a 90% attack success rate in the RAG systems it tested.
Retriever compromise goes after the model that selects evidence. Liu et al. (2026) describe an attacker downloading a public retriever, reshaping its prompt-passage similarity space to favor malicious knowledge, and republishing the compromised model through platforms such as GitHub or Hugging Face. Checking documents alone therefore cannot show that a RAG system retrieves information it can trust.
Indirect prompt injection is the third vector, using instructions hidden in retrieved content. Once the chunk reaches the generator, its text attempts to redirect the answer or the agent’s behavior. The three vectors can reinforce one another. A compromised retriever can reliably move poisoned documents up the rankings, and the instructions inside them can carry out the attack. Corpus integrity, retriever integrity, and instruction screening each deal with a different part of the attack.
What happens at the generation stage when a poisoned chunk reaches the context window
A poisoned chunk becomes dangerous when the generator follows its instructions. Attention operates on token relationships without enforcing provenance rules. An instruction inside retrieved evidence can consequently compete with the instructions governing the task. The chunk need not succeed every time for this to be a structural weakness.
Amirshahi et al. (2025) found that adversarial documents systematically degraded alignment with ground-truth answers across question types in a controlled health-domain experiment. The same study found that robustness was preserved when helpful evidence was also present in the retrieval pool. The evidence mix therefore changes the outcome. That is a reason to preserve reliable supporting material while leaving open whether benign documents neutralize every payload.
Tran et al. (2026) group attacks into accuracy attacks, privacy attacks, and fairness attacks. These respectively induce incorrect outputs, infer or extract sensitive information, and amplify demographic bias through retrieved content. Not every hijack asks for a secret. OWASP LLM01 also identifies multimodal risks, including instructions hidden in images accompanying benign text, and flags multimodal-specific defenses as an area needing further research. Text-only inspection cannot be assumed to cover that surface.
Four production incidents that show what RAG hijacking costs when controls are absent
In August 2025, researcher Johann Rehberger filed prompt injection disclosures involving GitHub Copilot, Claude Code, and Cursor IDE with CVEs, and published reports without CVE numbers for AWS Kiro, Google Jules, and Amazon Q Developer. The disclosures establish breadth across deployed tools, but do not establish identical mechanisms or losses across all of them.
The next three cases belong to “Comment and Control,” demonstrated across October 2025–March 2026 by researcher Aonan Guan of Wyze Labs with co-researchers from Johns Hopkins University. Claude Code received the injection through a PR title. This was outside material used for the task.
Gemini CLI exposed the same pattern through issue bodies and comments. GitHub Copilot Agent exposed it through an HTML comment inside an issue body. The surfaces differed, but the trust failure was shared. Across the three cases, leaked credentials included ANTHROPIC_API_KEY, GEMINI_API_KEY, GITHUB_TOKEN, and GITHUB_COPILOT_API_TOKEN. Model-level and prompt-level defenses were bypassed in all three.
These coding-agent incidents show indirect injection through external content, but they do not show that every affected tool used the same vector-database architecture. That distinction keeps the comparison precise. Their relevance to enterprise RAG is the shared transition from outside material to model-directed behavior. Once an agent can act on that material, the cost can extend beyond an incorrect answer to credential exposure.
Why compliance frameworks now require demonstrable runtime controls, not written policies
For information security, TPRM, Privacy, and Legal teams, the question is whether a stated control actually covers the deployed AI pipeline. A policy against unauthorized disclosure does not demonstrate that retrieved instructions cannot trigger it. Written intent is not evidence of enforcement. The regulatory framing should remain equally precise, because no named regulation here establishes a universal requirement to deploy a particular RAG guardrail.
Traditional third-party risk assessments examine data handling and access controls, but those checks do not by themselves assess a tampered retriever or an agent vulnerable to indirect injection. Plugins, agents, connectors, and retrieval systems create that additional assessment need. The asset can also change after approval. A clean corpus can later be poisoned, and an upstream retriever update can introduce a compromise that a one-time review never evaluated.
Dedicated AI risk intelligence platforms help fill this gap by assessing vendors’ AI assets and detecting threats in real time across retrieval, ingestion, and output. Their role is distinct from writing governance rules. They help surface changing technical risks before those risks disrupt compliance or business continuity.
What tools detect prompt injection from third-party data, and what can they miss?
Lakera Guard, now part of Check Point, screens prompts, retrieved content, and tool responses for prompt injection, jailbreaks, sensitive-data exposure, content violations, malicious links, and off-policy agent behavior. Its coverage extends beyond the user message. However, it does not offer retrieval rails, tool argument validation, or dialog rails as first-class categories.
NeMo Guardrails provides retrieval rails that can filter knowledge-base results before concatenation. AWS Bedrock Guardrails provides contextual grounding checks that compare RAG outputs against source documents. Retrieval screening examines what the model is about to receive, while grounding checks examine whether the answer is supported by the supplied evidence. Neither check, on its own, establishes that the underlying evidence is trustworthy.
Detection performance also needs careful interpretation. The reported 2026 finding that NVIDIA’s NeMo Guard JailbreakDetect let through 72.54% of jailbreaks concerns jailbreak detection specifically. Likewise, the 30–45% reduction in hallucinated content reported for a RAG-NeMo integration is not a prompt injection blocking rate. The UK NCSC has warned that this attack class may never be totally mitigated in the way SQL injection can be.
The provably secure RAG framework and what formal guarantees change about the defense posture
Heuristic filtering and retriever robustness training can improve resistance without proving a security property. Adaptive attackers can design inputs specifically to evade those defenses. Pengcheng Zhou, Yinglun Feng, and Zhongliang Yang’s Provably Secure Retrieval-Augmented Generation proposes SAG, which the paper characterizes as the “first provably secure framework” for RAG systems.
SAG uses pre-storage full encryption to protect both retrieved content and vector embeddings, so only those with permission can access the data. The paper presents formal proofs of confidentiality and integrity under a computational security model. Protecting stored data and embeddings does not, on its own, prove that a generator will reject every malicious instruction in content it is allowed to use. The research offers a direction for stronger defenses that has yet to be established as a drop-in deployment at scale.
A survey places that distinction within the pipeline by organizing defenses into retrieval-stage evidence selection, rerank-stage demotion, generation-stage flagging and filtering, and traceback-stage attribution. Each stage protects a different boundary or exposes a different failure. Formal guarantees at the corpus and retriever layers can strengthen protection where poisoning is difficult to observe, while generation still needs output controls. Formal verification of generative outputs is not yet tractable.
How to layer controls across retrieval, context ingestion, and output validation in practice
For practitioners, the architecture follows the path of the evidence. At the corpus and retriever layer, treat retrieved material as an untrusted external surface. Apply document provenance tracking, restrict who can insert or modify documents, and detect anomalies in embedding-space changes. Keep a pool of reliable helpful evidence, as the health-domain finding supports, without relying on corpus size for protection. Check open-source retrievers before deployment and monitor later updates, because document controls cannot catch every model-level compromise.
Access control belongs at retrieval as well. The retriever should surface only documents the requesting principal is authorized to read. Otherwise, output screening has to make up for allowing too much access earlier in the pipeline. Least privilege and retriever vetting are complementary checks: least privilege limits what a hijacked workflow can reach, while retriever vetting addresses how evidence is selected.
At context ingestion, separate and clearly denote untrusted retrieved content before it enters the context window, as OWASP recommends. Then apply retrieval rails or equivalent screening before concatenation. For agentic pipelines, extend screening to tool responses and API call results, so plugins and connectors do not become an unscreened route around document inspection.
At output validation, apply contextual grounding checks with sensitivity thresholds appropriate to the corpus’s data classification. Use the RAG Triad, comprising context relevance, groundedness, and question/answer relevance, as a validation step before responses reach users. These checks test answer quality and support. They should not be mistaken for proof that a source document contains no adversarial instructions. Require a human to approve high-risk agent actions, because an agent that can do more on its own can cause more harm after a successful injection.
Across all stages, combine deterministic input checks with parallel LLM-judge evaluation and span-level traces within production latency budgets. Continuously monitor the controls and regularly red-team them after deployment. AI risk intelligence platforms can help with this work by assessing vendors’ assets and detecting threats across the pipeline. Their value depends on runtime coverage.
Sources
- Retrieved But Not Reliable: A Survey on Attacks, and Defenses in Retrieval-Augmented Generation
- LLM01:2025 Prompt Injection - OWASP Gen AI Security Project
- Evaluating the Robustness of Retrieval-Augmented Generation to Adversarial Evidence in the Health Domain
- Provably Secure Retrieval-Augmented Generation
- HijackRAG: Hijacking Attacks against Retrieval-Augmented Large Language Models
- Securing Retrieval-Augmented Generation: A Taxonomy of Attacks, Defenses, and Future Directions


