Protecting LLM Bots From Prompt Injection: Key Lessons
How to protect a small open-source LLM chatbot from prompt injection: multilayer security experiment results, classifiers, and key takeaways.

An extensive experiment was conducted as part of an applied AI master's thesis to evaluate multilayer security against prompt injection for a chatbot powered by a small open-source language model, Qwen2.5-1.5B. Five distinct security configurations were tested against 300 standard attacks using the public NVIDIA garak scanner, alongside manual test cases in Russian and Kazakh. The main objective was to measure the real contribution of each security layer, from input filters and prompt separation to runtime monitoring.
- The experiment proved that relying on a single protective filter is insufficient to safeguard LLM bots from prompt injection vulnerabilities.
- Meta's specialized Llama Prompt Guard 2 classifier matched regex performance while eliminating false rejections for legitimate users.
- Indirect injections and attacks in languages outside the classifier's training dataset remained the primary residual risks.
- Window-based monitoring via MLflow successfully detected all simulated security incidents within the first tracking window.
Evaluating Filters and Neural Classifiers Comparing various security setups showed that basic regular expressions and the neural network classifier Llama Prompt Guard 2 offer a comparable baseline in blocking common attacks. However, the classifier demonstrated superior performance in mitigating complex DAN (Do Anything Now) jailbreaks, missing only isolated cases compared to rigid string matching patterns. Nevertheless, both methods face limitations when processing low-resource languages like Kazakh or heavily obfuscated inputs. The authors emphasize that strict separation of system instructions and user data within the prompt acts as an essential foundational layer that mitigates potential exploits even before reaching the language model.
The Role of Monitoring and Human Oversight Beyond static filtering, implementing dynamic request and response monitoring using logging tools became a critical component of the security architecture. Setting up threshold indicators in MLflow allowed operators to promptly detect behavioral anomalies, suspicious traffic spikes, and attempts to bypass defense mechanisms. However, automation is only capable of triggering timely alerts, while the final decision to activate safe modes or shut down the service rests with human operators. The experiment highlights that human intervention and the time required to manually analyze unforeseen attacks remain key operational costs when supporting secure LLM products in production.
Practical Implications for Developers and Business These findings are valuable for IT service owners and developers planning to deploy compact local language models without massive budgets for commercial cloud APIs. Small models like Qwen2.5-1.5B require careful handling during deployment because they are inherently more vulnerable to specific attack vectors compared to flagship models. For businesses, this underscores the need to build a comprehensive defense-in-depth strategy where input filtering is complemented by continuous log audits, output sanitation, and a team prepared to respond to security incidents before they affect real users.
Source: Все публикации подряд на Хабре



