TRI3D NSFW Filter v5.1.0
Auto-swap flagged images for a safe alternative — Stability's own safety checker, in a node
- image
- alternate_image
- IMAGE
If you're running a ComfyUI workflow in any kind of shared or client-facing setting, sometimes you want a guard: if a generated image comes out NSFW, swap it for a safe placeholder before it gets saved or shown. tri3d_NSFWFilter is that guard, using the same safety checker that ships in the original Stable Diffusion pipeline - the CLIP-based classifier that flags content against a fixed list of concept embeddings.
What it does
Three inputs: image (the images to screen), alternate_image (the safe replacement to use when something gets flagged), and sensitivity, a float from 0 to 1, default 0.5, which tunes how aggressive the flagging is. The output is an IMAGE batch - the same as the input, except every flagged frame has been replaced by the alternate image, resized to match.
Under the hood it's the CompVis stable-diffusion-safety-checker: a CLIP vision model whose embeddings are compared by cosine similarity against 17 "concept" embeddings and 3 "special care" embeddings. The sensitivity slider maps 0–1 onto an offset applied to the classification threshold (roughly -0.1 + 0.14 × sensitivity), so lower values flag more content, higher values flag less. On first use it downloads model.safetensors and the processor config from Hugging Face into the pack's safetychecker folder - a one-time download, and it needs network.
A few honest notes:
- It's a classifier, not a judge. This is the exact same heuristics that annoyed people in early SD pipelines - it has known blind spots and known false positives, and it only knows the concepts baked into its weights. Treat it as a coarse filter, not a content policy.
- The swap is all-or-nothing. A flagged frame is entirely replaced by the alternate image. If you'd rather blur, pixelate, or black-bar, you'll need to do that yourself on the side.
- Batch-friendly. It scores each image in the batch and replaces only the flagged ones, leaving the rest untouched.
When it's worth it
Client work, public demos, unattended batch runs where nobody's watching the preview - places where "let something through by accident" is worse than "occasionally swap out a false positive". For personal use it's mostly a curiosity; you know what you generated.
Installing
ComfyUI Manager (search "tri3d"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes
Install requirements (pip install -r custom_nodes/tri3d-comfyui-nodes/requirements.txt) - this node needs transformers and kornia in addition to the pack's base deps. First run downloads the safety-checker model, so give it a moment.
Troubleshooting
- First run errors mid-download - the model pull failed. Re-run; if it persists, check the
safetychecker/folder for a partial download and network access to Hugging Face. - Too many/too few swaps - adjust
sensitivitytoward 0 (stricter) or 1 (more lenient). Note the mapping is subtle; a big behavior change usually needs a large slider move. - Alternate image looks stretched - it's resized to each flagged frame's dimensions, so a mismatched aspect ratio gets warped. Use a placeholder that's roughly the right shape.
A blunt instrument with a real purpose. Set the sensitivity once, wire a decent placeholder in, and let it watch the door.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| alternate_image | IMAGE | — | |
| sensitivity | FLOAT | 0.50–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |