PromptGuard: Soft Prompt-Guided Unsafe Content Moderation for Text-to-Image Models

Lingzhi Yuan, Xinfeng Li, Chejian Xu, Guanhong Tao, Xiaojun Jia +5 more
1/7/2025
22 citations
cs.CVcs.AIcs.CR

No official code found. Best implementation: lingzhiyxp/PromptGuard (6 stars, Python, Apache-2.0, last commit 2026-01-26).

Abstract

Recent text-to-image (T2I) models have exhibited remarkable performance in generating high-quality images from text descriptions. However, these models are vulnerable to misuse, particularly generating not-safe-for-work (NSFW) content, such as sexually explicit, violent, political, and disturbing images, raising serious ethical concerns.

Show full abstract

In this work, we present PromptGuard, a novel content moderation technique that draws inspiration from the system prompt mechanism in large language models (LLMs) for safety alignment. Unlike LLMs, T2I models lack a direct interface for enforcing behavioral guidelines. Our key idea is to optimize a safety soft prompt that functions as an implicit system prompt within the T2I model's textual embedding space. This universal soft prompt (P*) directly moderates NSFW inputs, enabling safe yet realistic image generation without altering the inference efficiency or requiring proxy models. We further enhance its reliability and helpfulness through a divide-and-conquer strategy, which optimizes category-specific soft prompts and combines them into holistic safety guidance. Extensive experiments across five datasets demonstrate that PromptGuard effectively mitigates NSFW content generation while preserving high-quality benign outputs. PromptGuard achieves 3.8 times faster than prior content moderation methods, surpassing eight state-of-the-art defenses with an optimal unsafe ratio down to 5.84%.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

The official code for "PromptGuard : Soft Prompt-Guided Unsafe Content Moderation for Text-to-Image Models"

60Python, ShellSep 18, 202510 months agoApache-2.0

Similar Papers

Cite this paper

@article{yuan2025promptguard,
  title  = {PromptGuard: Soft Prompt-Guided Unsafe Content Moderation for Text-to-Image Models},
  author = {Lingzhi Yuan and Xinfeng Li and Chejian Xu and Guanhong Tao and Xiaojun Jia and Yihao Huang and Wei Dong and Yang Liu and Xiaofeng Wang and Bo Li},
  year   = {2025},
  eprint = {2501.03544},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2501.03544v4}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2501.03544.svg)](https://codeofpaper.com/paper/2501.03544)

Discussion