SysArt
Book a briefing
SysArt

AI security

Prompt Injection Defenses for On-Premises RAG: Hardening Retrieval-Augmented Generation

How to defend on-premises RAG against direct and indirect prompt injection with the OWASP Top 10 for LLM Applications: trust tiers, tool limits and testing.

Last reviewed by SysArt AI Architecture Team5 min readHow we review

In short

Prompt injection happens when text in a user prompt or in retrieved content changes what a language model does. RAG widens the attack surface, because every retrieved document becomes part of the prompt. No filter fully prevents it, so on-premises RAG needs layered defences: trusted sources, marked untrusted content, least-privilege tools, human approval, output checks and adversarial testing.

Key takeaways

  • Prompt injection is LLM01 in the OWASP Top 10 for LLM Applications 2025, and OWASP states that it is unclear whether fool-proof prevention methods exist.
  • In RAG, indirect injection is the main risk: instructions hidden in documents, tickets or web pages reach the model through retrieval.
  • Hosting the model on-premises changes where inference runs, not whether retrieved text can steer it.
  • Design so that a misled model can do little harm: least-privilege tools, authorisation outside the model, approval for high-impact actions, and patterns that keep untrusted data away from tool decisions.
  • Test with poisoned documents in staging, and rerun the tests after every change to models, prompts, embeddings or sources.
Fiber optic and telecommunications equipment in a network equipment rack

Why does RAG change the prompt injection threat model?

Because the retrieved text becomes part of the prompt. OWASP defines prompt injection as user prompts altering a model’s behaviour or output in unintended ways, and lists it first, as LLM01, in its Top 10 for LLM Applications 2025. Direct injection comes from the user’s own input. Indirect injection comes from external content the model reads, such as websites or files, and in a retrieval-augmented generation (RAG) system that means every document in the index. Our explainer on retrieval-augmented generation shows how retrieved passages reach the model.

Greshake and colleagues showed in 2023 that attackers can compromise LLM-integrated applications by planting instructions in data that is likely to be retrieved, and argued that such applications blur the line between data and instructions. The UK National Cyber Security Centre (NCSC) makes a related point: in SQL, parameterised queries keep code and data apart, but a language model has no such separation, so it cannot reliably tell instructions from content.

Is an on-premises model safer against prompt injection?

Only in where inference runs, not in how the model behaves. On-premises hosting keeps prompts and documents inside your boundary and removes exposure to external APIs, but the model reads retrieved text the same way wherever it runs. Internal wikis, support tickets, emails, supplier documents and user uploads can all carry injected instructions from inside the perimeter, and so can poisoned content in the corpus itself.

Retrieval does not solve the problem either. OWASP notes that research shows RAG and fine-tuning do not fully mitigate prompt injection, and that it is unclear whether fool-proof prevention methods exist. The NCSC concluded in December 2025 that prompt injection may never be totally mitigated, so the realistic goal is to reduce its likelihood and impact. Defences therefore have to be layered.

Which OWASP Top 10 risks apply to on-premises RAG?

Prompt injection rarely arrives alone. Six of the ten entries in the 2025 list bear directly on a RAG system:

OWASP 2025 entryHow it shows up in RAGFirst control
LLM01 Prompt InjectionInstructions hidden in retrieved documents steer the answerTrust tiers and marked untrusted content
LLM02 Sensitive Information DisclosureAnswers reveal data the user should not seePermission-aware retrieval and output checks
LLM05 Improper Output HandlingGenerated text or queries run downstream without validationValidate and encode all model output
LLM06 Excessive AgencyAn injected instruction triggers a tool callLeast-privilege tools and human approval
LLM07 System Prompt LeakageSecurity rules placed in the prompt are exposed or bypassedEnforce controls outside the model
LLM08 Vector and Embedding WeaknessesPoisoned or cross-tenant content in the indexSource validation and access-controlled stores

Layer 1: How do you control what retrieval can return?

Reduce what an attacker can get into the context window in the first place.

  • Trust tiers. Separate curated sources, such as approved policies and manuals, from content anyone can write, such as tickets, wiki comments and uploads, and pass the tier on to prompt assembly and downstream rules.
  • Ingestion hygiene. Strip scripts and hidden markup from web captures, normalise encodings, and keep every chunk linked to its source and author.
  • Permission filters. Retrieve only what the user is entitled to see, as described in our post on policy-enforced RAG boundaries.
  • Diversity limits. Stop one document from filling the context with near-duplicate chunks.

Layer 2: How do you separate instructions from untrusted content?

Mark retrieved text clearly as data, and validate the shape of the output in code. OWASP recommends segregating and identifying external content, defining expected output formats and validating them with deterministic code, and filtering inputs and outputs.

