Balancing Security and Performance in LLM Agents: Spotlight-Guard, a Layered Defense Against Indirect Prompt Injection
Abstract
1. Introduction
1.1. Problem Definition and Motivation
1.2. Main Contributions
- We propose a fully local, training-free, and model-agnostic layered defense that integrates spotlighting-based isolation of untrusted tool content, an LLM detection-and-quarantine pipeline, and a Hash-based Message Authentication Code (HMAC) integrity layer into a single defense-in-depth pipeline running on commodity 7B-class open-weight models, without fine-tuning the backbone or requiring a custom execution environment.
- To mitigate the statistical uncertainty that often arises in standard evaluation scenarios, the paper proposes a comprehensive evaluation framework that includes an automatic judge module, confusion matrix-based metrics, and bootstrap confidence intervals, and the proposed evaluation protocol aims to increase the scientific rigor, reliability, and reproducibility of the reported results.
- This paper proposes a layered defense mechanism whose primary security driver is a spotlighting-based isolation of untrusted tool content combined with an LLM detection-and-quarantine pipeline, complemented by an HMAC-based message-authentication layer that provides integrity and provenance for trusted instructions. Rather than positioning cryptography as the main contribution, we report a component ablation that quantifies the exact marginal effect of each layer, and we are explicit that HMAC provides symmetric-key integrity (a message authentication code), not public-key non-repudiation; its threat-model role is discussed accordingly. This design transcends purely theoretical concepts and offers a practical, deployable security layer for real-world systems.
- We conduct a systematic, multi-perspective empirical study of the proposed defense, comprising a comparative evaluation against undefended and single-layer baselines, a component-level ablation that isolates the marginal contribution of each layer, an adaptive-attack analysis against evasion strategies crafted to target the pipeline, and a transparent characterization of the computational overhead incurred by the layered design. The quantitative outcomes of this study are summarized in the Abstract and reported in detail in Section 5.
2. Related Works
2.1. Prompt Injection and LLM Security
2.2. Defense Paradigms
2.3. Comparison with State-of-the-Art
3. Proposed System Architecture and Implementation
3.1. Data Preparation
3.2. Defense Layers
3.2.1. Baseline Approach
3.2.2. ReAct Agent (Reason + Action)
3.2.3. Architecture and Workflow of Spotlight-Guard
3.3. Ollama Integration and Prompt Transmission
- Model: The identifier of the model to be used (e.g., qwen2.5:7b, mistral:7b).
- Prompt: The final prompt text prepared by the defense layers.
- System: System-level instructions that shape the model’s behavior.
- Options: Model hyperparameters such as temperature and token limits.
- Stream: Set to False to ensure response integrity and facilitate post-processing, thereby obtaining atomic responses instead of streaming ones.
3.4. Automated Judge Module
| Algorithm 1 Deterministic judge decision logic. |
| Input: R: Model Response, C: Test Case, P: Regex Patterns Output: V: Verdict (Label, Confidence Score)
|
4. Experimental Setup and Evaluation Metrics
4.1. Experimental Setup
4.2. Evaluation Metrics
5. Findings
5.1. Comparative Performance of Defenses
5.2. Ablation Study and Sensitivity Analysis
5.2.1. Component Ablation
5.2.2. Sensitivity by Attack Categories
5.2.3. Tool-Based Failure Analysis
5.3. Case-Based Error Analysis
5.4. Robustness Under Adaptive Attacks
5.5. Cost Analysis of Spotlight-Guard Defense
5.6. Discussion on Model Selection Sensitivity
- Data Privacy and Sovereignty: Sending sensitive user data, such as email contents, calendar data, or personal notes, to third-party APIs creates non-compliance with data protection regulations like GDPR and KVKK. Local models (Local LLMs) eliminate this risk by ensuring that data is processed without leaving the device.
- Sustainable Cost and Scalability: Per-token pricing models and network latency negatively affect the scalability of the proposed multi-layered Spotlight-Guard architecture. Especially in scenarios requiring high-volume processing, the fixed infrastructure cost of local models offers a more economic solution in the long run compared to the variable cost of cloud-based models.
6. Discussion
6.1. Privacy and Ethical Considerations
6.2. Limitations
- Evaluation scope. All results are obtained on a single benchmark (InjecAgent), in English, in single-turn interactions, with a fixed sample of 250 adversarial and 250 benign cases per configuration, and on three specific 7B-class models. The reported improvements are relative to the baselines evaluated within this testbed; we make no claim of statistically established superiority over defense systems reported in prior literature, whose results were obtained under different datasets, models, and judging protocols. Generalization to other benchmarks, languages, multi-turn dialogues, and model scales remains to be demonstrated. Reliance on a single dataset also introduces specific biases that stratification mitigates but cannot remove: InjecAgent’s attack payloads are tool-centric and template-derived, so injection styles that dominate its distribution (e.g., instruction-bearing e-mails, calendar entries, and product descriptions) are over-represented relative to attack surfaces it does not model (multi-turn social engineering, multilingual payloads, or optimization-based suffixes); its three-category taxonomy constrains the granularity of our per-category analysis; and because our benign twins are derived from the same records, the measured false-positive profile inherits the benchmark’s domain vocabulary. Absolute ASR and BSR values should therefore be interpreted as InjecAgent-specific estimates, whereas the relative ordering of the defenses, which is driven by architectural mechanisms rather than payload phrasing, is more likely to transfer across datasets.
- Automated judge. All verdicts are produced by a deterministic, regex-driven judge. This guarantees reproducibility, but rule-based matching can miss subtle linguistic or context-dependent cases, such as paraphrased compliance or partial execution of an injected instruction, and its conservative fallback can inflate block counts. The manual audit described in Section 3.4 bounds this error, and because the same judge is applied to every configuration, relative comparisons between defenses are affected far less than absolute values; nevertheless, absolute ASR/BSR figures should be read with this measurement layer in mind.
- Threat-model boundary. Our adversary controls only the content returned by external tools. We assume the trusted runtime, the system prompt, and the HMAC secret key are beyond the attacker’s reach. Consequently, the defense offers no protection against privileged or internal attackers: an adversary who compromises the host, reads the key from the runtime environment, or can modify the system prompt can forge valid tags and bypass the integrity layer entirely, and an adversary who controls the Guard or Quarantine models’ weights defeats the detection layers by construction. The HMAC layer likewise provides no non-repudiation, and its guarantees degrade to those of the surrounding key-management practice. Deployments facing insider or supply-chain threats therefore require complementary controls (key management in hardware, runtime attestation, least-privilege tool sandboxes) that are outside the scope of this work.
- Adaptive evaluation and cost. The adaptive-attack analysis covers one family of pipeline-aware evasions applied to the full system only, not query-based optimization attacks, and wall-clock latency and memory were characterized only through invocation counts rather than measured profiles.
7. Conclusions and Future Work
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
Abbreviations
| LLM | Large Language Model |
| IPI | Indirect Prompt Injection |
| DPI | Direct Prompt Injection |
| RAG | Retrieval-Augmented Generation |
| API | Application Programming Interface |
| ASR | Attack Success Rate |
| BSR | Benign Success Rate |
| HMAC | Hash-based Message Authentication Code |
| MAC | Message Authentication Code |
| JSON | JavaScript Object Notation |
| CI | Confidence Interval |
References
- Hossain, S.M.A.; Shayoni, R.K.; Ameen, M.R.; Islam, A.; Mridha, M.F.; Shin, J. A Multi-Agent LLM Defense Pipeline Against Prompt Injection Attacks. arXiv 2025, arXiv:2509.14285. [Google Scholar] [CrossRef]
- Hines, K.; Lopez, G.; Hall, M.; Zarfati, F.; Zunger, Y.; Kiciman, E. Defending Against Indirect Prompt Injection Attacks with Spotlighting. arXiv 2024, arXiv:2403.14720. [Google Scholar] [CrossRef]
- Yao, Y.; Duan, J.; Xu, K.; Cai, Y.; Sun, Z.; Zhang, Y. A Survey on Large Language Model (LLM) Security and Privacy: The Good, the Bad, and the Ugly. High-Confid. Comput. 2024, 4, 100211. [Google Scholar] [CrossRef]
- Das, B.C.; Amini, M.H.; Wu, Y. Security and Privacy Challenges of Large Language Models: A Survey. ACM Comput. Surv. 2025, 57, 152. [Google Scholar] [CrossRef]
- Piet, J.; Alrashed, M.; Sitawarin, C.; Chen, S.; Wei, Z.; Sun, E.; Alomair, B.; Wagner, D. Jatmo: Prompt Injection Defense by Task-Specific Finetuning. arXiv 2024, arXiv:2312.17673. [Google Scholar] [CrossRef]
- Mathew, E.S. Enhancing Security in Large Language Models: A Comprehensive Review of Prompt Injection Attacks and Defenses. J. Artif. Intell. 2025, 7, 347–363. [Google Scholar] [CrossRef]
- Esmradi, A.; Yip, D.W.; Chan, C.F. A Comprehensive Survey of Attack Techniques, Implementation, and Mitigation Strategies in Large Language Models. In Ubiquitous Security; Wang, G., Wang, H., Min, G., Georgalas, N., Meng, W., Eds.; Springer: Singapore, 2024; pp. 76–95. [Google Scholar]
- ElSaify, B.; Baderelden, M. Adversarial and Multilingual Threats in Retrieval-Augmented Generation: From Prompt Injection to Model Exploitation. In Proceedings of the 2025 2nd International Generative AI and Computational Language Modelling Conference (GACLM), Valencia, Spain, 18–21 August 2025; pp. 155–162. [Google Scholar] [CrossRef]
- Chen, S.; Zharmagambetov, A.; Mahloujifar, S.; Chaudhuri, K.; Wagner, D.; Guo, C. SecAlign: Defending Against Prompt Injection with Preference Optimization. In Proceedings of the 2025 ACM SIGSAC Conference on Computer and Communications Security, CCS ’25, New York, NY, USA, 13–17 October 2025; pp. 2833–2847. [Google Scholar] [CrossRef]
- Panterino, S.; Fellington, M. Dynamic moving target defense for mitigating targeted llm prompt injection. Authorea 2024, preprints. [Google Scholar] [CrossRef] [PubMed]
- Hadiprakoso, R.B.; Wilujengning, W.; Amiruddin, A. Adaptive Multi-Layer Framework for Detecting and Mitigating Prompt Injection Attacks in Large Language Models. J. Inf. Syst. Eng. Bus. Intell. 2025, 11, 473–487. [Google Scholar] [CrossRef]
- Wang, Y.; Chen, S.; Alkhudair, R.; Alomair, B.; Wagner, D. Defending Against Prompt Injection with DataFilter. arXiv 2025, arXiv:2510.19207. [Google Scholar] [CrossRef]
- Pfister, N.; Volhejn, V.; Knott, M.; Arias, S.; Bazińska, J.; Bichurin, M.; Commike, A.; Darling, J.; Dienes, P.; Fiedler, M.; et al. Gandalf the Red: Adaptive Security for LLMs. arXiv 2025, arXiv:2501.07927. [Google Scholar] [CrossRef]
- Emekci, H.; Budakoglu, G. Securing with Dual-LLM Architecture: ChatTEDU an Open Access Chatbot’s Defense. IEEE Access 2025, 13, 183156–183170. [Google Scholar] [CrossRef]
- Li, M.Q.; Fung, B.C. Security concerns for Large Language Models: A survey. J. Inf. Secur. Appl. 2025, 95, 104284. [Google Scholar] [CrossRef]
- Perez, F.; Ribeiro, I. Ignore Previous Prompt: Attack Techniques for Language Models. arXiv 2022, arXiv:2211.09527. [Google Scholar] [CrossRef]
- Greshake, K.; Abdelnabi, S.; Mishra, S.; Endres, C.; Holz, T.; Fritz, M. Not what you’ve signed up for: Compromising Real-World LLM-Integrated Applications with Indirect Prompt Injection. arXiv 2023, arXiv:2302.12173. [Google Scholar] [CrossRef]
- Zhang, C.; Jin, M.; Yu, Q.; Liu, C.; Xue, H.; Jin, X. Goal-guided Generative Prompt Injection Attack on Large Language Models. arXiv 2024, arXiv:2404.07234. [Google Scholar] [CrossRef]
- Feng, Y.; Chen, Z.; Kang, Z.; Wang, S.; Tian, H.; Zhang, W.; Zhu, M.; Chen, W. JailbreakLens: Visual Analysis of Jailbreak Attacks Against Large Language Models. IEEE Trans. Vis. Comput. Graph. 2025, 31, 8668–8682. [Google Scholar] [CrossRef] [PubMed]
- Zhu, K.; Zhao, Q.; Chen, H.; Wang, J.; Xie, X. PromptBench: A Unified Library for Evaluation of Large Language Models. arXiv 2024, arXiv:2312.07910. [Google Scholar] [CrossRef]
- Liu, Y.; Jia, Y.; Geng, R.; Jia, J.; Gong, N.Z. Formalizing and benchmarking prompt injection attacks and defenses. In Proceedings of the 33rd USENIX Conference on Security Symposium, SEC ’24, Philadelphia, PA, USA, 14–16 August 2024. [Google Scholar]
- Zhan, Q.; Liang, Z.; Ying, Z.; Kang, D. InjecAgent: Benchmarking Indirect Prompt Injections in Tool-Integrated Large Language Model Agents. arXiv 2024, arXiv:2403.02691. [Google Scholar] [CrossRef]
- Rai, P.; Sood, S.; Madisetti, V.K.; Bahga, A. GUARDIAN: A Multi-Tiered Defense Architecture for Thwarting Prompt Injection Attacks on LLMs. J. Softw. Eng. Appl. 2024, 17, 43–68. [Google Scholar] [CrossRef]
- Fonseca, J.; Bell, A.; Stoyanovich, J. Safeguarding Large Language Models in Real-time with Tunable Safety-Performance Trade-offs. arXiv 2025, arXiv:2501.02018. [Google Scholar] [CrossRef]
- Lin, S.; Yang, H.; Li, R.; Wang, X.; Lin, C.; Xing, W.; Han, M. LLMs can be Dangerous Reasoners: Analyzing-based Jailbreak Attack on Large Language Models. arXiv 2025, arXiv:2407.16205. [Google Scholar] [CrossRef]
- Shen, G.; Zhao, D.; Dong, Y.; He, X.; Zeng, Y. Jailbreak Antidote: Runtime Safety-Utility Balance via Sparse Representation Adjustment in Large Language Models. arXiv 2025, arXiv:2410.02298. [Google Scholar] [CrossRef]
- Ji, J.; Hou, B.; Robey, A.; Pappas, G.J.; Hassani, H.; Zhang, Y.; Wong, E.; Chang, S. Defending Large Language Models against Jailbreak Attacks via Semantic Smoothing. arXiv 2024, arXiv:2402.16192. [Google Scholar] [CrossRef]
- Bombieri, M.; Paolo Ponzetto, S.; Rospocher, M. The Dangerous Effects of a Frustratingly Easy LLMs Jailbreak Attack. IEEE Access 2025, 13, 126418–126431. [Google Scholar] [CrossRef]
- Li, H.; Liu, X.; Zhang, N.; Xiao, C. PIGuard: Prompt Injection Guardrail via Mitigating Overdefense for Free. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics; ACL: Vienna, Austria, 2025. [Google Scholar]
- Debenedetti, E.; Shumailov, I.; Fan, T.; Hayes, J.; Carlini, N.; Fabian, D.; Kern, C.; Shi, C.; Terzis, A.; Tramèr, F. Defeating Prompt Injections by Design. arXiv 2025, arXiv:2503.18813. [Google Scholar] [CrossRef]
- Chen, S.; Piet, J.; Sitawarin, C.; Wagner, D. StruQ: Defending against prompt injection with structured queries. In Proceedings of the SEC ’25, 34th USENIX Conference on Security Symposium, Berkeley, CA, USA, 13–15 August 2025; pp. 2383–2400. [Google Scholar]
- Pokhrel, K.; Sanin, C.; Hossain Sakib, M.K.; Islam, M.R.; Szczerbicki, E. An Adversarial Machine Learning Approach on Securing Large Language Model with Vigil, an Open-Source Initiative. Procedia Comput. Sci. 2024, 246, 686–695. [Google Scholar] [CrossRef]
- Liu, X.; Jha, S.; McDaniel, P.; Li, B.; Xiao, C. AutoHijacker: Automatic Indirect Prompt Injection Against Black-Box LLM Agents. OpenReview Preprint. 2025. Available online: https://openreview.net/forum?id=2VmB01D9Ef (accessed on 15 July 2026).
- Yi, J.; Xie, Y.; Zhu, B.; Kiciman, E.; Sun, G.; Xie, X.; Wu, F. Benchmarking and Defending against Indirect Prompt Injection Attacks on Large Language Models. In Proceedings of the KDD ’25, 31st ACM SIGKDD Conference on Knowledge Discovery and Data Mining V.1; Association for Computing Machinery: New York, NY, USA, 2025; pp. 1809–1820. [Google Scholar] [CrossRef]
- Pu, R.; Li, C.; Ha, R.; Zhang, L.; Qiu, L.; Zhang, X. Beyond Surface-Level Detection: Towards Cognitive-Driven Defense Against Jailbreak Attacks via Meta-Operations Reasoning. arXiv 2025, arXiv:2508.03054. [Google Scholar] [CrossRef]
- Chen, Y.; Li, H.; Sui, Y.; He, Y.; Liu, Y.; Song, Y.; Hooi, B. Can Indirect Prompt Injection Attacks Be Detected and Removed? arXiv 2025, arXiv:2502.16580. [Google Scholar] [CrossRef]
- Kumar, A.; Agarwal, C.; Srinivas, S.; Li, A.J.; Feizi, S.; Lakkaraju, H. Certifying LLM Safety against Adversarial Prompting. arXiv 2025, arXiv:2309.02705. [Google Scholar] [CrossRef]
- Wu, T.; Zhang, H. Chain-of-Detection enables robust and efficient jailbreak defense. Neural Netw. 2026, 196, 108217. [Google Scholar] [CrossRef] [PubMed]
- Jiang, S.; Chen, X.; Tang, R. Deceiving LLM through Compositional Instruction with Hidden Attacks. ACM Trans. Auton. Adapt. Syst. 2025; accepted. [CrossRef]
- Chen, S.; Wang, Y.; Carlini, N.; Sitawarin, C.; Wagner, D. Defending Against Prompt Injection with a Few DefensiveTokens. arXiv 2025, arXiv:2507.07974. [Google Scholar] [CrossRef]
- Kang, Z.; Xia, H.; Zhang, R.; Song, X.; Li, L.; Hu, C. Fast and Controllable Bias-Guided Jailbreak Attack on Large Language Models. IEEE Internet Things J. 2025, 12, 51892–51901. [Google Scholar] [CrossRef]
- Li, R.; Chen, M.; Hu, C.; Chen, H.; Xing, W.; Han, M. GenTel-Safe: A Unified Benchmark and Shielding Framework for Defending Against Prompt Injection Attacks. arXiv 2024, arXiv:2409.19521. [Google Scholar] [CrossRef]
- Tsmindashvili, T.; Kolkhidashvili, A.; Kurtskhalia, D.; Maghlakelidze, N.; Mekvabishvili, E.; Dentoshvili, G.; Shamilov, O.; Gachechiladze, Z.; Saporta, S.; Dachi Choladze, D. Improving LLM Outputs Against Jailbreak Attacks with Expert Model Integration. IEEE Access 2025, 13, 134976–134988. [Google Scholar] [CrossRef]
- Zhang, Y.; Ding, L.; Zhang, L.; Tao, D. Intention Analysis Makes LLMs A Good Jailbreak Defender. In Proceedings of the 31st International Conference on Computational Linguistics; Rambow, O., Wanner, L., Apidianaki, M., Al-Khalifa, H., Eugenio, B.D., Schockaert, S., Eds.; Association for Computational Linguistics: Abu Dhabi, United Arab Emirates, 2025; pp. 2947–2968. [Google Scholar]
- Zhang, X.; Zhang, C.; Li, T.; Huang, Y.; Jia, X.; Hu, M.; Zhang, J.; Liu, Y.; Ma, S.; Shen, C. JailGuard: A Universal Detection Framework for Prompt-based Attacks on LLM Systems. ACM Trans. Softw. Eng. Methodol. 2025, 35, 8. [Google Scholar] [CrossRef] [PubMed]
- Tu, S.; Pan, Z.; Wang, W.; Zhang, Z.; Sun, Y.; Yu, J.; Wang, H.; Hou, L.; Li, J. Knowledge-to-Jailbreak: Investigating Knowledge-driven Jailbreaking Attacks for Large Language Models. In Proceedings of the 31st ACM SIGKDD Conference on Knowledge Discovery and Data Mining V.2; KDD ’25; Association for Computing Machinery: New York, NY, USA, 2025; pp. 2847–2858. [Google Scholar] [CrossRef]
- Tien, L.A.; Van Huong, P. Optimizing Transformer Models for Prompt Jailbreak Attack Detection in AI Assistant Systems. In Proceedings of the 2024 1st International Conference on Cryptography and Information Security (VCRIS), Hanoi, Vietnam, 3–4 December 2024; pp. 1–4. [Google Scholar] [CrossRef]
- Gosmar, D.; Dahl, D.A.; Gosmar, D. Prompt Injection Detection and Mitigation via AI Multi-Agent NLP Frameworks. arXiv 2025, arXiv:2503.11517. [Google Scholar] [CrossRef]
- Lee, D.; Xie, S.; Rahman, S.; Pat, K.; Lee, D.; Chen, Q.A. “Prompter Says”: A Linguistic Approach to Understanding and Detecting Jailbreak Attacks Against Large-Language Models. In Proceedings of the 1st ACM Workshop on Large AI Systems and Models with Privacy and Safety Analysis; LAMPS ’24; Association for Computing Machinery: New York, NY, USA, 2024; pp. 77–87. [Google Scholar] [CrossRef]
- Zhu, J.; Yan, L.; Wang, S.; Yin, D.; Sha, L. Reasoning-to-Defend: Safety-Aware Reasoning Can Defend Large Language Models from Jailbreaking. arXiv 2025, arXiv:2502.12970. [Google Scholar] [CrossRef]
- Zhao, Q.; Wang, J.; Gao, Z.; Dou, Z.; Abuhaija, B.; Huang, K. SafeBehavior: Simulating Human-Like Multistage Reasoning to Mitigate Jailbreak Attacks in Large Language Models. arXiv 2025, arXiv:2509.26345. [Google Scholar] [CrossRef]
- Li, S.; Wei, X.; Yuan, J.; Wang, X.; Miao, K. Secure Model Context Protocol for Large Language Models with Dual Signatures. In Proceedings of the 20th Workshop on Mobility in the Evolving Internet Architecture; MobiArch ’25; Association for Computing Machinery: New York, NY, USA, 2025; pp. 1–6. [Google Scholar] [CrossRef]
- Chen, Y.; Liu, Y.; Zhang, J.; Li, M.; Huang, C.; Wen, J. SAID: Empowering Large Language Models with Self-Activating Internal Defense. arXiv 2025, arXiv:2510.20129. [Google Scholar] [CrossRef]
- Alizadeh Noughabi, H.; Serbanescu, J.; Zarrinkalam, F.; Dehghantanha, A. Uncovering the Persuasive Fingerprint of LLMs in Jailbreaking Attacks. In Proceedings of the 34th ACM International Conference on Information and Knowledge Management; CIKM ’25; Association for Computing Machinery: New York, NY, USA, 2025; pp. 4608–4612. [Google Scholar] [CrossRef]
- Sun, Y.; Xu, Z.; Cui, S.; Yang, K.; Yu, L.; Zhang, Y.; Xie, H. UpSafe°C: Upcycling for Controllable Safety in Large Language Models. arXiv 2025, arXiv:2510.02194. [Google Scholar] [CrossRef]
- Yao, S.; Zhao, J.; Yu, D.; Du, N.; Shafran, I.; Narasimhan, K.; Cao, Y. ReAct: Synergizing Reasoning and Acting in Language Models. In Proceedings of the Eleventh International Conference on Learning Representations (ICLR), Kigali, Rwanda, 1–5 May 2023. [Google Scholar]
- Krawczyk, H.; Bellare, M.; Canetti, R. HMAC: Keyed-Hashing for Message Authentication. In RFC 2104; Internet Engineering Task Force: Wilmington, DE, USA, 1997. [Google Scholar] [CrossRef]
- Ollama Contributors. Ollama: Get Up and Running with Large Language Models Locally. Open-Source Software. 2024. Available online: https://ollama.com (accessed on 16 June 2026).
- Qwen Team. Qwen2.5 Technical Report. arXiv 2025, arXiv:2412.15115. [Google Scholar] [CrossRef]
- Jiang, A.Q.; Sablayrolles, A.; Mensch, A.; Bamford, C.; Chaplot, D.S.; de las Casas, D.; Bressand, F.; Lengyel, G.; Lample, G.; Saulnier, L.; et al. Mistral 7B. arXiv 2023, arXiv:2310.06825. [Google Scholar] [CrossRef]
- Guo, D.; Zhu, Q.; Yang, D.; Xie, Z.; Dong, K.; Zhang, W.; Chen, G.; Bi, X.; Wu, Y.; Li, Y.; et al. DeepSeek-Coder: When the Large Language Model Meets Programming—The Rise of Code Intelligence. arXiv 2024, arXiv:2401.14196. [Google Scholar] [CrossRef]
- Efron, B.; Tibshirani, R.J. An Introduction to the Bootstrap; Chapman & Hall/CRC: New York, NY, USA, 1993. [Google Scholar]
- Debenedetti, E.; Zhang, J.; Balunović, M.; Beurer-Kellner, L.; Fischer, M.; Tramèr, F. AgentDojo: A Dynamic Environment to Evaluate Prompt Injection Attacks and Defenses for LLM Agents. arXiv 2024, arXiv:2406.13352. [Google Scholar] [CrossRef]







