arXiv:2611.24936cs.CLNov 2026

Manuscript Offprint

arXiv:2611.24936

Jailbreak Detection on Large Language Models via Contrastive Prototype Structures

Yan Qiu, Yuanyuan Li

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

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.

1 Introduction

For cybersecurity and safety, AI agents are typically deployed with policy constraints and safety guardrails. However, the increasing use of external tools and environments also introduces emerging security risks, including indirect prompt injection Zhan et al. (2024), tool-integrated agent security Debenedetti et al. (2024), and broader agent attack and defense scenarios Zhang et al. (2025a). Despite these safeguards, security vulnerabilities and failure modes remain Perez et al. (2022); Chao et al. (2024); Mazeika et al. (2024); Ganguli et al. (2022) and so-called "jailbreaking" techniques are also commonly used to bypass safety alignment Wei et al. (2023); Zou et al. (2023), which can pose risks to current AI-agent applications, starting from LLM use cases.

Many safety guards have been constructed at different levels. One commonly used tool is a classifier, which usually formulates safety detection as a classification problem Inan et al. (2023); Sharma et al. (2025), and the workflow can be: first define or construct a series of policy-violating cases, and then train the classifier to detect whether an input or output is intended to trigger harmful content.

The problem arises from this setup itself: first, the taxonomies are usually designed according to predefined safety policies or risk categories Mazeika et al. (2024); Markov et al. (2023) and may not fully cover all cases. Second, attention may be directed toward distinguishing detailed categories rather than the underlying intent of the context itself. Third, the boundaries between detailed categories can be fuzzy and may not correspond directly to the structure of the representation space Inan et al. (2023); Sharma et al. (2025); Galinkin and Sablotny (2024). This motivates the question of whether harmful and benign inputs also form exploitable geometric structures in the learned representation space. If such structure exists, it raises two related questions: whether representation-aware structural features can improve conventional classifiers, and whether the classification process can be replaced by direct geometric inference based on the learned representation geometry.

We propose Jailbreak Detection with Prototype Inference (JDPI). We use contrastive learning to improve the separation between harmful and benign inputs in the representation spaceGao et al. (2022); Khosla et al. (2021); Chen et al. (2020). Using binary safety labels, JDPI constructs harmful and benign prototypes and classifies inputs by their relative distances to these prototypes. This design eliminates the need for a separate labeled split to train a downstream classifier.

Methods B–D test whether adding explicit clustering-derived features improves classifier-based detection. Because the encoder is adapted to labeled data from a particular source, we test cross-dataset robustness by transferring the detector to other datasets without target-dataset adaptation. Our four benchmarks cover prompt-level, question–answer, and multi-turn inputs and include adversarial examples. We assess whether retaining user history improves multi-turn detection on TomGibbs.

References (44)