journal article·2025Open access

Adversarial Prompt Detection in Large Language Models: A Classification-Driven Approach

Ahmet Emre Ergün, Aytuğ Onan

Computers, Materials & Continua· Volume 83· Issue 3

Abstract

Large Language Models (LLMs) have significantly advanced human-computer interaction by improving natural language understanding and generation. However, their vulnerability to adversarial prompts–carefully designed inputs that manipulate model outputs–presents substantial challenges. This paper introduces a classification-based approach to detect adversarial prompts by utilizing both prompt features and prompt response features. Eleven machine learning models were evaluated based on key metrics such as accuracy, precision, recall, and F1-score. The results show that the Convolutional Neural Network–Long Short-Term Memory (CNN-LSTM) cascade model delivers the best performance, especially when using prompt features, achieving an accuracy of over 97% in all adversarial scenarios. Furthermore, the Support Vector Machine (SVM) model performed best with prompt response features, particularly excelling in prompt type classification tasks. Classification results revealed that certain types of adversarial attacks, such as “Word Level” and “Adversarial Prefix”, were particularly difficult to detect, as indicated by their low recall and F1-scores. These findings suggest that more subtle manipulations can evade detection mechanisms. In contrast, attacks like “Sentence Level” and “Adversarial Insertion” were easier to identify, due to the model’s effectiveness in recognizing inserted content. Natural Language Processing (NLP) techniques played a critical role by enabling the extraction of semantic and syntactic features from both prompts and their corresponding responses. These insights highlight the importance of combining traditional and deep learning approaches, along with advanced NLP techniques, to build more reliable adversarial prompt detection systems for LLMs.
Source: openalex_inverted_index · Quality: baseline

Research context

OpenAlex topics: Adversarial Robustness in Machine Learning · Topic Modeling

SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.

References (30)

Show source-provided references
1. Minaee S, Mikolov T, Nikzad N, Chenaghlu M, Socher R, Amatriain X, et al. Large language models: a survey. arXiv:2402.06196. 2024.
2. Rababah B, Wu S, Kwiatkowski M, Leung C, Akcora CG. SoK: prompt hacking of large language models. arXiv:2410.13901. 2024.10.1109/BigData62323.2024.10825103 ↗
3. Prompting Guide AI. Risks of adversarial prompts [Internet]. [cited 2025 Jan 23]. Available from: https://www.promptingguide.ai/risks/adversarial.
4. Fan L, Li L, Ma Z, Lee S, Yu H, Hemphill L. A bibliometric review of large language models research from 2017 to 2023. arXiv:2304.02020. 2024.10.1145/3664930 ↗
5. Weng L. Adversarial attacks on LLMs [Internet]. [cited 2025 Jan 23]. Available from: https://lilianweng.github.io/posts/2023-10-25-adv-attack-llm/.
6. Struppek L, Le MH, Hintersdorf D, Kersting K. Exploring the adversarial capabilities of large language models. arXiv:2402.09132. 2024.
7. Das N, Raff E, Gaur M. Human-readable adversarial prompts: an investigation into LLM vulnerabilities using situational context. arXiv:2412.16359. 2024. doi:10.48550/arXiv.2412.16359.
8. Paulus A, Zharmagambetov A, Guo C, Amos B, Tian Y. AdvPrompter: fast adaptive adversarial prompting for LLMs. arXiv.2404.16873. 2024. doi:10.48550/arXiv.2404.16873.
9. PromptRobust: towards evaluating the robustness of large language models on adversarial prompts
10. Ayub M, Majumdar S. Embedding-based classifiers can detect prompt injection attacks. arXiv:2410.22284. 2024. doi:10.48550/arXiv.2410.22284.
11. Hu Z, Wu G, Mitra S, Zhang R, Sun T, Huang H, et al. Token-level adversarial prompt detection based on perplexity measures and contextual information. arXiv:2311.11509. 2023. doi:10.48550/arXiv.2311.11509.
12. Kumar A, Agarwal C, Srinivas S, Li AJ, Feizi S, Lakkaraju H. Certifying LLM safety against adversarial prompting. arXiv:2309.02705. 2023. doi:10.48550/arXiv.2309.02705.
13. A review on the long short-term memory model10.1007/s10462-020-09838-1 ↗
14. Long short-term memory10.1162/neco.1997.9.8.1735 ↗
15. Convolutional neural networks for sentence classification
16. Backpropagation applied to handwritten zip code recognition10.1162/neco.1989.1.4.541 ↗
17. A hybrid CNN-LSTM model for pre-miRNA classification10.1038/s41598-021-93656-0 ↗
18. Donahue J, Anne Hendricks L, Guadarrama S, Rohrbach M, Venugopalan S, Saenko K, et al. Long-term recurrent convolutional networks for visual recognition and description. arXiv.1411.4389. 2015. doi:10.1109/CVPR.2015.7298878.10.21236/ADA623249 ↗
19. Cho K, Van Merriënboer B, Bahdanau D, Bengio Y. On the properties of neural machine translation: encoder-decoder approaches. arXiv:1409.1259. 2014.10.3115/v1/W14-4012 ↗
20. Learning phrase representations using RNN encoder-decoder for statistical machine translation
21. A decision-theoretic generalization of on-line learning and an application to boosting10.1006/jcss.1997.1504 ↗
22. Experiments with a new boosting algorithm
23. Random forests10.1023/A:1010933404324 ↗
24. XGBoost: a scalable tree boosting system
25. C4.5: programs for machine learning by J. Ross Quinlan. Morgan Kaufmann Publishers, Inc., 1993
26. Breiman · Classification and regression trees · 1984
27. Schölkopf · Learning with kernels: support vector machines, regularization, optimization, and beyond · 200110.7551/mitpress/4175.001.0001 ↗
28. Support-vector networks10.1023/A:1022627411411 ↗
29. Rish · IJCAI-2001 Workshop on Empirical Methods in AI · 2001 · 41
30. Nearest neighbor pattern classification10.1109/TIT.1967.1053964 ↗