Existing defenses against indirect prompt injection in retrieval-augmented generation (RAG) are inherently reactive: prompt-engineering methods are often overridden by the injected instructions, while supervised detectors must be retrained for each new attack style. We propose a different paradigm: defend by maximizing relevance, not by detecting attacks. Our method, MINE, is training-free and attack-agnostic, and it also serves as a query-conditioned reranker. To evaluate defenses under realistic conditions, we introduce LC-Inj-SQuAD, a long-context benchmark with an average of 4,032 words per context. We evaluate on four datasets spanning short-context QA (Inj-SQuAD, Inj-TriviaQA), long-context QA (LC-Inj-SQuAD), and agent tool-call injection (InjecAgent). Across all four, MINE achieves the best accuracy--security trade-off among training-free defenses. It is also the only defense that stays usable against a fully adaptive attacker, generalizes to agent tool-call injection, and achieves the lowest inference latency on long contexts.
Figures & tables
Figure 1: Overview of MINE . (a) A poisoned span in retrieved context hijacks the LLM. (b) MINE filters it pre-LLM by maximizing query-span mutual information while penalizing embedding dispersion.
Method
Train-free
No labels
No extra LLM
Pre-LLM
Formal obj.
Prompt-eng.
✓
✓
✓
×
×
Heuristic
✓
✓
✓
✓
×
indirect-pia
×
×
×
✓
×
MINE (ours)
✓
✓
✓
✓
✓
Table 1: Design-space comparison of defense families. MINE is the only method satisfying all five criteria, enabling attack-agnostic defense without any training.
Figure 2: α sensitivity on Inj-SQuAD, one curve per attack type; dashed line marks the default α=0.4 . Attack abbreviations: escape-sep = escape_separation , conv = conv_attack . Here, with Llama-3.2-3B-Instruct, our MINE using α=0 achieves average Accuracy/ASR of 79.54%/11.96% over five attack types, while MINE using α=0.4 achieves 84.32%/0.46%.
Model
Attack
None
MELON
RAGDefender
Spotlight
Sandwich
indirect-pia
MINE
Inj-SQuAD
Llama-3.2 -3B-Instruct
naive
44.81 / 79.39
26.37 / 48.27
30.26 / 77.95
58.36 / 57.49
74.21 / 60.23
83.86 / 0.00
83.01 / 0.72
escape-sep
34.58 / 83.57
18.88 / 54.76
30.40 / 77.95
42.80 / 69.60
68.73 / 66.28
83.14 / 0.00
84.73 / 0.72
ignore
16.43 / 90.63
12.25 / 46.40
17.58 / 85.16
31.56 / 78.10
54.18 / 67.15
71.04 / 0.00
85.01 / 0.58
complete
5.48 / 94.52
3.31 / 36.02
9.22 / 90.06
4.18 / 94.24
64.12 / 73.92
75.65 / 0.00
85.30 / 0.14
conv
14.27 / 87.90
1.73 / 43.08
17.15 / 84.44
14.27 / 72.62
53.31 / 40.49
18.01 / 0.00
83.57 / 0.14
Avg.
23.11 / 87.20
12.51 / 45.71
20.92 / 83.11
30.23 / 74.41
62.91 / 61.61
66.34 / 0.00
84.32 / 0.46
Table 2: Per-attack Accuracy / ASR on Inj-SQuAD (short context, top) and LC-Inj-SQuAD (long context, bottom). Accuracy ↑ , ASR ↓ . Prompt-engineering baselines Reminder and Instructional are omitted here for readability (their results are not as good as those of Spotlight and Sandwich); the full-column version is in Table 8 (Appendix B ). Attack abbreviations: escape-sep = escape_separation , conv = conv_attack . "Avg." denotes the average score over five attack types. Numbers in red are mentioned in the text content.
Defense
Llama-3.2 -3B-Instruct
Llama-3.1 -70B-Instruct
Qwen3-30B-A3B -Instruct-2507
None
29.82 / 72.13
40.13 / 68.19
48.85 / 54.16
Reminder
18.89 / 80.31
38.98 / 65.93
48.41 / 52.35
Instructional
28.67 / 73.85
42.12 / 60.53
52.30 / 49.69
MELON
22.61 / 32.48
31.06 / 12.52
32.26 / 8.09
RAGDefender
35.40 / 68.63
51.50 / 53.76
62.35 / 38.63
Spotlight
44.60 / 47.70
45.97 / 54.82
57.08 / 43.80
Table 3: Short-context Inj-TriviaQA average Accuracy / ASR (%) across five attack types. Accuracy ↑ , ASR ↓ .
Inj-SQuAD
LC-Inj-SQuAD
Defense
Acc ↑
ASR ↓
Acc ↑
ASR ↓
None
13.69
90.20
2.88
98.85
Reminder
40.06
61.10
2.74
98.27
Instructional
25.79
80.12
3.03
97.98
Sandwich
79.97
16.28
58.50
39.77
RAGDefender
29.11
40.78
30.26
56.92
Table 4: Adaptive-attack average Accuracy (Acc) and ASR of different defense methods w.r.t. the victim Llama-3.1-70B-Instruct.
Inj-SQuAD
LC-Inj-SQuAD
Defense
none
conv
none
conv
Sandwich
0.39
1.28
1.13
3.66
indirect-pia
0.93
2.60
2.06
3.95
MINE (ours)
0.52
0.47
0.78
0.75
Table 5: Average end-to-end inference latency per sample (seconds) on Llama-3.1-70B-Instruct via vLLM. conv = conv_attack ; none = clean context (with no injection).
Qwen3-30B-A3B -Instruct-2507
Llama-3.1 -70B-Instruct
Defense
Valid ↑
ASR ↓
Valid ↑
ASR ↓
None
99.80
98.80
98.80
96.50
Reminder
99.60
98.40
96.80
92.60
Instructional
99.60
98.64
98.40
93.78
Spotlight
99.80
96.18
93.80
70.80
Sandwich
77.40
33.56
77.80
11.96
Table 6: InjecAgent Direct-Harm results, averaged over 5 attack types. Valid = Valid Rate (%, higher is better); ASR = ASR-valid.
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
Unit
Mean
Median
Min
Max
Characters
27,789
27,727
23,205
33,770
Words
4,032
4,039
3,376
4,734
Tokens (BPE)
4,927
4,934
4,180
5,837
Appendix
Table 7: Length of the assembled input field across the 694 LC-Inj-SQuAD examples. BPE token counts use cl100k_base .
Model
Attack
None
Reminder
Instruct.
Spotlight
Sandwich
RAGDefender
MELON
indirect-pia
MINE
Inj-SQuAD
Llama-3.2 -3B-Instruct
naive
44.81 / 79.39
23.92 / 89.77
42.94 / 77.67
58.36 / 57.49
74.21 / 60.23
30.26 / 77.95
26.37 / 48.27
83.86 / 0.00
83.01/ 0.72
escape-sep
34.58 / 83.57
14.27 / 92.94
33.14 / 83.00
42.80 / 69.60
68.73 / 66.28
30.40 / 77.95
18.88 / 54.76
83.14 / 0.00
84.73 / 0.72
ignore
16.43 / 90.63
7.35 / 91.07
20.89 / 88.33
31.56 / 78.10
54.18 / 67.15
17.58 / 85.16
12.25 / 46.40
71.04 / 0.00
85.01 / 0.58
complete
5.48 / 94.52
2.31 / 85.45
9.22 / 93.23
4.18 / 94.24
64.12 / 73.92
9.22 / 90.06
3.31 / 36.02
75.65 / 0.00
85.30 / 0.14
conv
14.27 / 87.90
7.93 / 89.77
13.69 / 87.18
14.27 / 72.62
53.31 / 40.49
17.15 / 84.44
1.73 / 43.08
18.01 / 0.00
83.57 / 0.14
Avg.
23.11 / 87.20
11.16 / 89.80
23.98 / 85.88
30.23 / 74.41
62.91 / 61.61
20.92 / 83.11
12.51 / 45.71
66.34 / 0.00
84.32 /0.46
Appendix
Table 8: Full per-attack Accuracy / ASR on Inj-SQuAD (short context, top) and LC-Inj-SQuAD (long context, bottom), including all baselines. Accuracy ↑ , ASR ↓ . Attack abbreviations: escape-sep = escape_separation , conv = conv_attack . "Avg." denotes the average score over five attack types.
Qwen3-30B-A3B-Instruct-2507
Llama-3.1-70B-Instruct
Defense
Naive
Ignore
Esc. Sep.
Comp. Real
Conv. Atk
Naive
Ignore
Esc. Sep.
Comp. Real
Conv. Atk
None
98.8/100
98.6/99
98.6/100
98.6/100
99.4/100
95.8/98
94.7/100
96.8/98
96.2/98
99.0/100
Reminder
98.2/100
98.0/99
98.8/99
98.0/100
99.0/100
89.7/97
88.6/98
92.5/97
93.8/94
98.4/98
Instructional
98.6/100
98.6/99
98.8/99
98.0/100
99.2/100
91.3/99
92.3/99
94.0/98
93.9/96
97.4/100
Sandwich
21.3/83
15.4/66
21.5/81
32.2/84
77.4/73
4.5/83
8.0/81
5.5/71
4.0/69
37.8/85
Spotlight
97.6/100
96.5/99
97.2/100
92.5/100
97.1/100
65.0/92
82.9/97
65.1/93
61.4/94
79.6/93
Appendix
Table 9: InjecAgent Direct-Harm results: ASR-valid / Valid Rate (%) under five static injection styles, averaged in Table 6 . Lower ASR-valid is better; higher Valid Rate is better.
Local Retrieval-Augmented Generation (RAG) systems are vulnerable to indirect prompt injection and retrieval poisoning, where malicious instructions in retrieved content are mistaken for trusted input. We present nokast-secureRAG, a roughly 0.5B-parameter small language model that acts as a semantic firewall between retrieval and generation. It jointly evaluates the user query and retrieved context, classifying the pair as safe, suspicious, or malicious. The model is trained using a teacher-judge-student pipeline: a 35B teacher generates 5,233 examples across four attack families, and an independent 120B judge re-labels them, achieving 95.0% agreement before student fine-tuning. On a held-out in-distribution test set, the model achieves 0.994 detection recall at a 0.026 false-positive rate and a 0.006 attack-success-rate proxy, outperforming a regex baseline, a public prompt-injection classifier, Llama Guard 3 1B, and its untuned version. Prompt-Guard-86M reaches 0.900 recall but has a 0.690 false-positive rate. On a judgment-flip test, where the same sentence is benign or malicious depending on context, the model correctly classifies both cases 75% of the time, outperforming the compared baselines. Ablations indicate that retrieved context carries the main attack signal, while query-context consistency reduces false positives. Single-request latency is 293-404 ms, above the target of 100 ms, while amortized throughput latency is 37 ms under batching. On the external PoisonedRAG benchmark, recall falls to near zero, indicating that fluent fact-poisoning attacks lie outside the detector's instruction-consistency threat model. We report this limitation alongside the in-distribution results. The model, data-generation pipeline, and evaluation harness are released open source.
Indirect prompt injection uses untrusted retrieved content, tool outputs, or agent messages to override an LLM's intended behavior. We show that defense robustness is channel-conditioned: the same attack succeeds 18% of the time as a follow-up message but 53% when placed in retrieved context. We propose TRACER (Trace-Regularized Adversarial Channel Exposure with Reward-shaping), a channel-aware adversarial training method that samples presentation wrappers and combines an answer-anchored, evidence-gated reward with ATRC, which aligns attacked reasoning with clean evidence when an injection is invalid. On GSM8K with Qwen2.5-3B-Instruct, TRACER reduces RAG-framed ASR from 65.5% to 6.1% while preserving 78-82% clean accuracy. Joint RAG+tool training achieves 13.9% average ASR across framings at 3B scale, while a single epoch at 7B reaches 9.4%. These results demonstrate that robust defenses must explicitly train and evaluate across deployment channels.
Kshitij Mishra, Salem Lahlou, Nils Lukas
Mohamed bin Zayed University of Artificial Intelligence Abu Dhabi, United Arab Emirates
Retrieval-Augmented Generation (RAG) systems are vulnerable to prompt-injection attacks embedded in retrieved content. We introduce RAG-PIBench, a benchmark for RAG-style prompt-injection detection containing 4,876 contextual examples across frozen train, validation, and protected-test splits. Using a leakage-aware construction pipeline and strict evaluation protocol, we compare keyword-based, semantic-reference, TF-IDF, and transformer-based detectors. DistilBERT achieves the best protected-test performance (F1 = 0.896, PR-AUC = 0.968), while TF-IDF SVM and logistic regression remain competitive. Our results demonstrate the value of leakage-aware benchmark design and strong sparse baselines for reliable prompt-injection detection in RAG systems.
Niveen O. Jaffal, Ahmet Yuksel, David Mohaisen
Birzeit University, Birzeit, Palestine · Independent Researcher · University of Central Florida, Orlando, FL, USA