Ijraset Journal For Research in Applied Science and Engineering Technology
Authors: V. Rudrani, Ch. D V Subba Rao
DOI Link: https://doi.org/10.22214/ijraset.2026.85566
Certificate: View Certificate
Retrieval-Augmented Generation (RAG) enables large language models (LLMs) to answer queries using information obtained from external documents. However, retrieved content may contain concealed commands intended to influence the model\'s behaviour, creating a security risk called indirect prompt injection. This research develops a GAT-based approach to identify harmful instructions in retrieved documents before they reach the language model. Each document is split into individual sentences, which are encoded using a frozen DeBERTa-v3-base model. A graph is constructed from the sentence embeddings, linking adjacent sentences and pairs with a cosine similarity score above 0.7. A two-layer Graph Attention Network (GAT), comprising approximately 0.4 million trainable parameters, processes the graph to classify the document as benign or malicious. The model was evaluated using 10,000 samples collected from financial and corporate policy documents. The dataset contains 6,400 training samples, 1,600 validation samples, and 2,000 testing samples, with equal representation of both classes. Following the addition of calibrated Gaussian noise to the input features, the model obtained 99.80% test accuracy, an F1-score of 0.998, and a Matthews correlation coefficient of 0.996. Its 95% Wilson confidence interval for accuracy ranged from 99.49% to 99.92%. The keyword-based approach recorded an accuracy of 87.93%, but 24.1% of the malicious samples contained none of its specified trigger terms. Its performance on unseen data remains to be established through further experiments involving independently collected datasets, additional application domains, and attack techniques excluded from the original evaluation.
The text presents a Graph Attention Network (GAT)-based method for detecting indirect prompt injection attacks in Retrieval-Augmented Generation (RAG) systems, particularly those used in financial and company-policy applications.
RAG systems retrieve relevant documents and provide them to LLMs to generate answers.
Retrieved documents may contain malicious instructions that manipulate the model. This is known as indirect prompt injection.
Existing security methods mainly focus on filtering user prompts rather than examining retrieved documents.
Keyword-based filters are insufficient because malicious instructions can be written in different ways or hidden within legitimate text.
The study proposes a sentence-level graph-based detection method to identify malicious instructions in retrieved documents.
Its main components are:
Each retrieved passage is divided into individual sentences.
Every sentence is converted into a numerical embedding using a pretrained DeBERTa-v3 model.
Sentences are represented as nodes in a graph.
Edges connect neighbouring sentences and semantically similar sentences.
A two-layer Graph Attention Network (GAT) classifies the passage as either benign or containing indirect prompt injection.
The encoder remains frozen, while only the GAT classifier is trained. The classifier contains approximately 395,782 trainable parameters, making it relatively lightweight.
The study reviews existing research in five main areas:
Indirect prompt injection: Research demonstrates that malicious instructions hidden in external content can manipulate LLM-based applications.
Detection and defence: Existing approaches include embedding-based classifiers, keyword filters, prompt signing, and guardrail models.
RAG knowledge-base attacks: Research shows that poisoned documents can manipulate answers or cause systems to refuse responses.
Graph-based text classification: Graph neural networks can capture relationships between sentences.
Attention mechanisms: GAT attention weights may help interpret relationships between sentences, although their reliability as explanations remains uncertain.
The study identifies a research gap: using sentence-level graphs and GATs specifically to detect malicious instructions in retrieved RAG passages.
The detection process consists of the following steps:
Sentence segmentation: Retrieved passages are divided into sentences using the NLTK Punkt tokenizer.
Sentence embedding: DeBERTa-v3-base generates a 768-dimensional embedding for each sentence.
Graph construction: Each sentence becomes a graph node. Connections are created between adjacent sentences and sentences with cosine similarity greater than 0.7.
Graph classification: A two-layer GAT processes the graph using attention mechanisms.
Prediction: The sentence-level outputs are averaged to classify the entire passage as benign or malicious.
The proposed approach was evaluated using a public Kaggle dataset containing 10,000 records related to financial and company-policy RAG scenarios.
|
Dataset characteristic |
Value |
|---|---|
|
Total records |
10,000 |
|
Benign records |
5,000 |
|
Malicious records |
5,000 |
|
Attack categories |
6 |
|
Training samples |
6,400 |
|
Validation samples |
1,600 |
|
Testing samples |
2,000 |
The six attack categories include:
System-prompt leakage
Policy manipulation
Role hijacking
Security bypass
Instruction override
Sensitive-data extraction
An initial experiment achieved 100% validation accuracy without noise. To make the classification task more challenging, Gaussian noise was added to sentence embeddings.
The noise level was calibrated using an exponential bracketing and bisection procedure. The selected noise multiplier was r=1.0r=1.0, corresponding to a standard deviation of 0.9858.
The proxy model achieved 97.8% validation accuracy at this noise level.
The evaluation considers:
Confusion matrix
Wilson confidence intervals
Matthews Correlation Coefficient (MCC)
Class-wise performance metrics
Training and validation curves
Noise robustness
Comparison with a keyword-based baseline
The study acknowledges several limitations:
The dataset may contain templated or duplicated passages.
Malicious passages tend to be shorter than benign passages, meaning document length may influence classification.
Keyword indicators are present in only 75.9% of malicious records, limiting keyword-based detection.
Adding Gaussian noise artificially controls the difficulty of the classification task.
Graph construction has quadratic computational complexity as the number of sentences increases.
Attention weights cannot automatically be considered reliable explanations.
The method has not yet been compared directly against other trained detection models.
Real-world latency and throughput have not been measured.
This study developed a graph-based approach to identifying indirect prompt injection in retrieval-augmented generation (RAG) systems. Each retrieved passage is divided into sentences, which are encoded using a frozen DeBERTa-v3 model and represented as nodes in a graph. A two-layer graph attention network (GAT), containing approximately 0.4 million trainable parameters, then predicts whether the passage is malicious. Experiments on a balanced dataset of 10,000 records related to finance and corporate policies, with calibrated noise added to the input features, produced a test accuracy of 99.80%, an F1-score of 0.998, and an MCC of 0.996. The model generated three false positives and missed one attack, outperforming a keyword-based method that achieved 87.93% accuracy on the same dataset. Although these findings indicate strong classification performance under the tested conditions, further evaluation is needed to establish the model’s reliability across unfamiliar domains, previously unseen attack patterns, and adversarial scenarios. Future research will focus on evaluating the approach using publicly available and independently collected datasets containing prompt-injection attacks. Additional experiments will compare the proposed model with keyword-based and signing-based defenses, as well as TF-IDF, mean-pooled embeddings, and fine-tuned DeBERTa baselines. We will also investigate the effects of feature noise, removing duplicate records before data splitting, and addressing implementation issues involving pooling masks, feature scaling, and checkpoint selection. Furthermore, storing individual predictions will support a detailed examination of classification errors across different attack categories. Attention weights and SHAP values will be explored to assess the interpretability of the model’s decisions. Finally, inference latency and processing throughput will be measured under realistic retrieval workloads to determine the practical suitability of the approach for deployment.
[1] P. Lewis, E. Perez, A. Piktus, F. Petroni, V. Karpukhin, N. Goyal, et al., “Retrieval-augmented generation for knowledge-intensive NLP tasks,” in Advances in Neural Information Processing Systems (NeurIPS), vol. 33, 2020. [2] K. Greshake, S. Abdelnabi, S. Mishra, C. Endres, T. Holz, and M. Fritz, “Not what you’ve signed up for: Compromising real-world LLM-integrated applications with indirect prompt injection,” in Proc. 16th ACM Workshop on Artificial Intelligence and Security (AISec), 2023. [3] Q. Zhan, Z. Liang, Z. Ying, and D. Kang, “InjecAgent: Benchmarking indirect prompt injections in tool-integrated large language model agents,” in Findings of the Association for Computational Linguistics: ACL 2024, 2024. [4] E. Debenedetti, J. Zhang, M. Balunovi?, L. Beurer-Kellner, M. Fischer, and F. Tramèr, “AgentDojo: A dynamic environment to evaluate prompt injection attacks and defenses for LLM agents,” in Advances in Neural Information Processing Systems (NeurIPS), Datasets and Benchmarks Track, 2024. [5] T. Joshi, V. Naik, I. Mistry, and R. Mangrulkar, “Prevention of prompt injection attacks over financial applications integrated with LLM,” in Proc. 3rd Int. Conf. Advancement in Computation & Computer Technologies (InCACCT), 2025, pp. 225–230, doi: 10.1109/InCACCT65424.2025.11011372. [6] S. Jain and B. C. Wallace, “Attention is not explanation,” in Proc. NAACL-HLT, 2019. [7] S. Wiegreffe and Y. Pinter, “Attention is not not explanation,” in Proc. EMNLP-IJCNLP, 2019. [8] Y. Liu, Y. Jia, R. Geng, J. Jia, and N. Z. Gong, “Formalizing and benchmarking prompt injection attacks and defenses,” in Proc. 33rd USENIX Security Symposium, 2024. [9] H. Zhang, J. Huang, K. Mei, Y. Yao, Z. Wang, C. Zhan, H. Wang, and Y. Zhang, “Agent Security Bench (ASB): Formalizing and benchmarking attacks and defenses in LLM-based agents,” arXiv:2410.02644, 2024. [10] M. A. Ayub and S. Majumdar, “Embedding-based classifiers can detect prompt injection attacks,” arXiv:2410.22284, 2024. [11] H. Li and X. Liu, “InjecGuard: Benchmarking and mitigating over-defense in prompt injection guardrail models,” arXiv:2410.22770, 2024. [12] T. Wen, Y. Liu, Y. Zhang, and Y. Liu, “Defending against indirect prompt injection by instruction detection,” in Findings of the Association for Computational Linguistics: EMNLP 2025, 2025. [13] Y. Liu, Y. Jia, J. Jia, D. Song, and N. Z. Gong, “DataSentinel: A game-theoretic detection of prompt injection attacks,” in Proc. IEEE Symposium on Security and Privacy, 2025. [14] T. Shi et al., “PromptArmor: Simple yet effective prompt injection defenses,” arXiv:2507.15219, 2025. [15] ProtectAI, “deberta-v3-base-prompt-injection-v2,” Hugging Face model card, 2024. [Online]. Available: https://huggingface.co/protectai/deberta-v3-base-prompt-injection-v2 [16] Suo, “Signed-Prompt: A new approach to prevent prompt injection attacks against LLM-integrated applications,” arXiv:2401.07612, 2024. [17] S. Chen, J. Piet, C. Sitawarin, and D. Wagner, “StruQ: Defending against prompt injection with structured queries,” in Proc. 34th USENIX Security Symposium, 2025. [18] W. Zou, R. Geng, B. Wang, and J. Jia, “PoisonedRAG: Knowledge corruption attacks to retrieval-augmented generation of large language models,” in Proc. 34th USENIX Security Symposium, 2025. [19] J. Xue, M. Zheng, Y. Hu, F. Liu, X. Chen, and Q. Lou, “BadRAG: Identifying vulnerabilities in retrieval augmented generation of large language models,” arXiv:2406.00083, 2024. [20] A. Shafran, R. Schuster, and V. Shmatikov, “Machine against the RAG: Jamming retrieval-augmented generation with blocker documents,” in Proc. 34th USENIX Security Symposium, 2025. [21] L. Yao, C. Mao, and Y. Luo, “Graph convolutional networks for text classification,” in Proc. AAAI Conference on Artificial Intelligence, vol. 33, 2019. [22] P. Veli?kovi?, G. Cucurull, A. Casanova, A. Romero, P. Liò, and Y. Bengio, “Graph attention networks,” in Proc. International Conference on Learning Representations (ICLR), 2018. [23] M. Lin, T. Wang, Y. Zhu, X. Li, X. Zhou, and W. Wang, “A heterogeneous directed graph attention network for inductive text classification using multilevel semantic embeddings,” Knowledge-Based Systems, 2024. [24] S. M. Lundberg and S.-I. Lee, “A unified approach to interpreting model predictions,” in Advances in Neural Information Processing Systems (NeurIPS), vol. 30, 2017. [25] T. Kiss and J. Strunk, “Unsupervised multilingual sentence boundary detection,” Computational Linguistics, vol. 32, no. 4, pp. 485–525, 2006. [26] P. He, X. Liu, J. Gao, and W. Chen, “DeBERTa: Decoding-enhanced BERT with disentangled attention,” in Proc. International Conference on Learning Representations (ICLR), 2021. [27] P. He, J. Gao, and W. Chen, “DeBERTaV3: Improving DeBERTa using ELECTRA-style pre-training with gradient-disentangled embedding sharing,” in Proc. International Conference on Learning Representations (ICLR), 2023. [28] M. Fey and J. E. Lenssen, “Fast graph representation learning with PyTorch Geometric,” in ICLR Workshop on Representation Learning on Graphs and Manifolds, 2019. [29] D. P. Kingma and J. Ba, “Adam: A method for stochastic optimization,” in Proc. International Conference on Learning Representations (ICLR), 2015. [30] E. B. Wilson, “Probable inference, the law of succession, and statistical inference,” Journal of the American Statistical Association, vol. 22, no. 158, pp. 209–212, 1927.
Copyright © 2026 V. Rudrani, Ch. D V Subba Rao. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.
Paper Id : IJRASET85566
Publish Date : 2026-11-01
ISSN : 2321-9653
Publisher Name : IJRASET
DOI Link : Click Here
Submit Paper Online
