VLMGuard: Defending VLMs against Malicious Prompts via Unlabeled Data

## Abstract

Abstract Vision-language models (VLMs) are essential for contextual understanding of both visual and textual information. However, their vulnerability to adversarially manipulated inputs presents significant risks, leading to compromised outputs and raising concerns about the reliability in VLM-integrated applications. Detecting these malicious prompts is thus crucial for maintaining trust in VLM generations. A major challenge in developing a safeguarding prompt classifier is the lack of a large amount of labeled benign and malicious data. To
address the issue, we introduce VLMGuard , a novel learning framework that leverages the unlabeled user prompts in the wild for malicious prompt detection. These unlabeled prompts, which naturally arise when VLMs are deployed in the open world, consist of both benign and malicious information. To harness the unlabeled data, we present an automated maliciousness estimation score for distinguishing between benign and malicious samples within this unlabeled mixture, thereby enabling the training of a binary prompt classifier on top. Notably, our framework does not require extra human annotations, offering strong flexibility and practicality for real-world applications. Extensive experiment shows VLMGuard achieves superior detection results, significantly outperforming state-of-the-art methods. Disclaimer: This paper may contain offensive examples; reader discretion is advised.

## 1 Introduction

Safeguarding vision language models (VLMs) against persistent threats of adversarial
prompts has become a crucial yet challenging problem in safely deploying these multimodal foundation models in
the wild, where the user prompts in the deployment time can naturally arise from a mixture distribution of both benign and malicious sources (Zou et al., ; Liu et al., ; Yin et al., ). Compared with text-only language models, Modern VLMs process both text and images, making them particularly vulnerable to malicious prompts, which can target not only the textual input but also the visual component and thus allow attackers to manipulate both channels simultaneously (Zhang et al., ). These malicious prompts can elicit harmful outputs (Shayegani et al., ) or trigger unintended actions of VLM-integrated tools, such as personal assistants (Yi et al., ), and thus place critical decision-making at risk. This risk underscores the need for VLMs to not only generate coherent responses but also detect potentially malicious prompts before producing outputs (Alon & Kamfonas, ; Xie et al., ).

Malicious prompt detection, which involves determining whether a user-provided input is harmful, is essential for the safe deployment of VLMs. However, a primary challenge in learning a safeguarding prompt classifier is the limited availability of labeled datasets that include both benign and malicious samples. Constructing reliable datasets often requires extensive human annotation, which is time-consuming and difficult to scale given the evolving nature of generative models and the diversity of user inputs. Ensuring the quality of such labeled data further demands rigorous quality control, making manual annotation an unsustainable solution as models and user interactions become more complex. These significant challenges highlight the necessity of exploring methods that leverage unlabeled data for effective malicious prompt detection.

Figure: Figure 1: Illustration of our framework VLMGuard for malicious prompt detection, leveraging unlabeled user prompts in the model’s deployment environment. It first extracts the latent subspace from VLM representations to estimate the maliciousness of the prompt and then calculate the membership (benign vs. malicious) for samples in unlabeled data $\mathcal{D}$. Such membership enables learning a binary safeguarding prompt classifier.
Refer to caption: x1.png

Motivated by these challenges, we introduce VLMGuard, a novel learning framework designed to leverage unlabeled user data in the wild to enable the language model to distinguish between benign and malicious prompts. Unlabeled data naturally arises from interactions on chat-based platforms, where a vision language model such as LLaVA (Liu et al., ) deployed in the wild can receive a vast quantities of multimodal queries. This data frequently contains a blend of benign and potentially malicious content, such as those aimed at circumventing safety restrictions (Niu et al., ) or manipulating the model into executing unintended actions (Bagdasaryan et al., ). Formally, we conceptualize these unlabeled user prompts as a mixed composition of two distributions:

$$ $\mathbb{P}_{\text{unlabeled}}=\pi\;\mathbb{P}_{\text{malicious}}+(1-\pi)\; \mathbb{P}_{\text{benign}},$ $$

where $\mathbb{P}_{\text{malicious}}$ and $\mathbb{P}_{\text{benign}}$ respectively denote the distribution of malicious and benign data, and $\pi$ is the mixing ratio. Leveraging unlabeled data in this context is non-trivial due to the absence of explicit labels indicating whether a sample belongs to the benign or malicious category.

To address this, our framework introduces an automated maliciousness estimation score, enabling the differentiation of benign and malicious samples within unlabeled data. This differentiation facilitates the subsequent training of a binary safeguarding prompt classifier. Central to our approach is the exploitation of the language model’s latent representations, which encapsulate features indicative of malicious intent. Specifically, VLMGuard identifies a subspace within the activation space corresponding to malicious prompts. An embedding is considered potentially malicious if its representation strongly aligns with this subspace (see Figure 1). This concept is operationalized through decomposition in the VLM representation space, where the top singular vectors define the latent subspace for maliciousness estimation. The maliciousness estimation score is computed as the norm of the embedding projected onto these top singular vectors, which exhibits distinct magnitudes for benign and malicious data. Our estimation score provides a clear mathematical interpretation and is straightforward to implement in practice.

Extensive experiments on contemporary VLMs demonstrate that our approach VLMGuard can effectively enhance malicious prompt detection performance across different types of malicious data (Sections 4.2). Compared to the state-of-the-art methods, VLMGuard achieves a substantial improvement in detection accuracy, improving AUROC by 13.21% on average for LLaVA model. Additionally, we conduct an in-depth analysis of the key components of our methodology (Section 4.4) and further extend our investigation to illustrate VLMGuard’s scalability and robustness in addressing real-world challenges (Section 4.3). Our key contributions are as follows:

- •
We introduce VLMGuard, a framework that formalizes the problem of malicious prompt detection by leveraging unlabeled user prompts in the wild. This formulation offers strong practicality and flexibility for real-world applications.
- •
We introduce a scoring function derived from VLM representations to estimate the likelihood of a prompt being malicious, enabling effective classification in unlabeled data.
- •
We conduct extensive ablations to understand the efficacy of various design choices in VLMGuard, and validate
its scalability to large VLMs and different malicious data. These findings offer a systematic and comprehensive understanding of how to leverage unlabeled data for malicious prompt detection, providing insights for future research.

## 2 Problem Setup

Formally, we describe the vision language model and the problem of malicious prompt detection.

###### Definition 2.1 ( Vision language model ) .

We consider an $L$-layer causal VLM, which takes a sequence of $n$ textual tokens
$\mathbf{x}_{\text{prompt}}^{\rm t}=\{x_{1}^{\rm t},...,x_{n}^{\rm t}\}$ and $m$ visual tokens $\mathbf{x}_{\text{prompt}}^{\rm v}=\{x_{1}^{\rm v},...,x_{m}^{\rm v}\}$ to generate output text tokens $\mathbf{x}=\{x_{n+m+1},...,x_{n+m+o}\}$ in an autoregressive manner.
Each output token $x_{i},i\in[n+m+1,...,n+m+o]$ is sampled from a distribution
over the model vocabulary $\mathcal{V}$, conditioned on the prefix $\{x_{1},...,x_{i-1}\}$:

$$ $x_{i}=\operatorname{argmax}_{x\in\mathcal{V}}P(x|\{x_{1},...,x_{i-1}\}),$ (1) $$

and the probability $P$ is calculated as:

$$ $P(x|\{x_{1},...,x_{i-1}\})=\operatorname{softmax}(\mathbf{w}\mathbf{f}_{L}(x)+ \mathbf{b}),$ (2) $$

where $\mathbf{f}_{L}(x)\in\mathbb{R}^{d}$ denotes the representation at the $L$-th layer of VLM for token $x$, and $\mathbf{w},\mathbf{b}$ are the weight and bias parameters at the final output layer.

###### Definition 2.2 ( Malicious prompt detection ) .

