Abstract
As Large Language Models (LLMs) are increasingly integrated into critical workflows, they face growing threats from prompt injection attacks. AEGIS introduces an automated, GAN-inspired framework that co-evolves attackers and defenders to secure these systems. By employing "textual gradients"—natural language feedback—to iteratively optimize prompts, AEGIS achieves state-of-the-art detection performance, improving True Positive Rates by 20% without the need for expensive model fine-tuning.
Introduction
Prompt injection attacks involve maliciously crafted inputs designed to subvert an LLM's system instructions. For instance, in an automated grading scenario, a student might embed a hidden command in an essay to force a high grade regardless of content. Current defenses are often either training-based, which is computationally prohibitive for large models, or training-free manual guardrails, which are static and easily bypassed. AEGIS addresses this gap by automating the adversarial "arms race," allowing defenses to adapt dynamically to evolving attack strategies.
Methods
The AEGIS framework operates on a co-evolutionary principle where an attacker and a defender iteratively improve against one another in a manner similar to a Generative Adversarial Network (GAN).
The core optimization engine is Textual Gradient Optimization Plus (TGO+). Since black-box LLMs do not provide mathematical gradients, TGO+ uses an LLM to generate "textual gradients"—detailed natural language feedback explaining why a specific prompt succeeded or failed. This feedback is enhanced by two key innovations:
- Multi-Route Optimization: The system generates feedback based on multiple signals, such as Attack Success Rate (ASR) for attackers and True Positive Rate (TPR) for defenders.
- Gradient Buffer: By storing past textual feedback, the system prevents optimization loops and encourages the exploration of novel defensive strategies.
Experimental Results
The framework was evaluated using a real-world automated grading dataset from National Taiwan University, comprising 143 malicious articles and 100 benign articles.
As shown in the results table, AEGIS significantly outperformed existing baselines. By the eighth iteration, the defender achieved a True Positive Rate (TPR) of 0.84, representing a 0.20 improvement over previous state-of-the-art methods like LLaMA 3.1 Guard. Crucially, this gain in detection did not compromise precision; the True Negative Rate (TNR) remained high at 0.88-0.89, ensuring that benign student work was rarely misclassified. Furthermore, prompts optimized on one model (e.g., GPT-4o-mini) proved effective when transferred to others (e.g., Gemini 2.5-flash), demonstrating robust cross-model generalizability.
Discussion and Conclusion
AEGIS demonstrates that adversarial training can be effectively conducted at the prompt level rather than the weight level. This model-agnostic approach is particularly valuable for securing closed-source APIs. The co-evolutionary process prevents the defender from overfitting to a static set of attacks, enabling better generalization to "zero-day" injections. Future work will explore the framework's efficacy in multimodal contexts and focus on improving the interpretability and conciseness of machine-engineered prompts.
Summary updated