Gandalf the Red: Rethinking LLM Security with Adaptive Defenses
Lakera's latest research introduces adaptive defense strategies to enhance LLM security against evolving threats while balancing the need for usability.
Lakera's latest research introduces adaptive defense strategies to enhance LLM security against evolving threats while balancing the need for usability.
Download this guide to delve into the most common LLM security risks and ways to mitigate them.
In-context learning
As users increasingly rely on Large Language Models (LLMs) to accomplish their daily tasks, their concerns about the potential leakage of private data by these models have surged.
[Provide the input text here]
[Provide the input text here]
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.
Lorem ipsum dolor sit amet, Q: I had 10 cookies. I ate 2 of them, and then I gave 5 of them to my friend. My grandma gave me another 2boxes of cookies, with 2 cookies inside each box. How many cookies do I have now?
Title italic
A: At the beginning there was 10 cookies, then 2 of them were eaten, so 8 cookies were left. Then 5 cookieswere given toa friend, so 3 cookies were left. 3 cookies + 2 boxes of 2 cookies (4 cookies) = 7 cookies. Youhave 7 cookies.
English to French Translation:
Q: A bartender had 20 pints. One customer has broken one pint, another has broken 5 pints. A bartender boughtthree boxes, 4 pints in each. How many pints does bartender have now?
Lorem ipsum dolor sit amet, line first
line second
line third
Lorem ipsum dolor sit amet, Q: I had 10 cookies. I ate 2 of them, and then I gave 5 of them to my friend. My grandma gave me another 2boxes of cookies, with 2 cookies inside each box. How many cookies do I have now?
Title italic Title italicTitle italicTitle italicTitle italicTitle italicTitle italic
A: At the beginning there was 10 cookies, then 2 of them were eaten, so 8 cookies were left. Then 5 cookieswere given toa friend, so 3 cookies were left. 3 cookies + 2 boxes of 2 cookies (4 cookies) = 7 cookies. Youhave 7 cookies.
English to French Translation:
Q: A bartender had 20 pints. One customer has broken one pint, another has broken 5 pints. A bartender boughtthree boxes, 4 pints in each. How many pints does bartender have now?
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.
For those short on time, here are the key takeaways from the research:
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.”
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:
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.”
Lakera’s research identified three strategies that significantly improve LLM security while maintaining usability:
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.
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:
The insights from Gandalf have directly informed the development of adaptive defense strategies, demonstrating the power of community-driven initiatives in AI security.
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.
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."
Download this guide to delve into the most common LLM security risks and ways to mitigate them.
Get the first-of-its-kind report on how organizations are preparing for GenAI-specific threats.
Compare the EU AI Act and the White House’s AI Bill of Rights.
Get Lakera's AI Security Guide for an overview of threats and protection strategies.
Explore real-world LLM exploits, case studies, and mitigation strategies with Lakera.
Use our checklist to evaluate and select the best LLM security tools for your enterprise.
Discover risks and solutions with the Lakera LLM Security Playbook.
Discover risks and solutions with the Lakera LLM Security Playbook.
Subscribe to our newsletter to get the recent updates on Lakera product and other news in the AI LLM world. Be sure you’re on track!
Lakera Guard protects your LLM applications from cybersecurity risks with a single line of code. Get started in minutes. Become stronger every day.
Several people are typing about AI/ML security. Come join us and 1000+ others in a chat that’s thoroughly SFW.