Prompting4Debugging: Red-Teaming Text-to-Image Diffusion Models by Finding Problematic Prompts

Zhi-Yi Chin, Chieh Ming Jiang, Ching-Chun Huang, Pin-Yu Chen, Wei-Chen Chiu

TL;DR

Text-to-image (T2I) diffusion models often employ safety mechanisms to prevent the generation of NSFW or copyrighted content. But how robust are these defenses? This paper introduces Prompting4Debugging (P4D), an automated red-teaming tool that uses prompt optimization to uncover vulnerabilities in these safety filters. The authors reveal that around half of the prompts previously deemed "safe" can be manipulated to completely bypass state-of-the-art defenses, highlighting a critical need for automated stress-testing before model deployment.

The Vulnerability of T2I Safety Mechanisms

T2I models like Stable Diffusion are incredibly powerful but carry the risk of generating inappropriate content, such as explicit images or copyright infringement. To mitigate this, developers deploy safety mechanisms like negative prompting, Safe Latent Diffusion (SLD), or Erasing Concepts from Diffusion Models (ESD).

However, these defenses are usually evaluated on limited, static benchmarks. Malicious users can often find "jailbreak" prompts that bypass these filters, but discovering these flaws manually is unscalable. The authors tackle the urgent need for an automated, scalable red-teaming tool to systematically stress-test T2I safety mechanisms, ensuring they don't just offer a false sense of security.

Overview of the Prompting4Debugging (P4D) framework.

How Prompting4Debugging (P4D) Works

The authors propose P4D, a framework that leverages prompt engineering to automatically find safety-evasive prompts. The method requires white-box access to two models: an unconstrained T2I model (which willingly generates unsafe content) and a safe T2I model (the target being tested).

The P4D optimization pipeline: generating an anchor, obtaining latent vectors, and optimizing a discrete prompt.

The optimization process follows three main steps:

  1. Anchor Generation: Generate an unsafe image using a known problematic prompt in the unconstrained model, extracting the intermediate noisy latent representations.
  2. Latent Optimization: Optimize a new prompt for the safe model so that its noise predictions match those of the unconstrained model. If the noise predictions match in the latent space, the safe model will generate the unsafe image, effectively bypassing its filter.
  3. Discrete Projection: Because discrete text tokens are hard to optimize via gradients, P4D optimizes continuous embeddings and projects them back to discrete words (similar to the PEZ optimization technique).

The tool features two variants:

  • P4D-N: Optimizes a sequence of $N$ tokens entirely from scratch.
  • P4D-K: Inserts learnable tokens into the original prompt (e.g., every $K$ tokens), preserving some of the original human interpretability.

Evaluation and Datasets

The researchers evaluated P4D using several datasets:

  • Inappropriate Image Prompts (I2P): Used for concept-related evaluation, specifically focusing on the "nudity" category (854 prompts) due to privacy concerns, alongside a broader set of 4,703 prompts covering hate, violence, and self-harm.
  • ESD Dataset: Used for object-related evaluation (e.g., "car" and "French-horn" classes) to test if the model can be forced to generate objects it was explicitly fine-tuned to "forget."
  • New Benchmark: The authors collected the "universal problematic prompts" discovered by P4D and released an enhanced I2P dataset to help developers test future models.

Key Insights

  • "Information Obfuscation" in Safety Filters: The authors found a fascinating parallel to "obfuscated gradients" in adversarial machine learning. Safety text filters actually restrict the search space during prompt optimization, creating a false sense of security. By turning off the safety filter during the debugging/optimization phase and turning it back on during inference, P4D was able to find significantly more problematic prompts.
  • High Transferability: Prompts optimized to break one specific safety mechanism (like ESD's fine-tuning approach) are surprisingly effective at breaking entirely different mechanisms (like SLD's guidance-based filters).
  • Prompt Dilution: The optimized prompts often look like gibberish or a random assortment of sensitive and unrelated words. This works because adding unrelated details "dilutes" the prompt, confusing the safety mechanism while still guiding the diffusion process toward the target concept.

Results and Impact

When combining both prompt variants (P4D-UNION), the tool successfully bypassed defenses on a massive scale. For the nudity category, it achieved a 66.58% failure rate against ESD, 55.29% against SLD-STRONG, and 40.98% against Stable Diffusion with Negative Prompts (SD-NEGP). P4D significantly outperformed random token insertion, word shuffling, and existing prompt optimization techniques.

Black-Box Threat: Even though P4D requires white-box access to generate the prompts, the resulting "universal" prompts successfully transferred to closed-source, black-box models. They achieved a 56.14% failure rate on SDXL and a 30.7% failure rate on Midjourney. (DALL-E 3 proved more robust, with only an 8.77% failure rate).

Limitations and Future Work

P4D requires full access to the model's weights and noise predictions (gradients) to perform latent space optimization. This makes it a great tool for developers debugging their own models, but it cannot be directly run to optimize prompts against black-box APIs. Furthermore, the optimized prompts often lack semantic meaning (reading like gibberish). While effective for red-teaming the model's latent space, they don't perfectly mimic natural human adversarial attacks. Future work aims to explore methodologies that ease the white-box constraint, allowing for automated red-teaming of massive, closed-source T2I models accessed via APIs.

Summary updated

BibTeX
@inproceedings{chin2024prompting,
  author = {Zhi-Yi Chin and Chieh Ming Jiang and Ching-Chun Huang and Pin-Yu Chen and Wei-Chen Chiu},
  title = {{Prompting4Debugging: Red-Teaming Text-to-Image Diffusion Models by Finding Problematic Prompts}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=VyGo1S5A6d},
}
Figure