This paper explores a geometric approach to a persistent problem in AI safety: detecting "jailbreak" attempts—prompts designed to bypass the safety guardrails of Large Language Models (LLMs). Instead of relying on traditional, rigid classifiers, the authors propose Jailbreak Detection with Prototype Inference (JDPI), a method that identifies harmful intent by analyzing the "neighborhood" of a prompt in a learned representation space.
TL;DR
JDPI uses contrastive learning to map prompts into a geometric space where harmful and benign examples are clearly separated. By measuring the distance of a new prompt to "prototypes" (centroids) of safe and unsafe content, it achieves state-of-the-art detection accuracy while being more robust to new datasets and requiring significantly less labeled data than traditional classifiers.
What Problem Does This Paper Address?
Current safety guardrails often treat jailbreak detection as a standard classification problem. However, this setup has flaws:
- Rigid Taxonomies: Safety policies are often predefined and might not cover creative, emerging attack vectors.
- Fuzzy Boundaries: The line between a "harmful" request and a "benign" one that uses similar vocabulary can be thin.
- Data Inefficiency: Training a robust downstream classifier requires a large, separate set of labeled data.
The authors ask: Do harmful and benign inputs form exploitable geometric structures in the representation space? If they do, we might not need a complex classifier at all; we could simply look at the "shape" of the data.
Methods
The proposed framework consists of two main stages:
- Contrastive Representation Learning: The authors fine-tune a sentence encoder (specifically an MPNet-based model) using contrastive learning. This process "pushes" harmful and benign examples away from each other in the embedding space while "pulling" similar examples together.
- Prototype Inference (JDPI): Instead of training a Logistic Regression or Neural Network on top of these embeddings, JDPI identifies clusters (prototypes) for both harmful and benign classes. When a new prompt arrives, the system calculates its cosine distance to the nearest harmful prototype ($d_h$) and the nearest benign prototype ($d_b$). A simple softmax function then converts these distances into a "harmfulness score."
The authors also tested "Structure-Aware" classifiers (Methods B-D) that add features like cluster distances to a standard classifier, but found that the direct geometric inference of JDPI was often just as effective and more robust.
Datasets
The researchers evaluated JDPI across four diverse benchmarks:
- WildGuardMix (WGM): A mix of vanilla and adversarial prompts.
- WildJailbreak (WJB): Contains "in-the-wild" jailbreak attempts and benign prompts that resemble attacks.
- BeaverTailsQA (BTQA): Safety labels applied to complete Question-Answer pairs.
- TomGibbs (TG): A challenging dataset featuring multi-turn attacks using word-substitution ciphers.
Key Insights and Ideas
- The Power of Contrastive Tuning: Fine-tuning the encoder is the "secret sauce." Without it, the representation space is too cluttered for simple distance-based detection. With it, accuracy jumps by 9.1 to 18.0 percentage points.
- Geometric Sufficiency: The fact that JDPI performs as well as complex classifiers (Methods B-D) suggests that the discriminative information is already fully present in the embedding geometry. Adding more "structural features" to a classifier provides diminishing returns.
- Data Efficiency: Because JDPI doesn't need a separate split to train a downstream classifier, it uses 65.9% to 75.0% fewer labeled examples for model development compared to the baseline.
- Contextual Awareness: In multi-turn conversations (TomGibbs), JDPI's accuracy improves significantly when it considers the accumulated history of the conversation rather than just the current turn.
Key Results
- Vs. Classifiers: JDPI matches the performance of a standard embedding-based classifier (Method A) within 0.017 ROC-AUC across all benchmarks.
- Vs. Llama Guard 3-8B: When adapted to specific datasets, JDPI significantly outperforms the off-the-shelf Llama Guard 3-8B baseline, with ROC-AUC gains ranging from 0.173 to 0.310.
- Cross-Dataset Robustness: In "directed transfer" tests (training on one dataset and testing on another), JDPI outperformed the classifier baseline by an average of 1.59 percentage points, suggesting it generalizes better to unseen attack styles.
Limitations and Future Work
- Label Dependency: While JDPI avoids a separate classifier training split, it still requires binary safety labels for the initial contrastive fine-tuning and prototype construction.
- Hyperparameter Sensitivity: The performance depends on selecting the right "temperature" for the softmax score and a decision threshold, which currently requires a validation set.
- Refinement Mismatch: The authors noted that while iterative refinement of harmful subclusters (Phase 2) improved cluster separation, it didn't always translate to better binary detection, suggesting a potential mismatch between clustering objectives and classification goals.
Future work could explore jointly optimizing for both harmful-benign separation and internal subcluster structure to further harden LLMs against sophisticated, multi-stage attacks.
Summary updated