Jailbreak Detection on Large Language Models via Contrastive Prototype Structures

Yan Qiu, Yuanyuan LiarXiv 2026 · arXiv

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:

  1. Rigid Taxonomies: Safety policies are often predefined and might not cover creative, emerging attack vectors.
  2. Fuzzy Boundaries: The line between a "harmful" request and a "benign" one that uses similar vocabulary can be thin.
  3. 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:

  1. 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.
  2. 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."
Figure 1: Overview of the proposed framework. Contrastive fine-tuning first learns safety-aware representations that increase the separation between harmful and benign inputs. Method A serves as the embedding-based classifier baseline. Methods B–D progressively incorporate richer structural information, whereas JDPI performs direct prototype-based inference without relying on an additional downstream classifier.

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.
JDPI's inference process: clustering classes separately and scoring new inputs based on relative distances.

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

Abstract

Jailbreak attempts and harmful prompts remain a challenge for the safe deployment of large language models. We study whether contrastively learned representations can support safety detection without training an additional downstream classifier. We propose Jailbreak Detection with Prototype Inference (JDPI), which uses binary safety labels to construct harmful and benign prototypes and makes predictions from relative prototype distances. JDPI uses only binary safety labels for encoder adaptation, prototype construction, and validation. In our setup, it uses fewer labeled examples than the classifier baseline (Method A) by avoiding the separate split used to train the downstream classifier. Across four benchmarks covering different input formats, contrastive fine-tuning improves JDPI's detection accuracy by 9.1-18.0 percentage points. Using the same encoder, JDPI achieves slightly higher ROC-AUC on one benchmark and stays within 0.017 of the baseline across all four. With dataset-specific adaptation, JDPI exceeds the released Llama Guard 3-8B baseline by 0.173-0.310 in ROC-AUC across the four benchmarks. In multi-turn replay on TomGibbs, JDPI uses accumulated user history as the conversation unfolds, achieving higher conversation-level accuracy than when it uses the current turn alone. Across 12 directed transfers, JDPI outperforms the classifier by an average of 1.59 percentage points in accuracy, demonstrating stronger cross-dataset robustness.
BibTeX
@misc{qiu2026jailbreak,
  author = {Yan Qiu and Yuanyuan Li},
  title = {{Jailbreak Detection on Large Language Models via Contrastive Prototype Structures}},
  year = {2026},
  eprint = {2611.24936},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.24936},
}
Figure