Marking has measurable value. Hines and colleagues tested spotlighting, which marks retrieved text through delimiters, datamarking or encoding, and reported that it reduced attack success from above 50% to below 2% in their experiments with GPT-family models, with minimal impact on task performance. Results on other models and attacks may differ. The NCSC adds that marking data helps, that deny-listing known attack phrases does not because attackers can rephrase endlessly, and that products claiming to stop prompt injection deserve scepticism.

Keep system prompts as versioned artefacts rather than strings scattered through services, and constrain outputs to schemas where the task allows, so that deterministic validators can reject anything unexpected.

Layer 3: How do you limit what a misled model can do?

Assume that some injections will succeed, and make them harmless. This is where architecture matters most.

  • Least privilege. OWASP advises limiting the model’s access and handling privileged functions in application code with the application’s own credentials. The NCSC states it as a principle: a model that processes input from an untrusted party should have only that party’s privileges.
  • Human approval for high-risk actions, as OWASP recommends.
  • Outbound checks. Block or alert when an answer contains secrets, internal addresses or links that could carry data out.
  • Design patterns. Beurer-Kellner and colleagues propose six patterns for agents that read untrusted content: action-selector, plan-then-execute, LLM map-reduce, dual LLM, code-then-execute and context-minimisation. Their shared principle is that once an agent has ingested untrusted input, it must be constrained so that the input cannot trigger consequential actions. In plan-then-execute, for example, the agent commits to its sequence of actions before it processes any untrusted data.

The guardrails that enforce these limits are covered in our post on guardrails architecture for on-premises AI agents.

Layer 4: How do you test and monitor injection defences?

Test like an attacker, and repeat the tests whenever the stack changes. OWASP recommends regular penetration tests and attack simulations that treat the model as an untrusted user.

  • Adversarial regression suites in staging: poisoned documents, instructions hidden in tables or metadata, multilingual and obfuscated payloads, and injections in tool outputs. Rerun them after every change to the model, the embedding model, prompts or the corpus. Our post on automated red teaming describes the tooling.
  • Monitoring. The NCSC recommends logging inputs, outputs and tool or API activity so that suspicious behaviour and failed attempts can be detected. Useful signals include spikes in refusals, unusual tool calls, answers dominated by low-trust sources and sudden changes in context length.
  • Ownership. Decide who approves new sources for the index, who may change retrieval settings and who signs off model upgrades, so that no defence erodes through an unreviewed configuration change.

What does an effective defence look like overall?

Defence is cumulative. Private hosting decides where inference runs; RAG-specific controls decide whether retrieved text can hijack behaviour. Treat the corpus as potentially hostile, separate instructions from evidence, keep the model’s privileges small, and prove the posture with repeatable tests. The AI governance checklist helps assign owners for these controls, and our AI security service covers threat modelling and adversarial testing for enterprise RAG and AI agents.

Featured image by Kirill Sh on Unsplash.

Frequently asked questions

What is the difference between direct and indirect prompt injection?

OWASP defines direct prompt injection as a user's own prompt altering the model's behaviour, for example an attempt to override policies or extract the system prompt. Indirect prompt injection arrives through external content the model reads, such as websites or files. In RAG, every retrieved document is a possible carrier, which makes indirect injection the larger risk.

Can prompt injection be fully prevented?

Not with current techniques. The OWASP Top 10 for LLM Applications states that it is unclear whether fool-proof prevention methods exist, and the UK National Cyber Security Centre wrote in December 2025 that prompt injection may never be totally mitigated. The realistic goal is to reduce its likelihood and limit its impact, through architecture as well as filters.

Do delimiters around retrieved text stop prompt injection?

They help but do not guarantee safety. Hines and colleagues reported that spotlighting, which marks retrieved text as data through delimiters or encoding, cut attack success from above 50% to below 2% in their experiments with GPT-family models. The NCSC likewise says that marking data helps while deny-lists of attack phrases do not. Combine marking with least privilege, approvals and testing.

Does running the model on-premises protect against prompt injection?

No. On-premises hosting controls where inference runs and where data goes, but the model reads retrieved text the same way wherever it runs. Internal wikis, tickets, emails and uploaded files can all carry injected instructions from inside the perimeter. Treat every retrieved passage as untrusted input, and design the system so that a misled model can do little harm.

Which design patterns limit prompt injection in RAG agents?

A 2025 paper by Beurer-Kellner and colleagues proposes six: action-selector, plan-then-execute, LLM map-reduce, dual LLM, code-then-execute and context-minimisation. They share one principle: once an agent has ingested untrusted input, constrain it so that the input cannot trigger consequential actions. Each pattern trades some flexibility for security, so match the pattern to the workflow.

Related insights

Plan your private AI with people who build it

Book a briefing. We look at your use case, data and constraints, and you leave with the deployment options and governance steps that fit.