Embedding-Based Detection of Indirect Prompt Injection Attacks in Large Language Models Using Semantic Context Analysis
Top Cited Papers
Open Access
- 22 January 2026
- journal article
- research article
- Published by MDPI AG in Algorithms
- Vol. 19 (1) , 92
Abstract
Large Language Models (LLMs) are vulnerable to Indirect Prompt Injection Attacks (IPIAs), where malicious instructions are embedded within external content rather than direct user input. This study presents an embedding-based detection approach that analyses the semantic relationship between user intent and external content, enabling the early identification of IPIAs that conventional defences overlook. We also provide a dataset of 70,000 samples, constructed using 35,000 malicious instances from the Benchmark for Indirect Prompt Injection Attacks (BIPIA) and 35,000 benign instances generated using ChatGPT-4o-mini. Furthermore, we performed a comparative analysis of three embedding models, namely OpenAI text-embedding-3-small, GTE-large, and MiniLM-L6-v2, evaluated in combination with XGBoost, LightGBM, and Random Forest classifiers. The best-performing configuration using OpenAI embeddings with XGBoost achieved an accuracy of 97.7% and an F1-score of 0.977, matching or exceeding the performance of existing IPIA detection methods while offering practical deployment advantages. Unlike prevention-focused approaches that require modifications to the underlying LLM architecture, the proposed method operates as a model-agnostic external detection layer with an average inference time of 0.001 ms per sample. This detection-based approach complements existing prevention mechanisms by providing a lightweight, scalable solution that can be integrated into LLM pipelines without requiring architectural changes.Keywords
This publication has 42 references indexed in Scilit:
- LLMs in Software Security: A Survey of Vulnerability Detection Techniques and InsightsACM Computing Surveys, 2025
- Security concerns for Large Language Models: A surveyJournal of Information Security and Applications, 2025
- Benchmarking and Defending against Indirect Prompt Injection Attacks on Large Language Models2025
- SafeRAG: Benchmarking Security in Retrieval-Augmented Generation of Large Language Model2025
- Adversarial attacks and defenses for large language models (LLMs): methods, frameworks & challengesInternational Journal of Multimedia Information Retrieval, 2024
- A survey on large language model (LLM) security and privacy: The Good, The Bad, and The UglyHigh-Confidence Computing, 2024
- Not What You've Signed Up For: Compromising Real-World LLM-Integrated Applications with Indirect Prompt Injection2023
- SPC: Soft Prompt Construction for Cross Domain Generalization2023
- XGBoost2016
- Random ForestsMachine Learning, 2001