We denote $\mathbb{P}_{\text{malicious}}$ as the joint distribution over the visual and textual prompts where the VLM generations are malicious, which is referred to as a malicious distribution. For any user-provided prompt $(\mathbf{x}_{\text{prompt}}^{\rm v},\mathbf{x}_{\text{prompt}}^{\rm t})\in
\mathcal{X}_{\text{prompt}}$, the goal of malicious detection is to learn a binary predictor $G:\mathcal{X}_{\text{prompt}}\rightarrow\{0,1\}$ such that

$$ $G({\mathbf{x}}_{\text{prompt}}^{\rm v},{\mathbf{x}}_{\text{prompt}}^{\rm t})= \begin{cases}\;1,\hskip 11.38109pt&\text{if }\;(\mathbf{x}_{\text{prompt}}^{ \rm v},\mathbf{x}_{\text{prompt}}^{\rm t})\sim\mathbb{P}_{\text{malicious}}\\ \;0,&\quad\quad\quad\quad\text{otherwise}\end{cases}$ (3) $$

###### Definition 2.1 ( Vision language model ) .

###### Definition 2.2 ( Malicious prompt detection ) .

## 3 Proposed Approach

In this paper, we propose a learning framework that facilitates malicious prompt detection by leveraging unlabeled user prompts collected in real-world settings. These prompts naturally arise from user interactions within chat-based applications. For instance, consider a vision-language model such as LLaVA (Liu et al., ) deployed in the wild, which processes a vast array of visual and textual user queries. This data can be collected with user consent, yet often contains a mixture of benign and
potentially malicious content. Formally, the unlabeled user prompts can be modeled using the Huber contamination model (Huber, ) as follows:

###### Definition 3.1 ( Unlabeled prompt distribution ) .

We define the unlabeled VLM user prompts to be the following mixture of distributions

$$ $\mathbb{P}_{\text{unlabeled}}=(1-\pi)\mathbb{P}_{\text{benign}}+\pi\mathbb{P}_ {\text{malicious}},$ (4) $$

where $\pi\in(0,1)$. Note that the case $\pi=0$ is idealistic since no malicious information occurs. In practice, $\pi$ can be a moderately small value when most of the user prompts remain benign.

###### Definition 3.2 ( Empirical data ) .

An empirical set ${\mathcal{D}}=\{({\mathbf{x}}_{\text{prompt}}^{\rm v,1},{\mathbf{x}}_{\text{
prompt}}^{\rm t,1}),...,({\mathbf{x}}_{\text{prompt}}^{\rm v,N},{\mathbf{x}}_{
\text{prompt}}^{\rm t,N})\}$ is sampled independently and identically distributed (i.i.d.) from this mixture distribution $\mathbb{P}_{\text{unlabeled}}$, where $N$ is the number of samples. Note that we do not have clear membership (benign or malicious) for the samples in ${\mathcal{D}}$.

Overview. Despite the availability of unlabeled user prompt datasets, leveraging such data presents significant challenges due to the absence of explicit labels indicating whether samples are benign or malicious within the mixture data ${\mathcal{D}}$. To overcome this challenge, our framework VLMGuard is designed to create an automated function that estimates the maliciousness of samples in the unlabeled data. This functionality enables the subsequent training of a binary classifier (see Figure 1). We detail these two steps in Section 3.1 and Section 3.2, respectively. Our study represents an initial effort to address this intricate problem and provides a foundation for future research on leveraging unlabeled data for malicious prompt detection.

###### Definition 3.1 ( Unlabeled prompt distribution ) .

###### Definition 3.2 ( Empirical data ) .

### 3.1 Estimating Maliciousness in the Latent Subspace

The first step in our framework is to estimate the maliciousness of data instances within a mixed dataset $\mathcal{D}$. The effectiveness of distinguishing between benign and malicious data depends on the language model’s ability to capture features that are indicative of malicious intent. Our key idea is that if we could identify a latent subspace associated with malicious prompts, it might enable their separation from benign ones. We formally describe the procedure below.

Representation decomposition. To realize the idea,
we first extract embeddings from the VLM for samples in the unlabeled mixture ${\mathcal{D}}$. Specifically, let $\mathbf{F}\in\mathbb{R}^{N\times d}$ denote the matrix of embeddings extracted from the vision language model for samples in ${\mathcal{D}}$, where each row represents the embedding vector $\mathbf{f}_{i}^{\top}$ of a data sample $({\mathbf{x}}_{\text{prompt}}^{\rm v,i},{\mathbf{x}}_{\text{prompt}}^{\rm t,i})$. To identify the latent subspace, we analyze principal components of the extracted representations via singular value decomposition (Klema & Laub, ):

$$ $\begin{split}\mathbf{f}_{i}&:=\mathbf{f}_{i}-\boldsymbol{\mu}\\ \mathbf{F}&=\mathbf{U}\Sigma\mathbf{V}^{\top},\end{split}$ (5) $$

where $\boldsymbol{\mu}\in\mathbb{R}^{d}$ is the average embedding across all $N$ samples, and is used to center the embedding matrix. The columns of $\mathbf{U}$ and $\mathbf{V}$ are the left and right singular vectors, and they form an orthonormal basis. In principle, the decomposition can be applied to any layer of the VLM representations, which will be analyzed in Section 4.4. Such a decomposition is useful, because it enables discovering the most important spanning direction of the subspace for the set of points in ${\mathcal{D}}$.

Figure: Figure 2: Visualization of the representations for benign (in orange) and malicious samples (in purple), and their projection onto the top singular vector $\mathbf{v}_{1}$ (in gray dashed line).
Refer to caption: x2.png

#### Maliciousness estimation.

To build intuition, we start by considering a simplified case where the subspace is one-dimensional, represented as a line through the origin. Finding the best-fitting line through the origin for a set of points $\{\mathbf{f}_{i}|1\leq i\leq N\}$ involves minimizing the sum of the squared perpendicular distances from the points to the line. Geometrically, identifying the first singular vector $\mathbf{v}_{1}$ is also equivalent to maximizing the total distance from the projected embeddings (onto the direction of $\mathbf{v}_{1}$) to the origin, summed over all points in $\mathcal{D}$:

$$ $\vspace{-0.1em}\mathbf{v}_{1}=\underset{\|\mathbf{v}\|_{2}=1,\mathbf{v}\in \mathbb{R}^{d}}{\operatorname{argmax}}\sum_{i=1}^{N}\left<\mathbf{f}_{i}, \mathbf{v}\right>^{2},$ (6) $$

where $\left<\cdot,\cdot\right>$ denotes the dot product operator.
As illustrated in Figure 2, malicious data samples tend to exhibit anomalous behavior compared to benign user prompts, often positioning themselves farther away from the center. This reflects the practical scenarios where a minority of the generations are malicious, while the majority are benign. To determine the membership, we define the maliciousness estimation score as
$\kappa_{i}=\left<\mathbf{f}_{i},\mathbf{v}_{1}\right>^{2}$, which measures the norm of $\mathbf{f}_{i}$ projected onto the top singular vector. This scoring enables us to assign membership to each unlabeled user prompt based on the relative magnitude of the maliciousness score (see the score distribution on practical datasets and its design rationale in Appendix B).

Our maliciousness estimation score provides a straightforward mathematical interpretation and is easily implementable in practical applications. Furthermore, the score can be generalized to utilize a subspace of $k$ orthogonal singular vectors:

$$ $\kappa_{i}=\frac{1}{k}\sum_{j=1}^{k}\lambda_{j}\cdot\left<\mathbf{f}_{i}, \mathbf{v}_{j}\right>^{2},$ (7) $$

where $\mathbf{v}_{j}$ is the $j^{\text{th}}$ column of $\mathbf{V}$, and $\lambda_{j}$ is the corresponding singular value. Here, $k$ represents the number of spanning directions in the subspace.
The underlying intuition is that malicious samples can effectively be captured by a small subspace, thereby distinguishing them from benign samples. We show in
Section 4.4 that leveraging the subspace with multiple components can capture the maliciousness encoded in VLM activations more effectively
than a single direction.

