With LLMs evolving at breakneck speed, one thing has become abundantly clear: static defenses are no longer enough.
Attackers are growing more sophisticated, continuously refining their strategies by learning from the very systems they seek to exploit. This dynamic threat landscape calls for adaptive defenses that can evolve and improve faster than the attacker, always staying one step ahead.
Lakera’s latest research, published as "Gandalf the Red: Adaptive Security for LLMs," introduces a framework that i) accounts for the dynamic nature of LLM security and ii) allows developers to choose a security layer that keeps users safe while not disproportionally affecting the usability of their application.
In this article, we’ll take a closer look at the key findings of the paper, guided by insights from two of its authors, Niklas Pfister, Senior Research Scientist at Lakera, and Mateo Rojas-Carulla, Chief Scientist and Co-Founder at Lakera.
TL;DR
For those short on time, here are the key takeaways from the research:
- The D-SEC Framework – Our Dynamic Security and Utility Threat Model helps manage the trade-offs between security and usability while addressing the dynamic nature of LLM security.
- Balancing Security and Usability – LLM defenses affect application usability beyond simply blocking interactions. Developers must carefully consider the security-utility tradeoff.
- Evolving Threats Require Adaptive Defenses – As attackers continuously adapt their strategies based on model feedback, static defenses fall short. Adaptive approaches provide significantly better protection.
- Three Key Strategies for Stronger Defenses:
- Restricting Application Scope – Narrowing application functionality through the system prompt enhances security.
- Defense-in-Depth – Combining multiple security layers offers substantial protection benefits.
- Adaptive Security – User behavior during interactions provides valuable insights for strengthening defenses.
Balancing Security and Utility: The Core Challenge
The central theme of the research is the delicate balance between security and utility. Mateo explains, “Unlike traditional applications, security in LLMs isn’t just about blocking attacks. It’s about ensuring the system remains usable for legitimate users.”
Overly strict defenses can degrade the user experience, causing the model to refuse benign requests or provide suboptimal responses.
The interplay between security and usability is especially delicate when defenses are implemented in the system prompt. While this approach enhances security, it can reduce the length and quality of application responses. As Niklas points out, “Every red-teaming exercise should measure not just how well the defense blocks attacks but also how it impacts the application’s utility.”

Why Adaptive Defenses Matter
Static defenses often create a false sense of security. Mateo emphasizes, “Attackers don’t operate in a vacuum. They refine their strategies based on the feedback they receive from the model. Without adaptive defenses, systems remain vulnerable to the attacker getting wiser. Attackers are often stopped by the defenses in Gandalf on their first attempt, but eventually they all fall.”
To address this, the research introduces the Dynamic Security and Utility Threat Model (D-SEC), which incorporates two crucial elements:
- Dynamic Attacker Behavior: Models how attackers learn and adapt over time.
- Security-Utility Trade-offs: Evaluates the impact of defenses on both malicious and benign users.
Niklas explains, “D-SEC allows us to think about the problem in the right way, balancing the need to block attacks with the goal of preserving a positive user experience.”

Practical Strategies for Better Security
Lakera’s research identified three strategies that significantly improve LLM security while maintaining usability:
- Restricting Application Domains: Narrowing the scope of an LLM’s functionality reduces its attack surface. “If an LLM is only supposed to handle financial data, make that explicit in the system prompt,” suggests Mateo. Their experiments showed that more restricted applications were inherently more secure.
- Defense-in-Depth: Combining multiple, distinct defenses creates a stronger overall security posture. Mateo adds, “Even if individual defenses can be bypassed, their combination makes it much harder for attackers to succeed.”
- Adaptive Defenses: Using session history to identify suspicious users early and block them, depriving attackers of an unlimited attack budget.
The paper introduces metrics such as Session Completion Rate (SCR) and Attacker Failure Rate (AFR), which allow practitioners to select the defense strategy that provides the defenses they need without impacting usability too much.

The Role of Gandalf in LLM Security
Gandalf, a gamified red-teaming platform, has been instrumental in advancing our understanding of LLM vulnerabilities. Mateo explains, “With millions of players globally contributing over 25 years of gameplay, Gandalf uncovers vulnerabilities that static benchmarks often miss.”

Niklas highlights two key advantages of Gandalf:
- Human Creativity: Players generate diverse, adaptive attacks that mimic real-world adversaries.
- Accurate Feedback: Gandalf’s interactive nature allows precise labeling of successful attacks, even when they’re subtle or unconventional.
The insights from Gandalf have directly informed the development of adaptive defense strategies, demonstrating the power of community-driven initiatives in AI security.
Challenges and Trade-offs
The interplay between security and usability presents unique challenges for LLMs. Niklas notes, “Overly strict defenses can make applications less useful, blocking benign requests or reducing response quality.”
This trade-off becomes even more pronounced in autonomous agents, where defenses influence decision-making processes. Mateo stresses the importance of designing defenses that integrate seamlessly with applications, ensuring they remain functional and effective.

Play Gandalf and explore adaptive security firsthand!

Conclusion
Adaptive defenses represent the future of LLM security. They offer a way to protect systems while preserving their utility, addressing the challenges posed by evolving attacks. Tools like Gandalf and frameworks like D-SEC are paving the way for a more secure AI landscape.
To dive deeper into the research, check out the full paper, "Gandalf the Red: Adaptive Security for LLMs."
