Abstract
Large Language Models (LLMs) are increasingly integrated into critical applications but remain vulnerable to adversarial attacks—subtle perturbations like typos or synonym swaps that flip model predictions. Traditional defense mechanisms, such as Adversarial Fine-Tuning (AFT), are computationally expensive and often fail to generalize to unseen attack vectors. This paper introduces LLAMOS (Large LAnguage MOdel Sentinel), a "plug-and-play" framework that utilizes an LLM as a purification agent. By employing specific agent instructions, defense guidance, and in-context learning, LLAMOS cleanses adversarial noise from inputs before they reach the target model. Experimental results across the GLUE benchmark demonstrate that LLAMOS significantly reduces attack success rates and restores robust accuracy without requiring model retraining.
Introduction
Despite their impressive capabilities, state-of-the-art LLMs exhibit a surprising fragility. Adversarial attacks, which involve minor modifications to text—such as inserting a redundant emoji or swapping a word for a synonym—can easily deceive models into incorrect classifications. For instance, a sentiment analysis model might correctly identify a movie review as "Negative," but change its prediction to "Positive" if a smiley face is appended to the end of a scathing critique.
While Adversarial Fine-Tuning (AFT) is the standard defense, its high cost and lack of agility against evolving attack strategies make it impractical for many real-world scenarios. LLAMOS addresses this by treating the defense as a reasoning task, using the inherent linguistic knowledge of an LLM to act as a digital sentinel.
Methodology
The LLAMOS Framework
LLAMOS operates as a defense-in-depth module that sits in front of the target LLM. It consists of two primary components designed to guide the purification process:
- Agent Instruction: A system-level prompt that defines the LLM's role as a "Sentinel." It instructs the model to generate a purified version of the input that preserves the original semantic meaning while removing potential adversarial perturbations.
- Defense Guidance: A set of six strategic heuristics provided to the agent. These include instructions to correct obvious spelling errors, eliminate redundant symbols, and ensure the resulting sentence is coherent and logical.
In-Context Learning (ICL)
To handle novel or particularly effective attacks, LLAMOS leverages In-Context Learning. By providing the sentinel with a few examples of specific adversarial patterns and their purified counterparts, the system can adapt its defense strategy on the fly. This allows for a dynamic defense that does not require updating the underlying neural network weights.
Experimental Evaluation
Datasets and Attacks
The framework was evaluated using the GLUE (General Language Understanding Evaluation) benchmark, covering tasks such as sentiment analysis (SST-2), natural language inference (RTE, QNLI, MNLI), and question similarity (QQP). These models were subjected to PromptAttack, a comprehensive suite of character, word, and sentence-level perturbations.
Key Results
LLAMOS demonstrated robust performance as a modular defense:
- Attack Success Rate (ASR) Reduction: The framework reduced the ASR by an average of 29.3% for GPT-3.5 and up to 45.59% for Llama-2.
- Robust Accuracy Recovery: In a notable test on the SST-2 dataset using Llama-2, model accuracy plummeted to 30.42% under heavy attack. With LLAMOS purification, accuracy recovered to 86.96%.
- Zero-Shot vs. Few-Shot: While the sentinel is effective in a zero-shot setting, adding ICL examples further boosted performance, particularly against character-level attacks where accuracy improved from 89% to 97%.
Discussion and Limitations
The Semantic Blind Spot
A critical finding is that LLAMOS struggles when an attack changes the actual meaning of a sentence (e.g., inserting the word "not"). Because the sentinel does not know the ground-truth label, it may "purify" a malicious sentence into a grammatically perfect but semantically incorrect one, leading the target model astray.
AI Confrontation Loops
In experiments where an Attack Agent and LLAMOS engaged in a continuous loop, the researchers observed "stalemates." The models occasionally entered infinite loops, swapping the same words back and forth, highlighting the complexity of achieving absolute robustness in dynamic environments.
Conclusion
LLAMOS offers a promising, resource-efficient path toward more robust AI systems. By utilizing the reasoning power of LLMs to perform real-time text purification, it provides a flexible defense that can be deployed alongside existing models without the need for expensive retraining. Future work will focus on reducing inference latency and providing the sentinel with better task-specific context to overcome semantic blind spots.
Summary updated