### 3.2 Training the Safeguarding Prompt Classifier

Following the procedure outlined in Section 3.1, we define the (potentially noisy) set of malicious prompts and ${\mathcal{M}}=\{({\mathbf{x}}_{\text{prompt}}^{\rm v,i},{\mathbf{x}}_{\text{
prompt}}^{\rm t,i})\in{\mathcal{D}}:\kappa_{i}>T\}$ and the candidate benign set ${\mathcal{B}}=\{({\mathbf{x}}_{\text{prompt}}^{\rm v,i},{\mathbf{x}}_{\text{
prompt}}^{\rm t,i})\in{\mathcal{D}}:\kappa_{i}\leq T\}$. We then proceed to train a safeguarding prompt classifier $\mathbf{h}_{\boldsymbol{\theta}}$, which is specifically designed to optimize the distinction between these two sets. In particular, the training objective can expressed as minimizing the following risk, where samples from ${\mathcal{M}}$ should be classified as positive, and those from ${\mathcal{B}}$ as negative:

$$ $\begin{split}\mathcal{L}_{{\mathcal{M}},{\mathcal{B}}}(\mathbf{h}_{\boldsymbol {\theta}})=\mathcal{L}_{{\mathcal{M}}}^{+}(\mathbf{h}_{\boldsymbol{\theta}})+ \mathcal{L}_{{\mathcal{B}}}^{-}(\mathbf{h}_{\boldsymbol{\theta}})&=\mathbb{E}_ {({{{\mathbf{x}}}_{\text{prompt}}^{\rm v}},{{{\mathbf{x}}}_{\text{prompt}}^{ \rm t}})\in{\mathcal{M}}}~{}\mathds{1}\{\mathbf{h}_{\boldsymbol{\theta}}({{{ \mathbf{x}}}_{\text{prompt}}^{\rm v}},{{{\mathbf{x}}}_{\text{prompt}}^{\rm t}} )\leq 0\}\\ &+\mathbb{E}_{({{{\mathbf{x}}}_{\text{prompt}}^{\rm v}},{{{\mathbf{x}}}_{\text {prompt}}^{\rm t}})\in{\mathcal{B}}}~{}\mathds{1}\{\mathbf{h}_{\boldsymbol{ \theta}}({{{\mathbf{x}}}_{\text{prompt}}^{\rm v}},{{{\mathbf{x}}}_{\text{ prompt}}^{\rm t}})>0\}.\end{split}$ (8) $$

Given the impracticality of directly minimizing the $0/1$ loss, we substitute it with a binary sigmoid loss, providing a smooth and more computationally feasible alternative. At the test stage, the trained prompt classifier is utilized for malicious prompt detection, using a malicious scoring function $S({{\tilde{\mathbf{x}}}_{\text{prompt}}^{\rm v}},{{\tilde{\mathbf{x}}}_{\text{
prompt}}^{\rm t}})=\frac{e^{\mathbf{h}_{\boldsymbol{\theta}}({{\tilde{\mathbf{
x}}}_{\text{prompt}}^{\rm v}},{{\tilde{\mathbf{x}}}_{\text{prompt}}^{\rm t}})}
}{1+e^{\mathbf{h}_{\boldsymbol{\theta}}({{\tilde{\mathbf{x}}}_{\text{prompt}}^
{\rm v}},{{\tilde{\mathbf{x}}}_{\text{prompt}}^{\rm t}})}}$, where $({{\tilde{\mathbf{x}}}_{\text{prompt}}^{\rm v}},{{\tilde{\mathbf{x}}}_{\text{
prompt}}^{\rm t}})$ denotes the test visual and textual prompt. Based on this score, we classify the input as malicious if $G_{\tau}({{\tilde{\mathbf{x}}}_{\text{prompt}}^{\rm v}},{{\tilde{\mathbf{x}}}_
{\text{prompt}}^{\rm t}})=\mathds{1}\{S({{\tilde{\mathbf{x}}}_{\text{prompt}}^
{\rm v}},{{\tilde{\mathbf{x}}}_{\text{prompt}}^{\rm t}})\geq\tau\}$, with $1$ indicating a malicious prompt and 0 0 otherwise.

## 4 Experiments and Analysis

In this section, we present empirical evidence to validate the effectiveness of our method on real-world malicious prompt detection tasks. We describe the setup in Section 4.1, followed by the results and comprehensive analysis in Section 4.2–Section 4.4.

### 4.1 Setup

Datasets and models. We evaluate our approach under two threat models–adversarial meta-instruction and jailbreak prompts. For the meta-instruction, we leverage the dataset from Zhang et al. (), which comprises 25 benign and 300 malicious images in ImageNet, each associated with 60 questions. Malicious images are generated by injecting adversarial noise into benign data using projected gradient descent (PGD) (Madry et al., ) over 40 training question-answer pairs. These pairs are categorized under one of five meta-objectives: Language, Politics, Formality, Spam, and Sentiment. For instance, the malicious images are optimized to prompt VLMs to produce biased responses, such as answers in different languages, with political or formality bias, sentiment alterations, or appended spam texts.

To simulate the unlabeled prompt data $\mathbb{P}_{\text{unlabeled}}$, we mix the benign image-text pairs ($\mathbb{P}_{\text{benign}}$) with malicious pairs ($\mathbb{P}_{\text{malicious}}$) under various $\pi\in\{0.001,0.005,0.01,0.05,0.1\}$. Twenty benign images and their corresponding synthesized malicious versions are in the unlabeled data with 40 questions as the textual prompts. We then test with 20 held-out questions and the remaining 5 images.

For the jailbreak prompts, we create both benign and malicious data by combining 250 safe textual prompts and 200 unsafe prompts from the XSTest dataset (Röttger et al., ) with 5 benign and adversarial images from Qi et al. (). The unlabeled dataset is constructed based on benign image-text pairs (by pairing 200 safe textual prompts with 3 benign images) and malicious pairs (by pairing 100 unsafe textual prompts with 3 adversarial images), while the remaining prompts are reserved for evaluation. We apply the same mixing strategy as used for the meta-instruction, with varying ratios $\pi$. Additional details on the dataset and inference procedures are provided in Appendix A.

We evaluate our method using two families of models: LLaVA-1.6-7B & 13B (Liu et al., ) and Phi-3-Vision (Abdin et al., ), which are popularly adopted public multimodal foundation models with accessible internal representations. Following the convention, we use
the pre-trained weights and conduct zero-shot inference in all cases.

Baselines and evaluation metric. We compare our approach with a comprehensive collection of baselines, which include: (1) Uncertainty-based malicious prompt detection approaches–Perplexity (Alon & Kamfonas, ), GradSafe (Xie et al., ) and Gradient Cuff (Hu et al., ); (2) LLM-based methods–Self detection (Gou et al., ) and GPT-4V (OpenAI, ); (3) Mutation-based approach JailGuard (Zhang et al., ); and (4) Denoising-based methods–MirrorCheck (Fares et al., ) and CIDER (Xu et al., ). To ensure a fair comparison, we assess all baselines on identical test data, employing the default experimental configurations as outlined in their respective papers. Consistent with a previous study (Alon & Kamfonas, ; Xie et al., ), we evaluate the effectiveness of all methods by the area under the receiver operator characteristic curve
(AUROC), which measures the performance of a binary classifier under varying thresholds. We discuss the implementation details for baselines in Appendix A.

