Jailbreak attempts and harmful prompts remain a challenge for the safe deployment of large language models. While much work has focused on training dedicated classifiers to flag unsafe inputs, this approach requires labeled data and adds computational overhead. Researchers have increasingly turned to representation-level methods that can detect jailbreaks without retraining a full classifier architecture.

A gap in safety detection: from classifiers to prototypes

Prior work on LLM safety has largely relied on supervised classifiers trained on prompt-label pairs. These models need a separate training split, which reduces the amount of labeled data available for evaluation. Moreover, classifiers can be sensitive to the choice of architecture and hyperparameters, making cross-dataset performance inconsistent. The gap this paper addresses is whether contrastively learned representations alone—without any additional classifier head—can reliably distinguish harmful from benign prompts.

JDPI: Constructing harmful and benign prototypes from binary labels

The proposed method, Jailbreak Detection with Prototype Inference (JDPI), operates at the representation level. It begins by assigning binary safety labels (harmful / benign) to prompts in the training set. From these labels, two prototype vectors are constructed: one representing the aggregated embedding of all harmful prompts, and another for all benign prompts. During inference, a new prompt is embedded, and its safety decision is made by comparing its distance to the two prototypes. The closer prototype determines the prediction. This entire process—label assignment, prototype construction, and validation—uses only binary safety signals, no gradient-based classifier training is involved.

A key design choice is that JDPI avoids the separate train/validation split used for training a downstream classifier. In the paper's setup, this means fewer labeled examples are needed because the same binary labels serve both to adapt the encoder and to build the prototypes. The method leverages contrastive fine-tuning to shape the representation space so that harmful and benign prompts occupy distinct regions.

Contrastive fine-tuning and the accuracy lift

The authors evaluate JDPI across four benchmarks that cover different input formats—including single-turn prompts, multi-turn conversations, and structured inputs. Contrastive fine-tuning improves JDPI's detection accuracy by 9.1 to 18.0 percentage points relative to the un-fine-tuned baseline. These gains are substantial because they come from shaping the representation space rather than adding model capacity.

When comparing ROC-AUC using the same encoder (no dataset-specific adaptation), JDPI achieves slightly higher ROC-AUC on one benchmark and stays within 0.017 of the classifier baseline across all four. This indicates that the prototype-based approach does not sacrifice ranking quality even when operating without a trained classifier head.

Beating Llama Guard 3-8B with dataset-specific adaptation

With dataset-specific adaptation, JDPI exceeds the released Llama Guard 3-8B baseline by 0.173 to 0.310 in ROC-AUC across the four benchmarks. Llama Guard 3-8B is a purpose-built safety model, so outperforming it on multiple benchmarks demonstrates that a prototype-driven approach can compete with, and surpass, dedicated safety models when adapted to a target dataset.

Multi-turn conversation safety on TomGibbs

In multi-turn replay on the TomGibbs benchmark, JDPI uses accumulated user history as the conversation unfolds. Rather than judging each turn in isolation, the method incorporates prior turns into the prototype comparison. This conversational context yields higher conversation-level accuracy than when JDPI relies on the current turn alone. The result suggests that safety detection for jailbreaks benefits from viewing the full dialogue history, not just isolated prompts.

Cross-dataset robustness across 12 transfers

Across 12 directed transfers—where the model is tested on datasets different from those used for prototype construction—JDPI outperforms the classifier baseline by an average of 1.59 percentage points in accuracy. This consistent edge demonstrates stronger cross-dataset robustness. The improvement is particularly noteworthy because it occurs without any dataset-specific fine-tuning for the target domain.

Practical takeaways for developers

For engineers working on LLM safety, JDPI offers a practical alternative to training and maintaining a separate classifier. Because it only requires binary safety labels, the barrier to entry is lower: collect a set of prompts labeled harmful or benign, construct the two prototypes, and use distance comparison for inference. The contrastive fine-tuning step further improves accuracy without needing extensive labeled data. The multi-turn variant shows that maintaining conversation history can noticeably improve safety calls in chat interfaces. And the cross-dataset results indicate that prototype-based methods generalize better across domains than classifier-trained models, which often degrade when faced with new prompt distributions.

In summary, JDPI demonstrates that contrastive prototype structures can serve as an effective, data-efficient foundation for jailbreak detection. By avoiding the need for a downstream classifier, it reduces labeling overhead while achieving competitive or better-than-baseline performance across multiple benchmarks and safety baselines such as Llama Guard 3-8B.

Read the paper on arXiv

Read the paper on arXiv