InGuard: A general-purpose internal guardrail for safe text-to-image generationInGuard: Towards Generalized Inner Guardrail for Safe Text-to-Image Generation
The authors propose the in-pipeline T2I safety framework InGuard and the RevGen benchmark, and the authors state that it achieves a safety rate of 97.9–98.8% on five open-source models, with benign perturbation reduced by 57.5–73.5% relative to external guardrails.
Defender's perspective: users submit arbitrary prompts to open-weight T2I models, which may induce generation of porn, gore, or controlled IP character images. The defense is embedded inside the generation pipeline, working at the text encoding and denoising stages without changing base model parameters; it blocks, rewrites, or terminates midway according to risk level. The paper did not test adversarial bypass attacks.
- Open-weight T2I models generate NSFW and controlled IP content. Traditional external guardrails work outside generation: prompt classifiers are limited by small-model capacity, image checks run only after all denoising is complete, and a hit can only result in rejection.
- InGuard embeds three safety plugins into the generation pipeline: PE-MLP grades risk on text encoder embeddings, SAGE performs soft-gated projection rewriting on the embeddings of risky prompts, and the latent detector checks a one-step clean latent estimate mid-denoising. It also builds the RevGen benchmark from real-image reverse generation (10,000 prompts).
- On five open-source LDMs, InGuard achieves a safety rate of 97.9–98.8%, which the authors state matches or exceeds external guardrails; benign perturbation drops from 9.3–10.6% to 2.6–4.5%; mid-way interception saves 50–55.6% of denoising steps. SAGE enhancement success rate is higher than SAFREE on all five models.
- The authors note: SAGE depends on prompt classifier accuracy and a limited concept set, and its robustness to adversarial rewriting and multi-character IP scenarios needs improvement; it covers only three risk categories, porn, gore, and IP; latent detection needs to be extended to new generators and the video modality. Experiments cover only five open-source LDMs.
- Evaluated models
- Z-Image-TurboQwen-Image-2512HunyuanImage-2.1FLUX.2-klein-base-9BInternVL-U
- Benchmarks
- RevGen Safety BenchmarkOpenImages
- Metrics
- Safety rateBenign disturbance rateAvg F1Risk Hit RatioDINOv2-Vendi Score
Researchers propose an internal guardrail, InGuard, which matches or exceeds external guardrails with a 97.9%-98.8% safety rate on five open-weight text-to-image models. It does not modify the base parameters; it grades prompts, uses SAGE to rewrite risky prompt embeddings to return safe images rather than refusals, and terminates generation when risk is detected mid-denoising. On the RevGen Safety Benchmark with 10,000 prompts, benign perturbations are reduced by 57.5%-73.5% compared with external guardrails.
Paper analysis
What problem does this paper attempt to solve?
In-pipeline safety guardrails for open-weight T2I models: graded interception, rewriting, and mid-way detection on the model's own representations, replacing external guardrails that check after generation.
Core question: how to embed T2I safety guardrails inside the generation pipeline without changing the base model parameters, using the model's own representations to achieve a better safety–perturbation trade-off than external guardrails.
- Problem setting: open-weight T2I models (Qwen-Image, HunyuanImage, FLUX, Z-Image, etc.) can generate high-fidelity images from arbitrary prompts, but are equally prone to producing NSFW content such as porn and gore and controlled IP characters; public deployment requires safety mechanisms (per the authors).
- Shortcomings of existing external guardrails: the authors point out three — the prompt side relies on external small models (BERT, mE5), and representation capacity limits screening accuracy; image-side checks run only after all denoising is complete, so compute is already wasted when a hit occurs; under a refusal-style configuration, a hit can only lead to outright rejection, whereas many requests could have been rewritten into safe images. The common root of all three is that the guardrail cannot see the model's own representations.
- Core observation: model-internal representations such as text encoder embeddings and intermediate denoising latents already contain risk information; rewriting risky prompts at the embedding level can turn refusal into returning a safe image, and checking a clean latent estimate at one step mid-denoising can enable early termination.
- The paper proposes: InGuard, an in-pipeline safety framework (PE-MLP risk grading + SAGE embedding enhancement + latent safety detection), and the RevGen Safety Benchmark (10,000 prompts reverse-generated from real images, covering porn/gore/IP and near-boundary benign samples).
- Threat model (defender's perspective):
- Risk source: users submit arbitrary natural-language prompts, which may induce generation of NSFW or controlled IP content.
- Defender capability: access to the open-weight model's text encoder embeddings and intermediate denoising states, ability to attach plugins, without changing base parameters.
- Victim system: public applications deploying open-weight T2I models.
- The paper does not test adversarial bypass attacks against the guardrail.
What related research exists?
Related work falls into three categories: T2I safety enhancement (training-time/inference-time), safety detection (prompt/image/in-generation), and safety benchmarks; the baselines of this paper are SAFREE and the mE5+ConvNeXt external guardrail.
T2I safety enhancement
- Training-time methods: Concept Ablation [12] fine-tunes parameters to align the target concept distribution to an anchor concept; SafeGen [15] modifies U-Net self-attention to suppress sexual content; Erased Stable Diffusion [9] suppresses unsafe concepts via fine-tuning. The paper notes that such methods have model update costs and may affect semantically related benign concepts.
- Inference-time embedding-level methods: SAFREE [45] uses a hard trigger threshold to project trigger tokens out of the toxic concept subspace, requiring no training, and additionally provides Self-Validating Filtering (SVF) that switches across denoising steps; STG [21], Responsible Diffusion [16], and ItD [33] refine embeddings via step-wise gradient ascent or external safety directions, and the paper notes they have extra overhead or depend on precomputed components.
- Latent/attention-level methods: SLD [28] uses classifier-free guidance to steer latents away from unsafe regions, and the paper notes it may perturb benign outputs; SafeRoPE [43] perturbs the positional embeddings of safety-critical attention heads; CASG [39] dynamically selects class-aligned guidance to handle multi-category conflicts.
T2I safety detection
- Prompt and image side (external guardrails): The prompt side commonly uses compact encoders such as BERT [6] and mE5 [36]; the image side includes Stable Diffusion's built-in safety checker, Q16 [27], NudeNet [2], and the LAION classifier [29]. The paper notes that their target labels differ, that covering gore or controlled IP requires task adaptation, and that post-hoc detection runs only after generation is complete.
- In-generation detection: FlowGuard [42] uses linear latent decoding and curriculum learning to check intermediate denoising states and terminate unsafe generation early.
T2I safety benchmarks
- I2P [28], Ring-A-Bell [34], MMA-Diffusion [44], T2ISafety [14], Six-CD [24]: compile prompts from in-the-wild queries, adversarial transformations, or organized taxonomies, covering categories such as sexual content, violence, hate, and privacy. The paper notes that these benchmarks record what kind of risk a prompt carries rather than the severity of the risk, and that most release only risky prompts; although Six-CD releases benign prompts (a concept-deleted version and a general-corpus version), it does not target the graded near-boundary cases considered in this paper.
Baselines and positioning
- Comparison baselines: The enhancement component is compared with SAFREE; the system level is compared with external guardrails (mE5 text classifier + ConvNeXt-Base image classifier); prompt classification is compared with mE5-base and mBERT-cased. The benchmark used is the authors' own RevGen, and Tables 2 and 3 compare its diversity and risk induction rate with the five existing benchmarks above.
- The authors position this paper as follows: in contrast to external guardrails that work outside the generation pipeline, InGuard works on the model's own representations; in contrast to SAFREE's hard-threshold projection, SAGE uses continuous asymmetric soft gating; and in contrast to existing benchmarks, RevGen combines real-image grounding, graded risk annotation, and near-boundary benign negative samples (Table 1).
How does the paper address this problem?
InGuard's three components in series: PE-MLP performs three-level risk routing on text embeddings, SAGE soft-gated projection rewrites risky embeddings, and the latent detector checks a one-step clean latent estimate midway through denoising.
Overall approach: embed the safety plugin into the text encoding and iterative denoising stages of the T2I generation pipeline, completing grading, rewriting and mid-process detection on the model's own representations, without changing the base parameters. InGuard consists of three components (Figure 5).
Problem setting and the RevGen benchmark
- Risk dimensions: porn (levels 0–5), gore (levels 0–5), IP (levels 0–7; 1–5 are five controlled characters: Snow White, Doraemon, Minions, Elsa, SpongeBob SquarePants; 6–7 are associated characters and other copyrighted characters, which are benign).
- Data construction: a four-stage pipeline — real internet image pool → VLM reverse-generates Chinese-English bilingual prompts → LLM rewrites and injects IP entities (controlled IP + three types of benign variants: uncontrolled copyrighted characters, associated characters from the same series, visually similar characters) → TF-IDF + SVD + K-Means clustering with per-cluster sampling to ensure diversity; train/test split isolated by source image, MinHash-LSH deduplication.
- Scale and annotation: 10,000 prompts; annotations generated by the multimodal model Qwen3.7-Plus (temperature 1e-4), with manual spot-check accuracy above 98% on about 1,000 images (Appendix A.4).
Component one: prompt embedding risk classification (PE-MLP)
- Input: output embeddings from the T2I model's own text encoder, masked mean pooling to a fixed-length vector, no additional encoding overhead.
- Structure: a multi-task MLP with a shared backbone, three independent heads for porn/gore/IP, trained with multi-task cross-entropy on RevGen prompt embeddings.
- Routing: porn or gore reaching the per-model interception threshold τp/τg (Table 13) is directly intercepted; IP alone does not trigger interception; those reaching the enhancement threshold (porn ≥ 3, gore ≥ 2, or IP ∈ [1, 5]) enter SAGE.
Component two: SAGE embedding-space safety enhancement
- Label-gated concept subspace: 34 Chinese-English bilingual concepts (porn 13, gore 11, IP 5×2, Table 4), with the concept group dynamically selected according to the predicted risk label, constructing the projection matrix PC = C(C⊤ C)−1 C⊤, and (I − PC) projects the embedding onto the orthogonal complement of the concept subspace. Only user content tokens participate; structural tokens are left unchanged.
- Trigger detection (leave-one-out): replace tokens one by one and re-encode, using the residual distance di and the relative ratio ri to measure token toxicity; the authors state this is a heuristic score rather than a direct toxicity measure.
- Asymmetric soft-gated mixing: with δi = ri − (1 + α) as the signed distance to the threshold, an asymmetric sigmoid yields the mixing coefficient γi, p̃i = (1−γi)pi + γi p̂i continuously mixes the original embedding with the projected embedding; the authors state this eliminates the discontinuity of binary rules at the threshold, but explicitly note that the two temperature parameters do not guarantee a reduction in benign perturbations.
- Class-aware α: α is configured separately per class per model (Table 13, including negative values); when multiple classes co-occur, a single α is taken according to the fixed priority porn ≻ gore ≻ ip; the modified embedding applies to all denoising steps, with no step-by-step switching.
Component three: latent-space safety detection
- Detection target: a one-step clean latent estimate x̂1 = xt + (1 − t)·v midway through flow-matching denoising, reusing the velocity already computed by the denoiser, with no extra forward pass; detection occurs at selected steps, and a hit terminates and skips subsequent steps.
- Backbone: ConvNeXt-Base (88.6M), ImageNet-1K pretrained, with only the first-layer patchify stem replaced to accept C-channel latent input; three classification heads (porn/gore binary classification, IP as K+1 classes).
- Two-stage training: Phase A performs feature distillation on VAE-encoded latents from OpenImages (a frozen RGB teacher aligned to a latent student, with alignment at four stages S = {1,2,3,4}); Phase B fully fine-tunes on 5K–50K safety-annotated latents extracted from the RevGen generation process, with stratified sampling to balance risk groups.
- Success determination: whether an image is safe is determined by a VLM (Qwen3.7-Plus) according to image-side labels (porn = 2 or gore = 2 or IP ∈ [1, 5] is unsafe); the system safety rate counts intercepted requests as safe.
What experiments did the paper conduct?
On five open-source LDMs: PE-MLP classification outperforms mE5/mBERT, SAGE enhancement success rate exceeds SAFREE on all, system safety rate 97.9–98.8%, benign perturbation reduced to 2.6–4.5%.
Experimental Setup
- Models tested: Z-Image-Turbo, Qwen-Image-2512, HunyuanImage-2.1, FLUX.2-klein-base-9B, InternVL-U, five open-weight LDMs in total.
- Datasets: RevGen test set of 10,000 prompts (porn 0–5, gore 0–5, IP 0–7 labels); latent detector safety training pool 5K–50K; OpenImages used for Phase A pretraining.
- Baselines: prompt classification compared with mE5-base (282.0M) and mBERT-cased (181.8M); enhancement compared with SAFREE; system level compared with external guardrails (mE5 + ConvNeXt-Base image classifier, 370.6M).
- Metrics and judging: safety rate (proportion of requests whose final output is safe; interception counts as safe), benign perturbation rate (proportion of samples where both the original prompt and original image are safe that are either intercepted or judged by the VLM to have changed semantics), Avg F1 (mean F1 over the three risk categories); image safety and semantic change are judged by Qwen3.7-Plus.
- Generation settings: fixed random seed 42, each model uses its own recommended resolution (Appendix A.5); the paper does not report the number of repetitions.
Main Results
System-level comparison (per Table 8, RevGen test set):
Swipe horizontally to read the table
Model Configuration Parameters Safety rate Benign perturbation rate Z-Image-Turbo No / Outer / Inner — / 370.6M / ∼100M 50.97% / 98.18% / 98.23% — / 9.93% / 2.63% Qwen-Image-2512 No / Outer / Inner — / 370.6M / ∼100M 47.66% / 98.76% / 98.78% — / 10.63% / 4.52% HunyuanImage-2.1 No / Outer / Inner — / 370.6M / ∼100M 44.26% / 97.90% / 97.90% — / 9.33% / 3.51% FLUX.2-klein-base-9B No / Outer / Inner — / 370.6M / ∼100M 56.72% / 97.02% / 98.59% — / 10.05% / 2.81% InternVL-U No / Outer / Inner — / 370.6M / ∼100M 48.24% / 97.86% / 98.15% — / 9.45% / 3.14% - The authors state that InGuard's safety rate is on par with or 0.00–1.57 percentage points higher than external guardrails, benign perturbation is relatively reduced by 57.5–73.5%, and added parameters are about 3.7× fewer (∼100M vs. 370.6M).
- Exception: on HunyuanImage-2.1, Inner and Outer have the same safety rate (97.90%), with no improvement.
- The authors note that this system comparison does not identify the individual causal contribution of each component, and that it compares complete systems rather than classifiers at matched thresholds.
Prompt Embedding Risk Classification
- What was measured: multi-class accuracy and prompt-side false positives of PE-MLP vs. mE5 and mBERT (Table 5).
- Results: PE-MLP across the five models achieves porn accuracy 93.01–93.76%, gore 95.20–95.83%, IP 98.15–98.76%, all higher than the two external classifiers (mE5: 90.67%/93.65%/97.19%); false positives 3.80–6.56%, lower than mE5's 8.01% and mBERT's 13.08%; parameter count 5.8–15.8M.
- Authors' interpretation: by leveraging the LDM's own text encoder representations, it achieves higher accuracy with 10× fewer parameters.
SAGE Enhancement vs. SAFREE
- What was measured: enhancement success rate (proportion of originally unsafe generations judged safe after enhancement) and benign perturbation rate on the same PE-MLP labeled pool (Table 6).
- Results: SAGE success rate is higher on all five models—Z-Image-Turbo 67.0% vs. 49.2%, Qwen-Image-2512 55.9% vs. 46.7%, HunyuanImage-2.1 29.9% vs. 21.4%, FLUX.2-klein-base-9B 67.6% vs. 58.2%, InternVL-U 54.1% vs. 29.2%; perturbation rates are all lower (e.g., InternVL-U 1.2% vs. 2.6%).
- Authors' interpretation: SAGE achieves a better safety–perturbation trade-off in every comparison group; the success metric measures only risk removal, not preservation of non-risk semantics.
Latent Detection and Efficiency
- Distillation pretraining: Figure 10 shows that distillation pretraining improves Avg F1 at all pool sizes and on all models; at 50K the improvement is 0.32–1.00 percentage points, and larger at 5K (e.g., Z-Image-Turbo +3.55). On Z-Image-Turbo, 5K pretraining reaches 90.18% Avg F1, close to 90.33% for 20K without distillation.
- Detection efficiency: the deployment step is step 3 for Z-Image-Turbo, step 4 for the three 10-step models, and step 8 for InternVL-U; at the deployment point, latent detection Avg F1 is 0.26–1.71 percentage points lower than image-level detection (Figure 11); mid-way interception saves 50–55.6% of denoising evaluations. The authors note that this proportion excludes text encoding, SAGE re-encoding, classifier inference, and VAE decoding, and does not represent end-to-end latency.
- Data generation cost: pretraining data generation is 48–139× faster than fine-tuning data (Table 7, about 100–400 ms/sample vs. 5–28 s/sample on H20-3e).
Other Ablations and Analyses
- Backbone choice (Table 11, Z-Image-Turbo): ConvNeXt at various scales achieves Avg F1 91.4–92.1% at 50K without distillation, vs. 85.0–85.4% for ViT; Base (92.87%) is chosen over Large, which the authors describe as a recall-leaning choice, with a higher perturbation rate than Tiny (9.40% vs. 6.18%).
- Gating effectiveness (Table 10): at the operating threshold, PE-MLP overall recall is 95.07–98.84%, image-side false positives are 34.88–46.77%, mixed relative to mE5/mBERT.
- Benchmark diversity (Table 2): RevGen's DINOv2-Vendi is highest on three of the five models (FLUX.2-klein-base-9B 79.72, Qwen-Image-2512 58.80, InternVL-U 52.97), with T2ISafety leading on the other two.
- Risk induction rate (Table 3): for the porn category, RevGen is highest on four models (e.g., HunyuanImage-2.1 76.92%), while on FLUX.2-klein-base-9B Ring-A-Bell is higher (52.78% vs. 30.50%).
- Negative results: in Table 12, distillation pretraining worsens perturbation rate or recall at individual operating points (e.g., HunyuanImage-2.1 50K perturbation +0.82, FLUX.2-klein-base-9B 50K recall −0.67); the authors note that improvements need not hold simultaneously across all three metrics.
What are some points that can be further explored?
The authors list three directions: SAGE's dependence on the classifier and concept set, only three risk categories, and the need to extend latent detection to new generators and video.
Limitations and future directions noted by the authors
- SAGE's dependence (Section 6): label gating binds SAGE to the accuracy of the prompt classifier and a limited concept set; improving robustness to adversarial rewrites and multi-character IP scenarios is the next step. Section 4.3.4 also notes that misclassification as benign lets risky prompts bypass enhancement entirely.
- Risk category coverage (Section 6): evaluation covers only the three categories porn, gore, and IP; other policy dimensions such as hate and privacy remain to be explored.
- Scope of detection (Section 6): detection relies on a one-step latent estimate; extending to unseen generators, video generation, and other iterative synthesis processes is a future direction.
- Single-label IP head (Section 4.3.1): the IP head selects only one controlled character per prompt and cannot explicitly represent all controlled characters in multi-character scenarios.
- Lower bound on benign perturbation (Section 4.3.3): the two temperature parameters independently control the transition shape but do not guarantee reduced benign perturbation; α and temperature are operating-point parameters, not a mechanism that eliminates the safety–perturbation trade-off.
Scope of experiments
- The models tested are five open-weight LDMs: Z-Image-Turbo, Qwen-Image-2512, HunyuanImage-2.1, FLUX.2-klein-base-9B, InternVL-U (Section 5.1.2).
- The evaluation benchmark is the RevGen test set of 10,000 prompts, with risk dimensions of porn, gore, and IP (Section 5.1.1).
- The enhancement comparison uses only one baseline, SAFREE; the system-level comparison uses one external guardrail combination, mE5 + ConvNeXt-Base (Section 5.1.2).
- Image safety and semantic change judgments were both performed by Qwen3.7-Plus; manual spot-check labeling of about 1,000 images had accuracy above 98% (Appendix A.4); the paper does not report a consistency coefficient between the judge and human labels.
- The paper does not report adversarial bypass experiments, end-to-end latency measurements, or the number of generation repetitions; Table 13 gives all thresholds and α parameters.
Summarize the main content of the paper
InGuard embeds guardrails inside the T2I pipeline, achieving 97.9–98.8% safety rates on five open-source models and 57.5–73.5% lower benign perturbation than external guardrails, and includes the RevGen benchmark.
A T2I safety defense paper that proposes an in-pipeline guardrail InGuard and the RevGen Safety Benchmark built by reverse-generating from real images (10,000 prompts, porn/gore grading + IP classification + near-boundary benign negative samples).
- Problem to solve: External guardrails work outside the generation pipeline; prompt screening is limited by small-model capacity, image checks run only after all denoising is complete, and a hit can only result in rejection; the authors argue the root cause is that guardrails cannot see the model's own representations.
- Method highlights: PE-MLP performs three-level risk routing on text encoder embeddings; SAGE performs label-gated, leave-one-out trigger detection and asymmetric soft-gated embedding projection rewriting on risky prompts; the latent detector checks a one-step clean latent estimate mid-denoising and terminates early on a hit. Base parameters are untouched.
- Main results:
- System level (Table 8): safety rate 97.9–98.8% on five open-source LDMs, which the authors say matches or exceeds external guardrails; benign perturbation drops from 9.3–10.6% to 2.6–4.5% (relative reduction 57.5–73.5%), with about 3.7× fewer added parameters.
- Enhancement (Table 6): SAGE success rate is higher than SAFREE on all five models, e.g., InternVL-U 54.1% vs. 29.2%, perturbation 1.2% vs. 2.6%.
- Detection (Figure 11): at the deployment point, latent detection Avg F1 is 0.26–1.71 percentage points lower than image-level, and mid-way interception saves 50–55.6% of denoising steps.
- Classification (Table 5): PE-MLP with 5.8–15.8M parameters exceeds mE5 (282.0M) and mBERT in accuracy on every risk dimension.
- Authors' conclusions and implications: The authors argue that building guardrails on the model's own representations can simultaneously improve the safety–perturbation trade-off and save compute; they also note that SAGE depends on classifier accuracy and a limited concept set, that evaluation covers only three risk categories, and that detection needs to be extended to new modalities, leaving these for future work.