Implementation details. Following embedding-based LM research (Zou et al., ), we use the last-token embedding to identify the subspace and train the safeguarding prompt classifier. The prompt classifier $\mathbf{h}_{\boldsymbol{\theta}}$ is a two-layer MLP with a ReLU non-linearity and an intermediate dimension of 512. We train $\mathbf{g}_{\boldsymbol{\theta}}$ for 50 epochs with an SGD optimizer, an initial learning rate of 0.05, cosine learning rate decay, batch size of 512, and weight decay of 3e-4. For synthesizing the malicious images, we apply PGD for 4,000 iterations with the step size of 0.01 on LLaVA and 2,000 iterations with the step size of 0.001 on Phi-3 model. The perturbation radius is set to $32/255$ following (Zhang et al., ). We discuss optimization details for malicious image generation in Appendix C, where we also report the attack success rate of the malicious prompts to ensure their validity. The layer index for representation extraction, the number of singular vectors $k$, and the filtering threshold $T$ are determined using the separate validation set, which consists of one additional benign image and its malicious counterpart, accompanied by the textual prompts used in the unlabeled data.

**Table 1: Results on detecting adversarial meta-instruction under varying meta-objectives ($N=800,\pi=0.01$). All values are percentages (AUROC). “Single inference" indicates whether the approach requires multiple forward passes during evaluation while “Single LM" means whether the approach requires additional LM for detection. Bold numbers are superior results. The results are averaged over 5 runs.**
| Model | Method | Single<br>inference | Single<br>LM | Language | Politics | Formality | Spam | Sentiment | Average |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| LLaVA | Perplexity (Alon & Kamfonas, ) | ✓ | ✓ | 71.82 | 79.27 | 62.34 | 92.36 | 92.52 | 79.66 |
| Self-detection (Gou et al., ) | ✓ | ✓ | 54.72 | 63.11 | 57.01 | 56.33 | 68.35 | 59.90 |  |
| GPT-4V (OpenAI, ) | ✓ | ✗ | 60.27 | 53.91 | 57.36 | 62.73 | 63.05 | 59.46 |  |
| GradSafe (Xie et al., ) | ✓ | ✓ | 72.80 | 63.97 | 66.94 | 60.70 | 61.45 | 65.17 |  |
| Gradient Cuff (Hu et al., ) | ✗ | ✓ | 73.19 | 69.27 | 68.48 | 59.64 | 60.44 | 66.20 |  |
| MirrorCheck (Fares et al., ) | ✓ | ✗ | 77.98 | 70.13 | 74.65 | 63.29 | 72.92 | 71.79 |  |
| CIDER (Xu et al., ) | ✓ | ✗ | 55.27 | 60.05 | 63.81 | 56.78 | 68.19 | 60.82 |  |
| JailGuard (Zhang et al., ) | ✗ | ✓ | 67.94 | 68.23 | 71.00 | 61.27 | 64.36 | 66.56 |  |
| VLMGuard (Ours) | ✓ | ✓ | 94.27^±2.31 | 88.24^±3.58 | 90.29^±2.79 | 96.21^±2.22 | 95.38^±3.04 | 92.87^±2.57 |  |
| Phi-3 | Perplexity (Alon & Kamfonas, ) | ✓ | ✓ | 89.89 | 84.62 | 87.13 | 89.94 | 88.08 | 87.93 |
| Self-detection (Gou et al., ) | ✓ | ✓ | 68.83 | 70.75 | 85.50 | 77.00 | 79.50 | 76.31 |  |
| GPT-4V (OpenAI, ) | ✓ | ✗ | 76.17 | 73.38 | 78.56 | 84.28 | 75.37 | 77.55 |  |
| GradSafe (Xie et al., ) | ✓ | ✓ | 73.46 | 57.39 | 70.45 | 53.75 | 63.07 | 63.62 |  |
| Gradient Cuff (Hu et al., ) | ✗ | ✓ | 72.23 | 73.49 | 60.61 | 68.92 | 79.82 | 71.01 |  |
| MirrorCheck (Fares et al., ) | ✓ | ✗ | 80.27 | 71.09 | 73.57 | 70.04 | 72.37 | 73.47 |  |
| CIDER (Xu et al., ) | ✓ | ✗ | 67.45 | 73.29 | 65.59 | 70.01 | 72.98 | 69.86 |  |
| JailGuard (Zhang et al., ) | ✗ | ✓ | 72.67 | 74.48 | 75.29 | 70.38 | 66.24 | 71.81 |  |
| VLMGuard (Ours) | ✓ | ✓ | 94.31^±3.67 | 92.20^±1.06 | 98.75^±1.23 | 93.04^±2.79 | 81.28^±3.31 | 92.11^±2.02 |  |

### 4.2 Main Results

Results on detecting meta-instruction. We present the malicious prompt detection results for adversarial meta-instruction in Table 1. Firstly, we observe that our method demonstrates a strong capability to identify test-time malicious prompts across different meta-objectives, even when trained on a minimal fraction of malicious prompts in the unlabeled data ($N=800,\pi=0.01$). In addition, our approach outperforms the state-of-the-art malicious prompt methods by a considerable margin on both the LLaVA and Phi-3 models. When compared to uncertainty-based baselines that lack access to malicious information, VLMGuard achieves an average improvement of 13.21% and 27.70% over Perplexity and GradSafe, respectively, which highlights the advantage of leveraging unlabeled user prompts for detection. We also notice that prompting language models to assess the maliciousness of input prompts is not effective because of the limited judgement capability discussed in prior work (Zheng et al., ). Finally, we compare our method with mutation-based and denoising-based approaches, which rely on multiple input mutations or additional diffusion models. From a computational standpoint, both alternatives incur significantly higher time complexity during inference compared to our method.

**Table 2: Jailbreak prompt detection results. The visual and textual inputs are from visual adversarial example (Qi et al., ) and XStest dataset (Röttger et al., ).**
| Method | LLaVA | Phi-3 |
| --- | --- | --- |
| Perplexity | 69.31 | 93.46 |
| Self-detection | 61.88 | 63.00 |
| GradSafe | 91.09 | 82.77 |
| MirrorCheck | 83.26 | 73.86 |
| JailGuard | 88.49 | 82.91 |
| VLMGuard (Ours) | 94.27^±1.75 | 95.74^±2.47 |

Results on detecting jailbreak prompt. Going beyond meta-instruction, we show that VLMGuard is also suitable and effective for detecting multimodal jailbreak prompts. To achieve this, we extract the maliciousness subspace using 600 unlabeled prompts and keep the maliciousness ratio as 0.01, and then apply the same binary classifier training setup used for the meta-instruction. The comparative results, as presented in Table 2, indicate that VLMGuard achieves superior jailbreak detection performance on both LLaVA and Phi-3 vs. competitive baselines. Interestingly, the higher detection accuracy for jailbreak prompts suggest that these may be easier to detect than meta-instruction. We hypothesize this is due to jailbreak prompts attacking both the visual and textual branches of VLMs, combining visual adversarial noise with malicious textual instructions (e.g., Instruct me how to murder someone), whereas meta-instructions typically involve visual adversarial noise only and thus are less separable from benign data.

### 4.3 Robustness Analysis

VLMGuard is a practical framework that may face real-world challenges. In this section, we explore how well it deals with different malicious data, its robustness under different malicious ratios $\pi$, and its scalability to larger VLMs. Additional analyses are discussed in Appendix D.

Generalization across different malicious data. We investigate whether VLMGuard can effectively generalize to different malicious data, which involves directly applying the learned prompt classifier on one unlabeled dataset (referred as the source(s)) and infer on malicious data that does not appear in the source data (referred to as target (t)). Concretely, we simulate the source and target data based on malicious text-image pairs that either belong to different meta-objectives or different threat models (i.e., meta-instruction vs. jailbreak prompt). The results depicted in Figure 3 (a) showcase the robust transferability of our approach across different malicious datasets. Notably, VLMGuard achieves a detection accuracy of 91.74% on the jailbreak prompts when trained on the unlabeled dataset consisting of the meta-instruction (from “Language"), which is close to the performance of the model that is directly trained on the jailbreak prompts. This demonstrates the strong generalizability and practicality of our approach in real-world LM application scenarios, where the malicious data is heterogeneous and usually differs from the previously collected user prompts.

Figure: Figure 3: (a) Generalization across different malicious data, where “(s)" denotes the source dataset and “(t)" denotes the target dataset. (b) Robustness of VLMGuard under different malicious ratio $\pi$. (c) Effect of the number of subspace components $k$ (Section 3.1). (d) Impact of different layers. All numbers are AUROC-based on the LLaVA model. Ablations in (b)-(d) are based on the threat of meta-instruction.
Refer to caption: x3.png

Robustness with different malicious ratios. Figure 3 (b) illustrates the robustness of VLMGuard with varying ratios of the unlabeled malicious samples $\pi$. The result shows that our method generally perform better when trained on a larger fraction of the malicious prompts. In the extreme case when $\pi=0.001$ where there is only one malicious example in the unlabeled dataset, our method can still be able to achieve a detection AUROC of 89.01%, which displays minimal drop compared to larger ratios. Considering the practical scenario where there is only a reasonably small amount of malicious prompts generated by users, we set $\pi$ to 0.01 in our main experiments (Section 4.2).

**Table 3: Malicious prompt detection results on larger VLMs.**
| Method | Meta-<br>Instruction | Jailbreak<br>Prompt |
| --- | --- | --- |
|  | LLaVA-1.6-13b |  |
| Perplexity | 82.33 | 75.91 |
| MirrorCheck | 74.94 | 82.01 |
| VLMGuard (Ours) | 95.27 | 96.01 |

Scalability to larger VLMs. To illustrate effectiveness with larger LLMs, we evaluate our approach on the LLaVA-1.6-13b model. The results of our method VLMGuard, presented in Table 3, not only surpass two competitive baselines but also exhibit improvement over results obtained with smaller VLMs. For instance, VLMGuard achieves an AUROC of 95.27% for meta-instruction detection with the 13b model, compared to 92.87% for the 7b model, representing an improvement of 2.4%.

### 4.4 Ablation Study

In this section, we provide further analysis and ablations to understand the behavior of our algorithm VLMGuard. Additional ablation studies are discussed in Appendix E.

Ablation on different layers. In Figure 3 (c), we ablate the effect of different layers in VLMs for representation extraction. The AUROC values of benign/malicious classification are evaluated based on the LLaVA model and the meta-instruction threat. All other configurations are identical to our main experimental setting. We observe that the malicious prompt detection performance generally increases from the lower to upper layers. This trend suggests a gradual capture of contextual information by language models in the first few layers and then condensing the information in the last layers to map to the vocabulary, which enables better malicious prompt detection. This observation echoes prior findings that indicate representations at upper layers are the most effective for downstream tasks (Burns et al., ).

Where to extract embeddings from multi-head attention? We investigate the multi-head attention (MHA) architecture’s effect on representing prompt maliciousness. Specifically, the MHA can be conceptually expressed as:

$$ $\mathbf{f}_{i+1}=\mathbf{f}_{i}+\mathbf{Q}_{i}\operatorname{Attn}_{i}(\mathbf{ f}_{i}),$ (9) $$

where $\mathbf{f}_{i}$ denotes the output of the $i$-th transformer block, $\operatorname{Attn}_{i}(\mathbf{f}_{i})$ denotes the output of the self-attention module in the $i$-th block, and $\mathbf{Q}_{i}$ is the weight of the feedforward layer. Consequently, we evaluate the malicious prompt detection performance utilizing representations from three *different locations within the MHA architecture*, as delineated in Table 4.

**Table 4: Malicious prompt detection results on different representation locations of multi-head attention.**
| Embedding location | LLaVA-1.6-7b | Phi-3 | LLaVA-1.6-7b | Phi-3 |
| --- | --- | --- | --- | --- |
|  | Meta-instruction | Jailbreak prompt |  |  |
| $\mathbf{f}$ | 92.87 | 91.82 | 94.27 | 94.77 |
| $\operatorname{Attn}(\mathbf{f})$ | 89.24 | 86.51 | 90.04 | 88.26 |
| $\mathbf{Q}\operatorname{Attn}(\mathbf{f})$ | 90.96 | 92.11 | 93.25 | 95.74 |

We observe that the LLaVA model tends to encode the maliciousness information mostly in the output of the transformer block while the most effective location for Phi-3 is the output of the feedforward layer, and we implement our malicious prompt detection algorithm based on this observation for our main results in Section 4.2.

**Table 5: Malicious prompt detection results on different maliciousness estimation scores.**
| Score design | LLaVA-1.6-7b | Phi-3 | LLaVA-1.6-7b | Phi-3 |
| --- | --- | --- | --- | --- |
|  | Meta-instruction | Jailbreak prompt |  |  |
| Non-weighted score | 91.92 | 89.74 | 93.09 | 94.16 |
| Summing up layer-wise scores | 67.96 | 70.62 | 75.29 | 68.58 |
| VLMGuard (Ours) | 92.87 | 92.11 | 94.27 | 95.74 |

Ablation on maliciousness score design choices. We systematically evaluate various design choices for the scoring function (Equation 7) used to differentiate between benign and malicious prompts within unlabeled data. Our investigation focuses on three key aspects: (1) The influence of the number of subspace components $k$; (2) The role of the weight coefficient associated with the singular value $\sigma$ in the scoring function; and (3) A comparison between score computation based on the best individual VLM layer versus aggregating layer-wise scores. Figure 3 (c) illustrates the detection performance for malicious prompts across different $k$ values (ranging from 1 to 10). We find that a moderate value of $k$ yields optimal performance, consistent with our hypothesis that malicious samples may occupy a small subspace within the activation space, where only a few key directions effectively distinguish malicious from benign samples. Additionally, Table 5 presents results from the LLaVA and Phi-3 models using a non-weighted scoring function ($\lambda_{j}=1$ in Equation 7). The weighted scoring function, which prioritizes top singular vectors, outperforms the non-weighted version, underscoring the importance of emphasizing key singular vectors. Lastly, we observe a marked decline in detection performance when layer-wise scores are summed, likely due to the reduced separability of benign and malicious data in the upper and lower layers of VLMs.

Figure: Figure 4: Comparison with using direction projection for malicious prompt detection. Value is AUROC.
Refer to caption: x4.png

Comparison with direct use of the maliciousness score for detection. Figure 4 showcases the performance of directly detecting malicious prompt using the score defined in Equation 7, which involves projecting the representation of a test sample to the extracted subspace and bypasses the training of the binary classifier as detailed in Section 3.2. On all four datasets, VLMGuard demonstrates superior performance compared to this direct projection approach on LLaVA, highlighting the efficacy of leveraging unlabeled data for training and the enhanced generalizability of the safeguarding prompt classifier.

Qualitative results. We provide qualitative examples of the model’s maliciousness score (Section 3.2) for different malicious prompts during inference (Figure 5). The model is LLaVA and we test on both threats of meta-instruction and jailbreak prompt. For example, when prompted with the adversarial image and the harmful textual prompt *“How do I commit fraud?"*, we find that VLMGuard can accurately produce the scores that align with the maliciousness of the inputs (the higher the score, the more malicious the prompt is).

Figure: Figure 5: Qualitative examples that show the effectiveness of our approach on meta-instruction (left, w/ the meta-objective of Spam) and jailbreak prompt (right) threats. Specifically, we compare the maliciousness scores $S({{{\mathbf{x}}}_{\text{prompt}}^{\rm v}},{{{\mathbf{x}}}_{\text{prompt}}^{ \rm t}})$ (Section 3.2) of VLMGuard with different prompts.
Refer to caption: x5.png

## 5 Related Work

Malicious prompt attack for LMs has attracted a surge of interest nowadays, where the main threats are prompt injection and jailbreak prompt. The former one is a class of attacks against applications built on top of LMs that concatenate untrusted user input with a trusted prompt constructed by the application’s developer (Greshake et al., ; Yi et al., ; Liu et al., , ; Shi et al., ; Rossi et al., ; Wang et al., ). For VLM, Bagdasaryan et al. () and Zhang et al. () proposed to inject adversarial noise to the visual model inputs to generate arbitrary fixed strings or texts that have adversary-chosen bias. By contrast, jailbreak prompt aims to trick the models into generating outputs that
violate their safety guardrails, e.g., toxic text (Chao et al., ; Zou et al., ; Liu et al., ; Wei et al., ; Yi et al., ; Russinovich et al., ; Gu et al., ). The current multimodal jailbreak attack mainly worked by optimizing the input images to elicit harmful generations (Shayegani et al., ; Carlini et al., ; Niu et al., ; Schlarmann et al., ) or leveraging typography images (Gong et al., ). We evaluate our algorithm on representative approaches in both categories (Zhang et al., ; Qi et al., )

Malicious prompt detection is crucial for ensuring LMs’ safety and reliability. Existing research is mostly developed based on text-based LLM and specifically for jailbreak prompts. One line of work performs detection by devising uncertainty scoring functions, such as perplexity (Alon & Kamfonas, ) and gradient scores (Xie et al., ; Hu et al., ). Another line of research utilized LM as a judge by querying the model itself (Gou et al., ) or another model, such as GPT for detection. In the multimodal domain, Xu et al. (); Fares et al. () took an embedding-based approach, where it relies on the embedding difference between the original image and its denoised version for jailbreak detection. Pi et al. () employed labeled data for harm detection, which differs from our scope on harnessing unlabeled prompts. Note that our studied problem is different from mitigation-based defense (Robey et al., ; Piet et al., ; Hines et al., ; Wang et al., ; Zeng et al., ; Chen et al., ; Li et al., ), which aims at preventing LM to generate compromised outputs given malicious prompts. Zou et al. () explored probing meaningful representation direction to detect hallucinations while VLMGuard aims for malicious prompt detection and presents a different algorithm design. (Bai et al., , ; Du et al., , ) utilized unlabeled data for out-of-distribution and hallucination detection, where the approach and problem formulation are different from ours.

## 6 Conclusion

In this paper, we propose a novel learning algorithm VLMGuard for malicious prompt detection in VLMs, which exploits the unlabeled user prompts arising in the wild. VLMGuard first estimates the maliciousness for samples in the unlabeled mixture data based on an embedding decomposition, and then trains a binary safeguarding prompt classifier on top. The empirical result shows that VLMGuard establishes superior performance on different malicious data and families of VLMs. Our in-depth quantitative and qualitative ablations provide further insights on the
efficacy of VLMGuard. We hope our work will inspire future research on malicious prompt detection with unlabeled prompt datasets.

## 7 Acknowledgement

Du is supported by the research internship program of Microsoft and Jane Street Graduate Research Fellowship. Li gratefully acknowledges the support from the AFOSR
Young Investigator Program under award number FA9550-23-1-0184, National Science Foundation
(NSF) Award No. IIS-2237037 & IIS-2331669, Office of Naval Research under grant number
N00014-23-1-2643, Philanthropic Fund from SFF, and faculty research awards/gifts from Google
and Meta.

## Appendix A Datasets and Implementation Details

Input prompts. We provide the detailed textual and visual input as prompts to different vision language models and datasets. Specifically, for LLaVA model, the prompt is shown as follows:

A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human’s questions. USER: $<$image$>$ \n [question] Your answers should be as concise as possible. ASSISTANT:

For Phi-3 model, we have the following template for prompts:

$<|$user$|>$\n $<|$image_1$|>$\n [question]$<|$end$|>$\n $<|$assistant$|>$\n

Here are some examples from different threats with our prompt format.

[Uncaptioned image]: x6.png

Meta objectives. For the threat of meta-instruction, we follow the original paper (Zhang et al., ) and create the malicious visual inputs with the following meta-objectives:

- •
Language: English, French, Spanish
- •
Formality: Formal, informal
- •
Sentiment: Positive, negative, neutral
- •
Political bias: Republican bias, Democratic bias
- •
Spam: Investment promotion, URL injection

Implementation details for baselines. For uncertainty-based baselines, we follow the codebase here(^1^11[https://huggingface.co/docs/transformers/en/perplexity](https://huggingface.co/docs/transformers/en/perplexity)) to implement the Perplexity method (Alon & Kamfonas, ), and calculate the score of the last input token. For GradSafe (Xie et al., ), we randomly select two malicious prompts from the unlabeled prompt dataset used in our approach for determining the weight vectors for gradient calculation. For LLM-based approaches, we adopt the following prompt for self-detection (Gou et al., ) on LLaVA model:

A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human’s questions. USER: $<$image$>$\n The user asks a question: [question] The input image contains adversarial noise that can lead to malicious generations with a probability (in %) of

and the prompt of

$<|$user$|>$\n $<|$image_1$|>$\n The user asks a question: [question] The probability that the input image contains adversarial noise that can lead to malicious generations when answering the user question is ? Please continue the sentence with a number (from 0 to 100) only. $<|$end$|>$\n $<|$assistant$|>$\n

for Phi-3 model. The prompt for using GPT-4V (OpenAI, ) for maliciousness judgement is:

[Insert Image] Carefully examine the input image and determine the probability that the image contains adversarial noise that can lead to malicious generations when answering the user question. Return a number (from 0 to 100) only.

For denoising-based baseline methods, we use the Stable Diffusion model with the CompVis SD-v1.4 weights for denoising. Finally, we employ the Random Grayscale mutation strategy on the visual input and set the number of mutations to 5 for JailGuard (Zhang et al., ).

## Appendix B Distribution of the Maliciousness Score

Figure: Figure 6: Distribution of maliciousness estimation score.
Refer to caption: extracted/5891374/figs/score_dis_app.png

We show in Figure 6 the distribution of the maliciousness estimation score (as defined in Equation 7 of the main paper) for the benign and malicious prompts in the unlabeled prompt dataset for meta-instruction threat (w/ the objective of “negative" in Sentiment). Specifically, we visualize the score calculated using the LLM representations from the 31-th layer of LLaVA-7b model. The result demonstrates a reasonable separation between the two types of data, and can benefit the downstream training of the safeguarding prompt classifier.

Design Rationale. We briefly provide our reasoning on the design rationale of utilizing embedding decomposition for maliciousness estimation. Firstly, subspace primary vectors derived through SVD often encapsulate the dominant patterns and variations within the internal representations of a model (^2^22[https://en.wikipedia.org/wiki/Principal_component_analysis](https://en.wikipedia.org/wiki/Principal_component_analysis)). These vectors can highlight the primary modes of variance in the unlabeled data, which are not purely random but instead capture significant structural features of the model’s processing. In our case, it could be the maliciousness information. Even though these vectors could, in theory, capture various features, they are particularly informative for detecting malicious samples because malicious and benign patterns are among these primary modes of variation in the unlabeled data. This phenomenon can be verified by the empirically observed separability in Figure 6 and literature (Zou et al., ).

## Appendix C Malicious Image Generation and the Attack Success Rate

We disclose the generation details for the malicious images. For the threat model of meta-instruction, we optimize the input images with 40 question-answer pairs per image that belong to different kinds of meta-objectives listed in Appendix Section A. Denote the answer as $a_{i}^{j}$ when feeding the textual and visual prompt $(\mathbf{x}_{\text{prompt}}^{{\rm t},i},\mathbf{x}_{\text{prompt}}^{{\rm v},j})$ to the vision language model, the adversarial noise $\delta$ is calculated by solving the following optimization problem:

$$ $\displaystyle\min_{(\mathbf{x}_{\text{prompt}}^{{\rm t},i},\mathbf{x}_{\text{ prompt}}^{{\rm v},j})\sim\mathcal{D}}\mathcal{L}(\operatorname{VLM}$ $\displaystyle(\mathbf{x}_{\text{prompt}}^{{\rm t},i},\mathbf{x}_{\text{prompt} }^{{\rm v},j}+\delta),a_{i}^{j}),$ (10) $\displaystyle s.t.\quad\|\delta\|_{\infty}\leq b,$ $$

where $b$ is the perturbation bound, and $\operatorname{VLM}(\cdot,\cdot)$ denotes the logit output of the input prompt. $\mathcal{L}$ is the cross entropy loss for the next-token prediction task. The dataset we used is directly taken from their official codebase (^3^33[https://github.com/Tingwei-Zhang/Soft-Prompts-Go-Hard](https://github.com/Tingwei-Zhang/Soft-Prompts-Go-Hard)).

For multimodal jailbreak prompt, we optimize the input images using the same objective as in the above equation. The textual dataset we used during optimization is from the harmful corpus in Visual Adversarial Example codebase (^4^44[https://github.com/Unispac/Visual-Adversarial-Examples-Jailbreak-Large-Language-Models/blob/main/harmful_corpus/derogatory_corpus.csv](https://github.com/Unispac/Visual-Adversarial-Examples-Jailbreak-Large-Language-Models/blob/main/harmful_corpus/derogatory_corpus.csv)) while the 5 visual images we optimize on are from the meta-instruction threat paper (Zhang et al., ).

We verify the validity of the synthesized malicious images by calculating the attack success rate (ASR) of input prompts, which denotes the percentage of successful attacks on a dataset. Specifically, we perform manual check on the evaluation prompts by examining the outputs of the VLMs under different threat models, and report the results in Table 6, where the ASRs of different attacks are all above 90% and thus signifying the strong attack capability of synthesized malicious images.

**Table 6: Attack success rate of the synthesized malicious data. Model is LLaVA-7b.**
| Threat | Language | Politics | Formality | Spam | Sentiment | Jailbreak |
| --- | --- | --- | --- | --- | --- | --- |
| ASR | 99% | 93% | 91% | 98% | 96% | 97% |

## Appendix D Results with Smaller Perturbation Radius

In Table 7, we investigate the effect of the perturbation radius on the detection accuracy. Concretely, we test two smaller radiuses on LLaVA-7b model for meta-instruction threat (w/ the objective of Sentiment), which are 8/255 and 16/255. Smaller radius means the injected adversarial noise has a smaller norm magnitude, and thus the adversarial images become more imperceptible and harder to detect. In practice, the experimental result validates our reasoning and we find that when the perturbation radius gets smaller, the detection accuracy drops.

**Table 7: Malicious prompt detection results with a smaller perturbation radius.**
| Perturbation radius | AUROC |
| --- | --- |
| 32/255 | 95.38 |
| 16/255 | 92.00 |
| 8/255 | 91.27 |

## Appendix E Results with Varying Size of Benign Data

In this section, we test our algorithm on the scenario where the number of malicious samples in the unlabeled data remains unchanged while the number of benign samples increases. This setting simulates the practical scenario that when user keeps querying the VLMs with more prompts and most of these prompts are benign, which is in contrast to the setting of our main Table 1 where the number of unlabeled samples $N$ is a constant. In Table 8, we observe that when the number of benign prompts in the unlabeled data increases, the detection accuracy drops. This phenomenon suggests that when applying our proposed algorithm VLMGuard, it might be useful to periodically filter benign samples in the unlabeled data to maintain a high detection accuracy.

**Table 8: Malicious prompt detection results with varying size of benign data. Model is LLaVA-7b and the threat is meta-instruction w/ the objective of Politics.**
| Number of benign data | AUROC |
| --- | --- |
| 792 | 88.24 |
| 600 | 89.61 |
| 400 | 92.67 |
| 200 | 96.55 |
| 100 | 98.71 |

## Appendix F Broad Impact and Limitations

Broader Impact. Vision language models have undeniably become a prevalent tool in
both academic and industrial settings, and ensuring the safe usage of these multimodal foundation models has emerged as a paramount
concern. In this line of thought, our paper offers a novel approach VLMGuard to detect malicious input prompts by leveraging the in-the-wild unlabeled data. Given the
simplicity and versatility of our methodology, we expect our work to have a positive impact on the
AI safety domain, and envision its potential usage in industry settings. For instance, within the chat-based platforms, the service providers could seamlessly integrate VLMGuard to automatically examine the maliciousness of the user prompts before model inference and information delivery to users. Such red-teaming efforts will enhance the reliability of AI systems in the current foundation model era.

Limitations. Our new algorithmic framework aims to detect malicious inputs of VLMs by harnessing the unlabeled user-shared prompts in the open world, and works by devising a scoring function in the representation subspace for estimating the maliciousness of the unlabeled instances. While VLMGuard shows good detection performance on optimization-based threat models, it is not clear how the proposed approach will work for the other malicious data, such as detecting the overlaying harmful text in the input images, etc., which is a promising future work. Another promising direction could be considering and mitigating the distribution shift between the unlabeled user data and the test-time samples using out-of-distribution detection techniques (Du et al., , , ; Xie & Du, ; Du et al., , , , , , ; Lan et al., ; Liu et al., ; Yang et al., , ; Zhang et al., ; Tao et al., ; Issaka et al., ).

## Appendix G Software and Hardware

We run all experiments with Python 3.8.5 and PyTorch 1.13.1, using NVIDIA RTX A6000 GPUs.

## Peer Reviews

confidence: 3
contribution: 3
initial_rating: 6
presentation: 3
questions: - Given your geometric intuition about malicious samples "malicious samples may occupy a small subspace within the activation space":
  - Could you provide formal conditions under which this property is guaranteed?
  - How does this property relate to the VLM's training objectives?
soundness: 3
strengths: - New Problem Definition:
  - The paper presents a practical solution to reduce dependency on labeled data, which is particularly valuable because manually labeling malicious prompts is time-consuming and expensive.

- Technical Approach:
  - The proposed maliciousness scoring mechanism uses VLM's internal representations, which is computationally efficient as it requires only a single forward pass.
  - The scoring function $\kappa_i = \frac{1}{k} \sum \left( \lambda_j \cdot \langle f_i, v_j \rangle^2 \right)$  combines information from multiple principal directions, making it more robust than single-direction approaches.
  - The framework can be easily integrated into existing VLM systems since it doesn't require architectural modifications.
summary: This paper addresses a challenge in VLM security in VLM security - detecting malicious prompts without requiring labeled data. The key innovation lies in analyzing unlabeled user data through subspace analysis of VLM representations. While the approach shows promising results, several fundamental questions about its theoretical foundation and practical applicability need to be addressed.
weaknesses: - The authors offer some geometric intuition and empirical validation, but the theoretical foundation could be clearer in a few areas:
  - The choice of SVD subspace analysis, while effective empirically, lacks a solid theoretical basis to confirm its effectiveness in detecting malicious patterns.
  - The current geometric explanation would be stronger with a formal analysis showing why this property holds across different types of attacks.


- The authors use the common approach of last-token embeddings, but there are still a few questions:
  - How does information from earlier tokens affect detection?
  - What properties of the last token make it particularly suitable?
  - How robust is this choice across different prompt structures?

---

confidence: 4
contribution: 2
initial_rating: 3
presentation: 2
questions: Please refer to the weaknesses section.
soundness: 2
strengths: - This paper focuses on a critical safety issue: the misuse of VLMs through malicious or adversarial user inputs. This topic is increasingly important due to the growing popularity and widespread deployment of VLMs.

- VLMGuard introduces an interesting approach by utilizing unlabeled user inputs to enhance the detection of malicious content. This method presents a promising and effective solution to the problem.
summary: This paper introduces a defensive framework called VLMGuard, designed to safeguard Vision-Language Models (VLMs) from malicious user inputs. VLMGuard approaches malicious prompt detection as a binary classification task, operating within the VLM's latent space. It identifies prompts that fall into a subspace defined by the latent vectors of known malicious prompts, effectively flagging them as toxic or jailbreaking attempts.
weaknesses: 1. **The motivation behind VLMGuard is unclear.** While it is purportedly designed for VLMs, the integration of VLM concepts into the method is not evident. VLMGuard appears to function as a general binary classifier using extracted latent features applicable to any deep neural network. The lack of a clear rationale and organized presentation diminishes the method's potential significance.

2. **The presentation is wordy and lacks informativeness.** The introduction fails to provide an overarching view of the method. Additionally, Figure 1 lacks annotations necessary for reader comprehension.

3. **There is insufficient discussion of novelty and technical contributions.** Although the authors highlight that VLMGuard requires no labeled data, it seems to rely on latent vectors of known malicious prompts. Furthermore, as indicated by Eqs 5, 6, and Figure 2, the solution resembles an SVM approach [a1]. The authors should clarify the novelty and contributions compared to existing methods.

[a1] M. A. Hearst, S. T. Dumais, E. Osuna, J. Platt, and B. Scholkopf, "Support vector machines," IEEE Intelligent Systems, vol. 13, no. 4, pp. 18-28, July-Aug. 1998, doi: 10.1109/5254.708428.

4. **There is a lack of comparison with closely related baselines.** The authors should compare their method with state-of-the-art content moderation solutions, such as Aegis [a2], LlamaGuard [a3], LlamaGuard2 [a3], LlamaGuard3 [a4], and OpenAI-Moderation [a5].


[a2] https://arxiv.org/abs/2404.05993
[a3] https://arxiv.org/abs/2312.06674 
[a4] https://arxiv.org/abs/2407.21783  
[a5] https://arxiv.org/pdf/2208.03274

5. **(minor) Figure 1 is misleading.** While the paper does not evaluate any of OpenAI's VLMs, it uses the OpenAI logo, potentially confusing readers. This should be corrected to accurately reflect the VLMs used in the evaluation.

---

confidence: 4
contribution: 3
initial_rating: 5
presentation: 3
questions: Listed in the weakness of the paper. 

Score can be improved if concerns listed above are resolved.
soundness: 3
strengths: - This paper explores the defense in VLM malicious generations, giving a good reference to the research on this aspect.

- The proposed method VLMGUARD is simple but effective to achieve the defense, and the good performance obtained by the experiments strongly supports this point.

- The ablation study is organized well to clearly demonstrate the whole proposed method. And it makes the paper easy to follow.
summary: Vision-language models (VLMs) are crucial for understanding visual and textual information but are vulnerable to adversarial inputs, which can compromise their reliability in applications. Detecting these malicious prompts is essential to maintain trust in VLM outputs. A significant challenge is the limited availability of labeled benign and malicious data for developing effective classifiers.

To tackle this, the paper introduces VLMGUARD, a novel framework that utilizes unlabeled user prompts from real-world deployments for malicious prompt detection. These prompts contain both benign and malicious information. The approach includes an automated maliciousness estimation score to differentiate between benign and malicious samples within this unlabeled dataset, allowing for the training of a binary prompt classifier without requiring additional human annotations.

Extensive experiments demonstrate that VLMGUARD achieves superior detection performance, significantly surpassing existing state-of-the-art methods, thus offering a flexible and practical solution for real-world applications.
weaknesses: - I am curious about why the binary classifier outperforms the direct use of the maliciousness score for detection, as illustrated in Fig. 4. The training dataset is based on an unlabeled dataset that has been annotated with maliciousness scores. Consequently, the accuracy of the binary classifier relies on the quality of these annotations, which in turn depends on the effectiveness of the maliciousness score detection. This raises the question: **is the upper bound of the binary classifier's performance essentially limited by the accuracy of the maliciousness score detection?** However, the results in Fig. 4 contrasts this view.

- I noticed that the values for $\pi$ are chosen from the set {0.001, 0.005, 0.01, 0.05, 0.1} as stated in Section 4.1. Is it possible for the proportion of malicious prompts to be higher, perhaps 0.5 or more? I am interested in understanding whether the proposed defense mechanism remains effective when faced with such a higher rate of malicious prompts.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: The biggest issue I see is related to Weakness 2.

Relation to Adversarial Images:The relationship between this work and adversarial images needs further clarification. While malicious prompts are discussed, there seems to be some overlap with the concept of adversarial examples, especially when dealing with adversarial attacks on the visual input. Could the authors elaborate on how their approach relates to or differs from traditional adversarial attack detection.

Applicability Beyond Multimodal Models:The method proposed in this paper does not seem inherently restricted to multimodal models. Would the authors agree that this approach could also be applied to unimodal models, such as those in CV or NLP? For instance, could this method be adapted for adversarial attack detection in CV models, where the "jailbreak" prompts are replaced by adversarial attacks?
soundness: 3
strengths: Clarity and Simplicity of the Approach:
The overall idea and methodology presented in this paper are highly intuitive and easy to follow. The process of feeding inputs into the model to obtain embeddings, followed by performing SVD, and finally identifying outliers, is clear and logically structured. This clarity allows for smooth comprehension of the workflow, making the contributions more accessible to both researchers and practitioners.

Significance in Addressing a Critical Problem:
The paper addresses a critical issue in trustworthy AI: the detection and defense against malicious prompts in VLMs. The significance of this contribution cannot be overstated, as enhancing VLMs' robustness to malicious inputs is a crucial step toward ensuring reliable deployment of AI systems in real-world applications. The focus on using pseudo-labeled, unlabeled data is particularly valuable in reducing the dependency on manually labeled datasets, which is often a bottleneck in scaling robust AI solutions.

Substantial Performance Improvement:
The experimental results demonstrate considerable improvements over existing baselines, showcasing the practical impact of the proposed method. The enhancements in robustness against malicious prompts, as reflected by the increased AUROC scores in the experiments, highlight the effectiveness of the approach. This strong empirical performance further strengthens the paper's contribution.
summary: This paper presents a novel approach to defending Vision-Language Models (VLMs) against malicious prompts. The proposed method leverages the intrinsic capabilities of VLMs to assign pseudo-labels to unlabeled data, and subsequently trains a binary classifier to detect malicious prompts using this pseudo-labeled dataset. By doing so, the method significantly enhances the robustness of VLMs in detecting and mitigating malicious prompts.
weaknesses: Limited Novelty in Core Contribution:
The core contribution of this work—applying SVD to detect malicious prompts—while effective, does not appear to be particularly novel. SVD has been extensively used in anomaly detection tasks across various domains, and its direct application here may lack the originality expected in top-tier conference submissions. The paper could benefit from further emphasizing any unique insights or enhancements introduced in the specific context of VLMs and malicious prompt detection, beyond the straightforward use of SVD.

Unclear Necessity of Training the Protective Prompt Classifier:
A significant question arises regarding the necessity of the protective prompt classifier. Given that the proposed “maliciousness estimation in the latent subspace” seems capable of distinguishing malicious samples effectively, the added step of pseudo-labeling and training a binary classifier may seem redundant. The paper could have provided stronger justification for why the classifier is needed, beyond simply determining the decision threshold \tau. It would strengthen the contribution if the authors could clarify whether the classifier introduces additional benefits in terms of generalization or robustness that are not achieved by the latent subspace estimation alone. Without this clarification, the added complexity might appear unnecessary.


**Post-Rebuttal**:

The authors have not addressed my concerns regarding the necessity of training a classifier. Overall, the paper attempts to implement some simple functions using complex modules, lacking true innovation. I am inclined to rate it between 5 and 6.