Manuscript Offprint

arXiv:2610.05908

Safe Image Generation via Reinforcement Learning

Eungyeol Han, Jong-Seok Lee

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

Abstract

Recent Text-to-Image (T2I) models achieve remarkable visual image generation performance, but they can still generate NSFW (Not-Safe-For-Work) contents, including violent or explicit images. Existing safety checker mechanisms are largely confined to pre-generation filtering (e.g. prompt-level text classifiers) or post-hoc moderation applied after an image is completely synthesized. However, adversarial attack methods operate over a much broader space. This imbalance highlights the need for a safety mechanism that intervenes during the generation process. We propose an in-generation safety framework that monitors the denoising trajectory and detects emerging NSFW signals from intermediate representations. Rather than merely detecting NSFW generations, our method applies reinforcement learning to generate safe images from NSFW prompts. By coupling in-generation detection with controllable steering, our approach mitigates unsafe trajectories even when NSFW signals emerge after generation has already begun. Experiments results show that our method consistently outperforms existing safe image generation methods across both standard and adversarial evaluation sets, while preserving perceptual quality and prompt fidelity. Code will be released upon acceptance.

Warning! This document contains sensitive images. While we censor Not-Safe-for-Work (NSFW) imagery, reader discretion is advised.

1 Introduction

Text-to-Image (T2I) models [9, 37] have achieved remarkable progress in generating high-resolution images. Despite these advances, current T2I models still exhibit critical problems regarding safety: they can generate NSFW (Not-Safe-For-Work) contents [35], including sexual and violent images as well as copyrighted or otherwise restricted materials. To mitigate these problems, a lot of research have proposed safety checkers intended to prevent models from generating NSFW contents.

However, most existing safety checker architectures remain stage-limited and passive. The most common architecture is to block generation before the denoising process begins by applying text-based filtering at the prompt level [12, 27, 30, 45], or to reject final results after generation completes by classifying the final image in pixel space [23, 35, 39]. While such approaches are practical and widely deployed, they provide only passive protection. Therefore, they are vulnerable to adversarial attacks to generate NSFW contents, which can be applied throughout the whole T2I process.

Adversarial attacks against safety checkers are increasingly multi-faceted and operate across multiple stages. Attack methods include prompt-based manipulations that evade text filters [20, 28, 44], attacks targeting the guidance mechanisms, and latent-space attacks that directly perturb the denoising trajectory [26, 35, 36]. This asymmetry between attack surfaces and defense mechanisms

∗^{*}Corresponding author.

Preprint.

Figure

(a) Pipeline with Trajectory-level Control to Generate Safe Images from NSFW prompts

(b) Latent Safety Probe for Monitoring NSFW Score, Distilled from the Frozen VAE Decoder and NSFW Detectors

Figure 1: Overall pipeline of the proposed trajectory-level safety framework.

exposes a key vulnerability: even if a safety checker is effective at one stage, an attacker can shift the attack to another stage where the defense is absent or weak.

Recent efforts have started to broaden the range of safety checkers beyond the prompt and final image. For example, Safe Latent Diffusion (SLD) [38] modifies intermediate representations by projecting latent states toward a “safe” subspace. Nevertheless, such approaches remain largely reactive and brittle because the checker operates as a one-shot safeguard, so they are vulnerable to adversarial perturbations injected after the safety applied.

Motivated by this gap, we propose the first framework that introduces an active reinforcement learning (RL) based safety checker agent that intervenes during the denoising trajectory of T2I models (Figure 1). We treat the denoising process as an RL trajectory and formulate safety enforcement as a sequential decision-making problem. At each denoising timestep, an RL agent observes the current generation state and predicts whether the ongoing trajectory is likely to produce an NSFW output. When the agent detects high NSFW risk, it intervenes online to steer the trajectory toward safe generation by guiding the noise predicted, effectively transforming the unsafe path into a safe one rather than merely blocking or rejecting the output.

This active, step-wise intervention provides three key advantages. First, even if adversarial attacks emerge after generation has already begun, the agent can still detect NSFW signals during generation and correct the trajectory before the final image is produced, providing robustness against multi-stage adversarial attacks [21, 44]. Second, unlike existing safe image generation methods that require retraining or fine-tuning the T2I model, our framework keeps the pretrained T2I model fully frozen and trains only a lightweight intervention policy, enabling plug-and-play deployment across diverse T2I architectures including both diffusion models [37] and flow matching models [9]. Third, by incorporating a terminal aesthetic reward into the policy training objective, our method explicitly preserves perceptual quality alongside safety enforcement, avoiding the quality degradation commonly observed in existing approaches. In short, our method expands safety enforcement from a passive, stage specific checker into an adaptive, trajectory-aware control mechanism that is robust to attacks occurring at any point in the T2I generation process.

References (43)