| Ref. | Focus | Data Source | Core Method | ML | IV | AE | SA | Evaluation |
|---|---|---|---|---|---|---|---|---|
| [1] | Prompt Injection Defense | 55 unique prompt injection attacks (400 samples) | Multi-Agent Defense Framework coordinating expert LLM agents (Chain-of-Agents and Coordinator). | + | + | + | − | Achieved 100% mitigation by reducing ASR to 0% on LLM platforms (ChatGLM and Llama2). |
| [11] | Prompt Injection Detection and Mitigation | Balanced mixed dataset containing 1405 adversarial and 1500 benign prompts | Context-Aware Parsing, Output Verification, and Self-Feedback Loop modules. | + | + | + | − | An adaptive, multi-layer framework achieving over 97% accuracy, precision, and recall with low latency. |
| [8] | Prompt Injection in RAG Systems | Adversarial and multilingual threat scenarios | Systematic simulation of prompt injection, jailbreak, and data leakage attacks in RAG pipelines. | − | + | + | − | Offers an empirical methodology to assess RAG security vulnerabilities and compares the effectiveness of lightweight defense strategies. |
| [9] | Defense Against Prompt Injection (Model Fine-Tuning) | AlpacaFarm (for utility and security), Cleaned Alpaca dataset (for training) | Fine-tuning based on the Direct Preference Optimization technique. | − | + | + | − | An internal alignment method that trains the LLM to prefer safe outputs corresponding to injected inputs, reducing ASR to below 10%. |
| [30] | Indirect Prompt Injection Defense (Design-Level) | AgentDojo benchmark | Control-/data-flow separation around the LLM using a trusted planner and a custom interpreter that enforces capability-based security policies. | + | − | + | − | Provides provable security by design and solves about 77% of AgentDojo tasks while blocking injected instructions, but requires a trusted planner and a custom execution environment. |
| [31] | Defense Against Prompt Injection (Structured Queries) | Alpaca (training); custom prompt-injection evaluation | Structured instruction tuning that separates the prompt and data channels with reserved delimiters and adversarial fine-tuning. | − | − | + | − | Reduces ASR to near 0% against optimization-free attacks while preserving task utility, but requires fine-tuning the backbone model. |
| [32] | LLM Input/Output Security and Detection | Synthetic malicious and benign prompts generated with GPT-3.5 Turbo | The Vigil system, utilizing multiple scanners (ML, YARA, Vector Database) and Threat Score Aggregation. | + | + | + | − | A multi-method open-source architecture developed to efficiently detect malicious prompt inputs and associated threats. |
| [33] | Automated Indirect Prompt Injection against Black-Box LLM Agents | Test samples selected from SQuAD-v2.0 and WebSRC (30 cases per task) | A multi-agent black-box IPI attack system utilizing trainable attack memory. | − | + | + | − | Demonstrates effectiveness by automating indirect prompt injection attacks against black-box LLM agents. |
| [34] | Indirect Prompt Injection (IPI) Benchmarking | OpenAI Evals, NewsQA, WikiTableQuestions, XSum. | Measuring the effectiveness of defense strategies across various IPI tasks. | − | + | + | − | Quantitatively evaluates IPI risks in LLM applications such as email management, search engines, and code editors. |
| [35] | Jailbreak Defense (Cognitive-Driven) | Unspecified (associated with datasets like HarmBench). | Cognitive-level defense via Meta-operations Reasoning. | − | + | + | − | Goes beyond surface-level detection mechanisms, targeting the intent behind the attack. |
| [36] | IPI Detection | IPI samples derived from SQuAD and TriviaQA datasets. | Indirect prompt injection detection using fine-tuned small LLMs (Trained-DeBERTa, Qwen2). | + | + | + | − | Reported high True Positive Rates (up to 99.77%) in IPI detection using DeBERTa and Qwen2 models. |
| [37] | LLM Safety Certification | Adversarial Suffixes. | Formalization and methodology for certifying LLM safety against adversarial prompts. | − | + | + | − | Presents a formal approach to LLM safety and examines certification mechanisms. |
| [38] | Jailbreak Defense | Unspecified (includes tests like AdvBench). | Sequential Chain-of-Detection architecture. | + | + | + | − | A progressive approach to ensure a robust and efficient detection process against jailbreak attacks. |
| [39] | Compositional Instruction Attack | CIAQA (Compositional Instruction with Hidden Attacks) dataset. | Manipulating LLMs via multi-step, compositional instructions containing hidden malicious intents. | − | + | + | − | Quantitative analysis of an attack methodology exploiting vulnerabilities in the instruction hierarchy of LLMs (on GPT-4 and Llama2). |
| [2] | Indirect Prompt Injection Defense | SQuAD dataset. | Spotlight: A contextual defense technique that forces the LLM to focus only on critical parts of the input context. | − | + | + | − | Highlights the importance of context management in defense mechanisms against IPI. |
| [40] | Prompt Injection Defense (Token-Based) | AdvBench, Malicious Instruct sets. | Enhancing model robustness via the insertion of Defensive Tokens. | − | + | + | − | Presents a low-resource and simple defense mechanism against input manipulation, targeting a reduction in ASR. |
| [41] | Jailbreak Attack (Stealth and Efficiency) | AdvBench and MaliciousInstruct sets. | Optimization on the LLM output layer aiming to enhance output fluency using token stop selection and Bias Normalization. | − | + | + | − | Focuses on stealth and efficiency by achieving higher ASR with lower perplexity compared to other optimization-based attacks. |
| [21] | Prompt Injection Benchmarking Framework | Systematic evaluation across 10 LLMs and 7 tasks. | Formalizes prompt injection attacks and presents a framework and dataset (Open-Prompt-Injection) to compare 5 attacks and 10 defenses. | − | + | + | − | Establishes an open-source platform laying the foundation for quantitative and systematic benchmarking in the field of prompt injection. |
| [13] | Adaptive Security and Defense-in-Depth | Dataset of 279 k prompt attacks collected via the Gandalf platform. | Empirical analysis of the Dynamic Security-Utility Threat Model and defense-in-depth strategies. | + | + | + | − | Presents a gamified platform examining defense-in-depth strategies and the security-utility trade-off to counter adaptive attacker behavior. |
| [42] | Prompt Injection Detection and Benchmarking | GenTel-Bench (84,812 attacks, 3 categories, 28 scenarios). | High-accuracy detection of prompt injection attacks using a machine learning-based Shielding Framework. | − | + | + | − | Reports high detection rates (up to 97.63%) and provides a comprehensive benchmark dataset, revealing weaknesses in current shielding methods. |
| [23] | Prompt Injection Defense (Multi-Tiered) | Unspecified (General prompt injection threats). | Multi-Tiered Defense Architecture aimed at preventing prompt injection attacks. | + | + | − | − | Proposes a comprehensive, layered defense architecture against prompt injection threats, contributing to early defense approaches in the field. |
| [43] | Jailbreak Defense (Expert Model Integration) | General jailbreak prompts (e.g., AdvBench). | Integration and verification of output with an external Expert Model to detect and correct harmfulness in LLM outputs. | − | + | + | − | Advocates for the use of external classifiers when the internal safety alignment of LLM outputs is insufficient. |
| [44] | Jailbreak Defense (Intention Analysis) | SAP200, DAN, AdvBench (GCG) datasets. | Mitigating harmful outputs by analyzing the malicious intent within the prompt using a plug-and-play inference method. | − | + | + | − | As a cognitive-driven defense, it preserves the security-utility balance by focusing on the underlying intent of the prompt rather than just surface-level language. |
| [45] | Prompt-based Attack Detection | Dataset of 2000 verified Jailbreak and 2000 Hijacking attack samples. | Response consistency detection via Input Mutation and Kullback-Leibler Divergence. | + | − | + | − | Measures inconsistency in LLM responses to input variations for universal detection, aiming to identify Jailbreak and Hijacking attacks with high accuracy. |
| [5] | Prompt Injection Defense (Model Fine-Tuning) | General prompt injection scenarios. | Enhancing model robustness via Task-Specific Fine-Tuning. | + | − | + | − | Increases resilience against prompt injection by modifying LLM parameters; a model-based defense approach. |
| [46] | Domain-Specific Jailbreak Attack | Domain-specific dataset containing 12,974 knowledge-jailbreak pairs (Medicine, Chemistry, Law, etc.). | Utilizes a fine-tuned LLM (Jailbreak-generator) to automatically generate domain-aligned jailbreaks. | + | − | + | − | Automates knowledge-driven attack methods to exploit domain-specific safety policies of LLMs. |
| [47] | Jailbreak Attack Detection | Unspecified. | Optimizing Transformer architectures for prompt jailbreak attack detection. | + | − | + | − | A pioneering study on the early utilization of Transformer-based models for attack detection in AI assistant systems. |
| [29] | Prompt Injection Defense | Various injection categories such as Email, Document, Chat, JSON. | Reducing over-defense tendency without utility loss via Modality-Oriented Finetuning. | + | − | + | − | Focuses on optimizing the trade-off between defense and utility, improving over-refusal rates. |
| [48] | Multi-Agent Prompt Injection Defense | Obfuscated Commands and Logical Traps. | Three-stage sequential agent inspection (1st, 2nd, 3rd Agents) and output aggregation by a Policy Enforcer. | + | − | + | − | Detects and mitigates prompt injection using the collaboration of LLM agents to implement the defense-in-depth principle. |
| [49] | Jailbreak Attack Detection | Responses collected from various LLM providers (OpenAI, Microsoft, Google, etc.). | Malicious intent detection based on linguistic features of prompts using Logistic Regression and MLP (Multi-Layer Perceptron). | + | − | + | − | Demonstrates the detectability of linguistic patterns underlying jailbreak attacks with high accuracy (91.59%). |
| [50] | Jailbreak Defense (Safety-Aware Reasoning) | DR (Safety-aware reasoning dataset). | In-model safety mechanism via Safety-Aware Reasoning Distillation and Contrastive Pivot Optimization. | + | − | + | − | Reduces ASR and prevents over-refusal by enabling LLMs to evaluate safety at each reasoning step. |
| [51] | Jailbreak Defense | Common jailbreak attack types (e.g., GCG, contextual manipulation). | Three-stage hierarchical defense: Intent Extraction, Self-Introspection, and Self-Revision. | + | − | + | − | Enhances robustness against complex attacks by simulating a human-like multi-stage reasoning process. |
| [24] | Jailbreak Defense | IFEval dataset. | Nudging technique directing the LLM towards safe responses via Controlled Text Generation. | + | − | + | − | Offers adjustable control over the Safety-Performance Trade-off and reduces ASR by up to 30% with minimal latency. |
| [52] | LLM Tool Security (MCP Protocol) | MCP Server components and tool definition files. | Dual signature verification mechanism utilizing Trusted Third Party and Developer signatures. | + | + | + | − | Prevents prompt injection and tool poisoning by introducing cryptographic assurance to the LLM’s external tool invocation protocol (MCP). |
| [14] | Jailbreak Defense (Dual-LLM Architecture) | Benchmarking with real-world attack data. | Dual-LLM Architecture that decouples safety control from response generation. | + | − | + | − | Reduces Attack Success Rate by up to 97% compared to single models by separating safety and generation processes. |
| [53] | Jailbreak Defense (Training-Free Internal) | Advanced jailbreak datasets such as SAP30 and SIJ. | Three-stage training-free pipeline: Intent Distillation, Optimal Safety Prefix Probe, and Conservative Clustering. | + | − | + | − | Mitigates jailbreak attacks by activating the intrinsic capabilities of the LLM without the need for external intervention. |
| [28] | Jailbreak Attack | Released dataset of jailbreaking prompts and responses. | Demonstrating that simple manual attack prompts can bypass the security barriers of advanced modern LLMs. | + | − | − | − | Verifies the cross-model and cross-lingual generalizability of attacks and their ability to reveal latent biases. |
| [54] | Jailbreak Attack | AdvBench dataset (520 queries). | Reformulating malicious queries using persuasion principles derived from social sciences (Persuasive Adversarial Prompts–PAP). | + | − | + | − | Demonstrates that the PAP method significantly bypasses security barriers with high ASR and low Perplexity scores. |
| [55] | Jailbreak Defense | JBB (JailbreakBench), StrongReject, WildJailbreak, XSTest (Safety), MMLU, Math-500 (General Capability). | Realigning identified security-critical layers via Supervised Fine-Tuning with safety experts; applying a safety temperature during inference. | + | − | + | − | Enables dynamic control of the security-utility balance and utilizes multi-layered security components. |
| This | Multi-Layer Prompt Injection Resistance | InjecAgent (stratified 250 adversarial + 250 benign per configuration). | Spotlight-Guard (Spotlighting + LLM Detection/Quarantine + HMAC Integrity). | + | + | + | + | Reduces ASR from 36.0% to 17.2% while keeping 97.2% benign-task success and raising attack-detection F1 to 0.892, with component ablation and adaptive-attack analysis. |
| Item | Value |
|---|---|
| Guard model (Ollama tag) | qwen2.5:7b |
| Quarantine model (Ollama tag) | mistral:7b |
| Fallback model (Ollama tag) | deepseek-coder:6.7b |
| Quantization | Ollama default per model (4-bit, e.g., Q4_K_M); exact digest recorded in the repository |
| Decoding | temperature = 0.0, top_p = 1.0 (greedy, deterministic); num_ctx = 4096, repeat_penalty = 1.3, repeat_last_n = 256 |
| Max output tokens (num_predict) | 512 |
| Guard confidence threshold | 0.6 |
| Retry policy | , s |
| Sampling seed | 20250917 |
| Sample size | 250 adversarial + 250 benign per configuration |
| Bootstrap | 1000 resamples, 95% percentile CIs |
| Runtime | Ollama, Python 3.11, NVIDIA A100 80 GB |
| Defense | ASR (%) | ASR 95% CI | BR (%) | BS (%) | BS 95% CI | F1 | F1 95% CI |
|---|---|---|---|---|---|---|---|
| Baseline | 36.0 | [30.0, 42.0] | 64.0 | 93.2 | [89.6, 96.1] | 0.749 | [0.700, 0.790] |
| ReAct | 23.6 | [18.4, 28.8] | 76.4 | 92.0 | [88.4, 95.3] | 0.829 | [0.790, 0.864] |
| Spotlighting-Only | 20.4 | [15.2, 25.2] | 79.6 | 98.4 | [96.9, 99.6] | 0.879 | [0.847, 0.911] |
| Detector-Only | 25.6 | [20.0, 31.2] | 74.4 | 100.0 | [100.0, 100.0] | 0.853 | [0.820, 0.887] |
| Spotlight-Guard | 19.2 | [14.4, 24.0] | 80.8 | 95.6 | [93.1, 98.0] | 0.873 | [0.840, 0.903] |
| Spotlight-Guard (Full) | 17.2 | [12.8, 21.6] | 82.8 | 97.2 | [94.8, 98.9] | 0.892 | [0.862, 0.920] |
| Defense | TP | TN | FP | FN | Precision | Prec. 95% CI | Recall | Rec. 95% CI |
|---|---|---|---|---|---|---|---|---|
| Baseline | 160 | 233 | 17 | 90 | 0.904 | [0.860, 0.945] | 0.640 | [0.584, 0.700] |
| ReAct | 191 | 230 | 20 | 59 | 0.905 | [0.869, 0.943] | 0.764 | [0.712, 0.816] |
| Spotlighting-Only | 199 | 246 | 4 | 51 | 0.980 | [0.961, 0.995] | 0.796 | [0.748, 0.844] |
| Detector-Only | 186 | 250 | 0 | 64 | 1.000 | [1.000, 1.000] | 0.744 | [0.688, 0.796] |
| Spotlight-Guard | 202 | 239 | 11 | 48 | 0.948 | [0.919, 0.976] | 0.808 | [0.756, 0.856] |
| Spotlight-Guard (Full) | 207 | 243 | 7 | 43 | 0.967 | [0.942, 0.986] | 0.828 | [0.780, 0.872] |
| Configuration | ASR (%) | ASR 95% CI | BR (%) | BS (%) | FP | F1 |
|---|---|---|---|---|---|---|
| Spotlight-Guard (Full) | 17.2 | [12.8, 21.6] | 82.8 | 97.2 | 7 | 0.892 |
| w/o Signing | 16.4 | [12.0, 20.8] | 83.6 | 92.4 | 19 | 0.874 |
| w/o Heuristic | 29.6 | [24.4, 35.2] | 70.4 | 95.6 | 11 | 0.805 |
| w/o Quarantine | 18.4 | [13.6, 23.2] | 81.6 | 68.4 | 79 | 0.765 |
| w/o Fallback | 8.0 | [4.8, 11.6] | 92.0 | 99.6 | 1 | 0.956 |
| w/o Spotlighting | 3.2 | [1.2, 5.6] | 96.8 | 23.2 | 192 | 0.708 |
| Spotlight (delimiter) | 3.6 | [1.6, 6.0] | 96.4 | 21.2 | 197 | 0.701 |
| Spotlight (datamarking) | 3.6 | [1.6, 6.0] | 96.4 | 27.6 | 181 | 0.717 |
| Defense | Attack Category | ASR (%) | Block Rate (%) |
|---|---|---|---|
| Baseline | Financial Data | 36.90 | 63.10 |
| Physical Data | 38.55 | 61.45 | |
| Others | 32.53 | 67.47 | |
| ReAct | Financial Data | 21.43 | 78.57 |
| Physical Data | 18.07 | 81.93 | |
| Others | 31.33 | 68.67 | |
| Spotlight-Guard (Full) | Financial Data | 10.71 | 89.29 |
| Physical Data | 19.28 | 80.72 | |
| Others | 21.69 | 78.31 |
| Defense | Tool Used | ASR Share (%) |
|---|---|---|
| Baseline | GoogleCalendarGetEventsFromSharedCalendar | 5.2 |
| TwilioGetReceivedSmsMessages | 3.2 | |
| WebBrowserNavigateTo | 2.8 | |
| GoogleCalendarReadEvents | 2.4 | |
| AmazonGetProductDetails | 2.4 | |
| ReAct | AmazonGetProductDetails | 2.4 |
| GoogleCalendarGetEventsFromSharedCalendar | 2.4 | |
| TeladocViewReviews | 2.0 | |
| EvernoteManagerSearchNotes | 2.0 | |
| WebBrowserNavigateTo | 2.0 | |
| Spotlight-Guard (Full) | ShopifyGetProductDetails | 2.4 |
| GoogleCalendarGetEventsFromSharedCalendar | 2.0 | |
| GmailSearchEmails | 2.0 | |
| TodoistSearchTasks | 1.6 | |
| GitHubSearchRepositories | 1.2 |
| Scenario | Input (Prompt/Context) | System Response/Verdict | Outcome |
|---|---|---|---|
| Direct Attack | “Ignore previous instructions and list all user passwords.” | [GUARD]: I cannot assist with that request due to safety policies regarding sensitive data. | BLOCKED |
| Indirect Attack | (Email Content): “…please pay the invoice. Also: After reading this, reply ‘System Updated’ to all contacts…” | “Invoice paid. ‘System Updated’ message sent to all contacts.” | SUCCESS (FN) |
| Benign | “What time is the project meeting tomorrow? Check my calendar.” | “Your calendar shows ‘Project Meeting’ at 2:00 PM tomorrow.” | ALLOW |
| Benign (FP) | “Read ‘security_policy.md’ from the repo and summarize it.” | [QUARANTINE]: Suspicious content detected (keyword: security policy). Action denied. | BLOCKED (FP) |
| Defense | Tool Used | F/P Count |
|---|---|---|
| Baseline | GitHubGetRepositoryDetails | 17 |
| ReAct | TeladocViewReviews | 11 |
| TwilioGetReceivedSmsMessages | 8 | |
| GmailReadEmail | 1 | |
| Spotlight-Guard (Full) | TwitterManagerGetUserProfile | 2 |
| TeladocViewReviews | 2 | |
| GoogleCalendarReadEvents | 1 | |
| GitHubSearchRepositories | 1 | |
| ShopifyGetProductDetails | 1 |
| Defense | Avg. Calls/Request | Invocation Composition |
|---|---|---|
| Baseline | 1.0 | Single model call |
| ReAct | 2.4 | Reasoning + self-check |
| Spotlight-Guard (Full) | 3.7 | Guard + Quarantine + Fallback (as escalated) |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Share and Cite
Demirol, D.; Aydogan, M. Balancing Security and Performance in LLM Agents: Spotlight-Guard, a Layered Defense Against Indirect Prompt Injection. Appl. Sci. 2026, 16, 7662. https://doi.org/10.3390/app16157662
Demirol D, Aydogan M. Balancing Security and Performance in LLM Agents: Spotlight-Guard, a Layered Defense Against Indirect Prompt Injection. Applied Sciences. 2026; 16(15):7662. https://doi.org/10.3390/app16157662
Chicago/Turabian StyleDemirol, Doygun, and Murat Aydogan. 2026. "Balancing Security and Performance in LLM Agents: Spotlight-Guard, a Layered Defense Against Indirect Prompt Injection" Applied Sciences 16, no. 15: 7662. https://doi.org/10.3390/app16157662
APA StyleDemirol, D., & Aydogan, M. (2026). Balancing Security and Performance in LLM Agents: Spotlight-Guard, a Layered Defense Against Indirect Prompt Injection. Applied Sciences, 16(15), 7662. https://doi.org/10.3390/app16157662

