ShieldCLIP: Selective Safety Alignment for Harmful Content in Multimodal Foundation ModelsShieldCLIP: Selective Safety Alignment for Harmful Content Mitigation in Multimodal Foundation Models
The authors propose ShieldCLIP, which selectively aligns the CLIP encoder according to modality safety states, and construct the ViSUv2 dataset; the authors state that it reduces harmful outputs in retrieval, SD v1.4/SDXL generation, and LLaVA.
Defenders finetune CLIP-like multimodal encoders at the pre-decoding stage to suppress harmful associations in text and images while preserving benign semantics; the victim systems are retrieval, text-to-image (SD v1.4, SDXL) and image-to-text (LLaVA) pipelines that reuse the same CLIP backbone, with unsafe prompts or images as input.
- The shared embedding space of CLIP-like multimodal encoders contains harmful associations, which drive downstream retrieval and generation systems to produce inappropriate content; existing paired data labels all generated samples as unsafe, and the authors report that 39% of the generated pairs in their collected data mix safe and unsafe modalities, so uniform redirection would alter benign representations.
- The authors construct ViSUv2 (195k quadruples, with independent safety annotations for text and images, 28 classes, 578 concepts) and propose ShieldCLIP: training objectives conditioned on modality safety state, anchoring safe content to a frozen CLIP, redirecting unsafe modalities to safe counterparts, updating only the unsafe branch for mixed pairs, and adding a consistency constraint when both are unsafe.
- On cross-modal retrieval, SD v1.4/SDXL text-to-image, and LLaVA image-to-text, the authors report that ShieldCLIP's harmful rate is lower than baselines such as Safe-CLIP, SafeR-CLIP, SafetyDPO, and DES, e.g., SD v1.4+I2P drops from 38.1% to 3.5%; zero-shot classification and FID/CLIP-Sim show utility close to the original CLIP.
- The authors note in Appendix D.2 that no absolute safety guarantee is provided, that the method depends on ViSUv2 annotation quality, that the predefined taxonomy cannot cover all risks, and that it may not fully transfer to downstream models with different architectures. The experiments cover two backbones, CLIP ViT-L/14 and ViT-bigG/14, and no adaptive attack evaluation is reported.
- Evaluated models
- ShieldCLIP
- Benchmarks
- ViSUv2ViSUI2PSneakyPromptMMA-DiffusionRing-A-BellNudeNetNSFW URLsSMIDCOCOFlickr30kCIFAR-10CIFAR-100SUN-397Food-101Caltech-101Imagenette
- Metrics
- harmful generation rateharmful retrieval rate (top-1)FIDCLIP-Simzero-shot top-1 accuracyVendi-ScoreSelf-BLEU
The research proposes ShieldCLIP, the first framework to condition safety alignment on each modality's own safety state rather than the sample's source, redirecting only unsafe parts while preserving safe content. The authors also release the ViSUv2 dataset, containing 195k quadruples, covering 578 concepts and 28 categories, with independent safety labels for each modality. Based on these labels, ShieldCLIP defines a four-way conditional objective: anchoring safe content, redirecting unsafe modalities to their corresponding safe versions, updating only the unsafe branch for mixed samples, and enforcing consistency when both modalities are unsafe. On cross-modal retrieval, text-to-image generation with Stable Diffusion v1.4 and SDXL, and image-to-text generation with LLaVA, ShieldCLIP consistently reduces harmful outputs compared to prior safety-aligned encoders and strong mitigation baselines, while preserving utility in the original embedding space. Ablation studies show that both modality-specific supervision and the selective alignment objective contribute.
Related events and news
1 events · 0 news mentions
- This event's paper
ShieldCLIP:多模态基础模型选择性安全对齐框架
Paper analysis
What problem does this paper attempt to solve?
How to suppress harmful associations in CLIP-like encoders without damaging benign representations; the authors consider it a core flaw that existing paired data treats all generated samples as unsafe.
Core question: how to suppress harmful associations in the shared embedding space of CLIP-like multimodal encoders without unnecessarily changing benign representations.
- Problem setting and importance: encoders such as CLIP support downstream systems including retrieval, text-to-image, and visual dialogue, but their web-scale training data contains harmful associations; unsafe prompts or images can be projected into harmful regions of the embedding space, causing downstream pipelines to produce inappropriate content (authors' view). Intervening at the encoder level can benefit multiple downstream systems without modifying each decoder individually.
- Shortcomings of existing methods: due to ethical and practical constraints, real unsafe content cannot be collected at scale, so existing paired data rewrites safe samples into unsafe variants and then labels the entire pair as unsafe; the authors report that in their collected data, 39% of generated pairs mix safe and unsafe single modalities, and uniform redirection would alter benign representations and introduce conflicting supervision.
- Core observation: generated provenance does not equal harmful—a caption rewritten around a harmful concept may be paired with a harmless image, and a benign caption may be paired with a disturbing image; the authors report that among generated pairs, 8.8% are both-safe, 52.3% are both-unsafe, and 38.9% are mixed, i.e., 47.7% of the generated data would receive incorrect supervision under the "generated means harmful" assumption.
- What the paper proposes: ShieldCLIP, a selective safety alignment framework that conditions retention and redirection on each modality's observed safety state (rather than sample provenance); and the ViSUv2 dataset (195k quadruples, 28 classes, 578 concepts, independent per-modality annotations).
- Defense positioning (threat model):
- Defense stage: pre-decoding stage, finetuning the CLIP text and image encoders (LoRA) without changing downstream decoders.
- Protected targets: retrieval, text-to-image (SD v1.4, SDXL), and image-to-text (LLaVA) systems that reuse the same CLIP backbone.
- Inputs addressed: unsafe text prompts and unsafe images.
- Relied-upon assumption: safety is operationalized via a taxonomy of 28 concept proxies, and the authors acknowledge that "safety" has no closed definition.
What related research exists?
Related work splits into two lines: mitigation techniques and datasets; the authors position this paper as one branch of pre-decoding encoder-level methods that "govern what gets redirected."
Decoding-time mitigation methods
- Model editing (ESD (Gandikota et al., 2023), UCE (Gandikota et al., 2024), SalUn (Fan et al., 2024), SPM (Lyu et al., 2024), Receler (Huang et al., 2024), etc.): finetune the U-Net or modify cross-attention layers to erase concepts. The paper notes that such methods may over-suppress related but benign concepts, and usually require retraining or separate finetuning for each new concept.
- Inference guidance (SLD (Schramowski et al., 2023), H. Li et al., 2024): guide sampling with latent-space directions or classifier-free guidance without changing weights; the paper states that they are lightweight and reversible but have weaker robustness to ambiguous prompts and limited controllability.
Pre-decoding and encoder-level methods
- Latent Guard (R. Liu et al., 2024), Embedding Sanitizer (Qiu et al., 2024), DES (Ahn & Jung, 2025), SafeText (Y. Hu et al., 2025), PromptGuard (Yuan et al., 2026): filter or finetune text representations so that unsafe prompts are shifted while safe prompts remain unchanged.
- Safe-CLIP (S. Poppi et al., 2024, the authors' prior work): extends encoder-level alignment to multimodal, applying pair-level supervision to safe and unsafe image-text pairs, treating all generated samples as unsafe.
- HySAC (T. Poppi et al., 2025) and SafeR-CLIP (Yousaf, Fioresi, et al., 2026): the former organizes safe/unsafe content with hyperbolic geometry, the latter brings each unsafe concept close to the nearest safe alternative to recover zero-shot accuracy; the paper states that both govern "where unsafe content is sent," whereas ShieldCLIP governs "what is redirected."
Harmful content mitigation datasets
- Text: I2P (Schramowski et al., 2023, 4.7k real web prompts), SneakyPrompt (Yang, Hui, et al., 2024, about 200 jailbreak prompts), Ring-A-Bell (Tsai et al., 2024), MMA-Diffusion (Yang, Gao, et al., 2024), CoPro (R. Liu et al., 2024, structured text pairs of 578 concepts). The paper notes that they have only a single safety label and lack one-to-one safe-unsafe multimodal pairs.
- Multimodal: ToViLaG, MM-SafetyBench, VLSBench, UnsafeBench, CoProV2, NSFW-Caps; the paper states that none of them provide aligned multimodal pairs with per-modality annotations. ViSU (S. Poppi et al., 2024) is the closest, but treats all generated data as unsafe and has only 20 classes.
Baselines and benchmarks: the baselines compared in the experiments include SLD-Strong, ESD, SPM, UCE, SalUn, Receler, Embedding Sanitizer, Safe-CLIP, SafeR-CLIP, SafetyDPO, DES, HySAC; the evaluation benchmarks include I2P, ViSU, ViSUv2, SneakyPrompt, MMA-Diffusion, Ring-A-Bell, NudeNet, NSFW URLs, SMID.
The authors position this paper as: retaining the pre-decoding, encoder-level form, but refining the supervision granularity from pair level to modality level, and state that ShieldCLIP is "the first framework" to condition safety alignment on modality safety state (per the authors).
How does the paper address this problem?
ShieldCLIP uses ViSUv2's per-modality safety labels to condition retention and redirection on four safety states, combining cosine alignment and bidirectional InfoNCE into five loss terms.
Overall approach: first use an LLM and a diffusion model to generate paired data with per-modality safety labels from real safety image-text pairs (ViSUv2), then use ShieldCLIP to conditionally combine retention (anchoring to a frozen CLIP) and redirection (pulling toward safe counterparts) objectives according to modality safety state, and LoRA-finetune the encoders.
Problem formulation
- Objective: for any modality encoder E ∈ {T, V}, require E(x̄) ≈ E(c(x̄)) ≈ E0(c(x̄)), i.e., the ideal encoder maps input x̄ to the embedding of the frozen oracle encoder E0 on the "cleaned" input c(x̄); safety is operationalized via a concept-proxy taxonomy.
- Data structure: each sample is a quadruple—a real pair (v, t) (safe) and a generated pair (v̄, t̄), where the generated text and image each carry independent labels f_t, f_v ∈ {0,1}, describing the same scene.
ViSUv2 dataset construction
- Text generation: use LLaMA-3.1-8B with output prefilling to rewrite COCO/Flickr30k safe captions according to sampled NSFW concepts; first compute CLIP similarity between the caption and 578 CoPro concepts, keep the 50 most similar and then uniformly sample one to guide the rewrite. After rewriting, use LLaMA-3.1-8B to classify safe/unsafe.
- Image generation: select the generator by caption—LLaMA-3.1-8B judges whether the caption implies nudity; if so use the uncensored FLUX, otherwise use NewRealityXL (an SDXL finetuned variant); images are jointly labeled with NudeNet and Q16, and if either judges NSFW it is labeled unsafe.
- Taxonomy: expanded from ViSU's 20 classes to 28 classes; CLIP-ViT-L/14 embeddings are used to cluster the 578 CoPro concepts into 30 clusters, the 8 clusters farthest from the original 20 classes are taken, and ChatGPT assists in naming them (e.g., discrimination); concept-to-class is a many-to-many mapping.
- Scale and splits: 195k quadruples (30k from Flickr30k, 165k from COCO), 8,000 test, 8,000 validation, 179,000 train; the generated-pair distribution is 8.8% both-safe, 52.3% both-unsafe, 8.4% safe text/unsafe image, 30.5% unsafe text/safe image.
- Quality control: on 1,000 generated pairs, 20 annotators (3 per sample, majority vote) verified the automatic labels, with 86% agreement for text and 81% for images (Appendix A.3).
ShieldCLIP conditional objectives
- Basic components: cosine alignment loss Lcos(X,Y) = −1/m∑i cos(xi, yi) (used for retention and redirection) and bidirectional InfoNCE (used for cross-modal alignment), both applied conditioned on batch subsets such as R, Ts, Tu, Vs, Vu, with stop-gradient on the oracle branch.
- Retention: real pairs and generated safe modalities are each aligned to anchors from the frozen oracle (T0, V0) (L_real_pres, L_gen-safe_pres), and when both are safe, cross-modal InfoNCE is added.
- Redirection: generated unsafe modalities are pulled toward the anchor of the corresponding real safe sample with the cosine loss (L_redir); mixed pairs use cross-modal InfoNCE to align the unsafe side to the safe side while freezing the safe branch (L_mix); when both are unsafe, L_coh is added to keep the two modalities semantically consistent.
- Total objective: L is a weighted sum of five terms, with λ = (0.1, 0.1, 0.1, 0.25, 0.25) corresponding to (λreal, λsafe, λredir, λmix, λcoh).
Training details
- Backbones and parameters: ViT-L/14 (corresponding to the SD v1.4 text encoder) and ViT-bigG/14 (SDXL's other text encoder) are finetuned separately; LoRA rank r=16 is added to all Transformer layers, and all oracle parameters are frozen.
- Optimization settings: Adam, constant learning rate 1×10⁻⁴, at most 50 epochs, early stopping by recall (patience 5); ViT-L/14 uses 8 A100s (batch 16 per card), ViT-bigG uses 16 cards (batch 8 per card, gradient accumulation 2 steps).
What experiments did the paper conduct?
Comparing against 11 baselines on three task types—retrieval, text-to-image, and image-to-text—the authors report that ShieldCLIP has the lowest harmful rate while maintaining utility close to the original CLIP.
Experimental Setup
- Subjects under test: ShieldCLIP (two backbones, ViT-L/14 and ViT-bigG/14), with downstream systems SD v1.4, SDXL (text-to-image), LLaVA (LLaMA-2-13B variant, image-to-text), and CLIP retrieval.
- Baselines: SLD-Strong, ESD, SPM, UCE, SalUn, Receler, Embedding Sanitizer, Safe-CLIP, SafeR-CLIP, SafetyDPO, DES, HySAC (retrieval only).
- Datasets: I2P (all prompts), the NSFW subset of the ViSUv2 test set, ViSU, SneakyPrompt, MMA-Diffusion, Ring-A-Bell; image-to-text and retrieval use 1,000 unsafe images each from NudeNet, NSFW URLs, and SMID (retrieval adds LAION-400M safe distractors).
- Metrics and judgment: harmful generation/retrieval rate (lower is better); images are judged jointly by NudeNet+Q16 (harmful if either judges NSFW), with LlavaGuard used for independent re-checking; text is judged jointly by LLaMA-3.1-8B and GPT-3.5 Turbo.
- Sampling: 5 random seeds per prompt for text-to-image, averaged over prompts and then over categories.
- Utility metrics: FID and CLIP-Sim (30k COCO validation samples), zero-shot top-1 accuracy on 6 datasets.
Main Results
Text-to-image harmful generation rate (%, NudeNet+Q16 judgment, per Table 2; Avg is the average across categories):
Swipe horizontally to read the table
Model SD v1.4 I2P SD v1.4 ViSUv2 SDXL I2P SDXL ViSUv2 Original SD 38.1 25.4 33.6 33.4 SLD-Strong 11.8 4.1 not reported not reported Safe-CLIP 21.8 6.1 8.2 2.0 SafeR-CLIP 16.8 7.5 not reported not reported SafetyDPO 11.4 2.8 8.7 4.4 DES 3.9 1.1 16.3 5.3 ShieldCLIP 3.5 1.0 4.6 1.4 - The authors state that ShieldCLIP achieves the lowest average harmful rate on both backbones and both datasets; the SDXL part of Table 2 does not list rows for SLD-Strong, SalUn, Receler, or SafeR-CLIP.
- Exceptions: in Table 2, on SDXL+I2P, Safe-CLIP's Sex category is 3.7 and ShieldCLIP's is 1.7, but on SDXL+ViSUv2 ShieldCLIP's Hate is 2.0, which is higher than DES's 3.6 and tied with Safe-CLIP's 2.0; category by category, ShieldCLIP is not lowest in every cell (e.g., SD v1.4+I2P Sex is 1.8, higher than DES's 1.0).
- Other prompt sources (Table 3): on SD v1.4, ShieldCLIP is 1.2, 1.1, 1.3, and 0.0 on ViSU, SneakyPrompt, MMA, and Ring-A-Bell respectively, which the authors call best or tied-best on four datasets; on SDXL it is 1.7, 0.0, 0.7, and 3.7, which the authors call best or tied-best on three of four, with ViSU 0.1 percentage points from the best.
Independent Classifier Re-check (LlavaGuard)
- What was tested: LlavaGuard does not participate in data construction or training and is used to test whether the gains depend on the classifier used in the annotation pipeline (Tables 4, 5).
- Results: On SD v1.4, ShieldCLIP's average harmful rate on I2P/ViSUv2 is 1.8/0.3 (Safe-CLIP 11.5/2.5, DES 2.1/0.5); on SDXL it is 1.8/0.4 (Safe-CLIP 3.1/0.9). In Table 5, SD v1.4's four sources are 0.5, 0.6, 0.1, and 1.3, and SDXL's are 1.5, 0.0, 0.4, and 0.0.
- Authors' interpretation: the authors state that the gains are not specific to the classifier used to construct ViSUv2.
Image-to-Text (LLaVA) and Retrieval
- Image-to-text (Table 7): 1,000 unsafe images per source are fed into LLaVA; ShieldCLIP has the lowest harmful description rate on NudeNet and NSFW URLs (12.5, 6.2, versus Safe-CLIP 14.6/7.5, SafeR-CLIP 17.4/10.2, original LLaVA 58.6/32.4); on SMID, SafeR-CLIP is lowest (2.2) and ShieldCLIP is 2.5.
- Retrieval (Table 8): in the T2I direction, the ViSUv2 harmful rate drops from CLIP's 95.2 to 3.5 and ViSU from 90.9 to 14.4; in the I2T direction, ViSUv2 is 20.8 and ViSU is 22.6; on the three real-image sources, both directions are ≤0.4. SafeR-CLIP reaches 70.3/53.0/52.7 in the I2T direction on NudeNet/NSFW URLs/SMID, which the authors call a directional imbalance, whereas ShieldCLIP is low in both directions.
- Exception: in the I2T direction, on ViSUv2 SafeR-CLIP (23.1) is higher than ShieldCLIP (20.8), but on ViSU SafeR-CLIP (17.7) is lower than ShieldCLIP (22.6).
Human Evaluation
- Setup: 20 annotators, 1,200 pairwise comparisons (ViSUv2 test-set prompts, 400 pairs each for Safe-CLIP/SafeR-CLIP/SafetyDPO), blind evaluation on two criteria, safety and content preservation, with ties split evenly (Table 6).
- Results: the preference rates of the three opponents over ShieldCLIP—safety 11.9/11.4/10.2, content preservation 23.5/26.2/22.1 (the values are the proportion preferring the opponent, i.e., ShieldCLIP's preferred proportion is higher).
Other Ablations and Analyses
- Data vs. objective (Table 9): with data fixed, ShieldCLIP outperforms Safe-CLIP in most settings; the exception is Safe-CLIP+ViSUv2 on ViSUv2 I2T at 15.2, better than ShieldCLIP's 20.8, but the same model on ViSU I2T is 59.9 (ShieldCLIP 22.6).
- Modality supervision ablation (Table 10): treating all generated samples as unsafe, treating mixed pairs as doubly unsafe, removing L_coh, and removing L_mix while applying L_coh to all pairs—all four variants worsen every metric, with the last degrading the most.
- Loss form (Table 11): with cosine loss only, the T2I harmful rate is 0.0 but I2T rises to 100.0, FID 80.3, CLIP-Sim 0.096; the authors state that cosine alignment is insufficient to preserve cross-modal geometry.
- Weight sweep (Table 11): from preservation-leaning to redirection-leaning, the safety improvement is accompanied by FID rising from 15.1 to 19.6 and CLIP-Sim dropping from 0.258 to 0.241; the chosen λ is the compromise point.
- Utility preservation (Tables 12, 13): zero-shot top-1 is no lower than original CLIP on CIFAR-100 (64.0 vs CLIP 60.7) and Caltech-101 (74.8, tied), and beats SafeR-CLIP on five of six datasets; on SD v1.4, FID changes from 14.7 to 17.8 and CLIP-Sim from 0.266 to 0.255, and on SDXL FID goes from 13.0 to 17.4.
- Failure cases (Appendix C.2, Fig. C9): the authors report that when unsafe semantics are entangled with the core scene description, or when the generative backbone has a strong prior for certain harmful concepts, harmful elements can only be partially suppressed.
What are some points that can be further explored?
The authors list four limitations in Appendix D.2; the experiments cover two CLIP backbones and three task types, and no adaptive attack evaluation is reported.
Limitations and future directions noted by the authors
- No absolute guarantee (Appendix D.2): the method provides no absolute guarantee against unsafe generation or retrieval, and may fail in edge cases where harmfulness is ambiguous or visual and textual cues interact in unexpected ways.
- Dependence on annotation quality (Appendix D.2): the effectiveness of selective alignment depends on the accuracy and balance of ViSUv2 labels; residual bias or annotation errors may propagate into the finetuned embedding space.
- Limited taxonomy coverage (Appendix D.2): a predefined harmful-content taxonomy cannot cover all risks or manifestations of offensiveness.
- Transferability uncertain (Appendix D.2): it may not fully transfer to downstream models with different architectures or decoding strategies.
- Future directions (Appendix D.2): expand the diversity of safety concepts, explore human-in-the-loop refinement, and develop adaptive alignment mechanisms that can adjust dynamically as the definition of "harmful" evolves.
- Ethical qualification (Appendix D.1): the authors state that "safety" is a context-dependent concept, alignment decisions may not generalize to all cultural or linguistic domains, and ShieldCLIP is only "a complementary step toward safer multimodal systems" rather than a final solution.
Scope of experimental coverage
- The encoder backbones tested are two: CLIP ViT-L/14 and ViT-bigG/14; downstream systems cover SD v1.4, SDXL, LLaVA (LLaMA-2-13B variant), and CLIP retrieval.
- Safety judgment relies on automatic classifiers (NudeNet+Q16, LlavaGuard, LLaMA-3.1-8B, GPT-3.5 Turbo, GPT-4); human evaluation consists of 20 annotators and 1,200 pairwise comparisons; the paper does not report agreement between automatic and human judgments on downstream tasks.
- Text-to-image evaluation uses 5 seeds per prompt; image-to-text and retrieval use 1,000 images per source; the paper does not report variance across multiple training runs or statistical significance tests.
- Robustness evaluation covers adversarial prompt sources such as SneakyPrompt, MMA-Diffusion, and Ring-A-Bell; the paper does not report evaluation of adaptive attacks against ShieldCLIP itself (i.e., attacks specifically constructed by an attacker who knows the defense mechanism).
- Human-machine agreement for data annotation is 86% for text and 81% for images (1,000 pairs, 3 annotators per sample).
Summarize the main content of the paper
ShieldCLIP selectively aligns the CLIP encoder according to the safety status of each modality, and together with the 195k quadruple dataset ViSUv2, the authors report that its harm rate on three types of tasks is lower than all baselines.
A defense paper on safety alignment of multimodal encoders, an extended version of the authors' prior work Safe-CLIP.
- Problem addressed: the shared embedding space of CLIP-like encoders contains harmful associations, and existing paired data labels all generated samples as unsafe; the authors report that 47.7% of the generated pairs in their data are not doubly unsafe, and uniform redirection would alter benign representations.
- Method highlights: construct ViSUv2 (195k quadruples, 28 categories, 578 concepts, independent safety annotation for text and images, human-verified agreement 86% for text and 81% for images); ShieldCLIP conditions the objective on four modality safety states—safe content anchored to frozen CLIP, unsafe modalities redirected, mixed pairs update only the unsafe branch, doubly unsafe adds a consistency constraint—fine-tuned with LoRA (r=16).
- Text-to-image results: on SD v1.4, the I2P harmful rate drops from 38.1% to 3.5% and ViSUv2 from 25.4% to 1.0% (NudeNet+Q16, Table 2); re-checking with the independent classifier LlavaGuard shows a consistent trend (1.8%/0.3%, Table 4).
- Retrieval and image-to-text: the ViSUv2 T2I retrieval harmful rate drops from 95.2% to 3.5% (Table 8); LLaVA's harmful description rate on NudeNet images drops from 58.6% to 12.5% (Table 7).
- Utility and ablations: zero-shot accuracy beats SafeR-CLIP on five of six datasets and is no lower than original CLIP on two (Table 12); ablations show that removing modality-level supervision or the mixed-pair-specific term both worsen results (Table 10).
- Authors' conclusion: the authors state that handling safety supervision by modality rather than by sample source is more balanced than uniformly redirecting generated content; they also acknowledge that the method provides no absolute guarantee, depends on annotation quality and a predefined taxonomy, and may not transfer to different architectures (Appendix D.2). The authors plan to release code, models, and controlled access to ViSUv2.