ComfyUI Node

NSFWDetection

Swap out anything your classifier flags, automatically

By trumanwong·Created 3 years ago·Updated about a year ago· 50
NSFWDetection
  • image
  • alternative_image
  • IMAGE
score0.90

Here's the thing about ComfyUI: it ships with zero built-in content filtering. No safety checker, no output classifier, nothing between your sampler and your Save Image node. That's by design - it's an open graph, and whatever comes out is whatever your model and prompt produce. Which is fine right up until you're not generating for yourself anymore. You're running an API, a bot, a client-facing app, something where a stray image reaching an end user is a real problem, not a shrug. That's the gap NSFWDetection fills: it drops a classifier straight into the graph and swaps out anything it flags, automatically, no separate service to stand up.

It's a small pack with one job, and it's become something of a reference point for that job - at least one other community node (ComfyUI-NSFW-Check) explicitly credits itself as based on this one. If you search around for "how do I filter NSFW output in ComfyUI," this is usually the first thing that comes up. Worth noting the reaction it gets is often "wait, why would you want less NSFW out of ComfyUI" - fair, given how much of the checkpoint ecosystem around here leans the other way - but the answer is simple: this node isn't for your personal generation queue, it's for anyone putting ComfyUI behind something other people touch.

How it works

It's a pass-through with a trapdoor. You feed it your generated image, it runs that image through an ML classifier to get an NSFW confidence score, and it compares that score against a threshold you set. Clear the threshold and the original image passes through untouched. Trip it, and the node substitutes a different image you've already provided instead - a placeholder, a blurred version, a "content unavailable" graphic, whatever you want end users to see instead of the flagged output. Either way, a single IMAGE comes out the other side. There's no branching, no boolean output to route yourself with an IF node - the swap logic lives inside the node.

The inputs and outputs that matter

Three required inputs, no optional ones:

  • image - the generated image you want checked.
  • score - the threshold, 0 to 1, default 0.9. This is the one knob you'll actually touch. It's the minimum confidence the classifier needs before it treats the image as NSFW and swaps it. Default 0.9 is fairly conservative - it only swaps things it's quite sure about. If content is slipping through that you'd rather catch, drop it toward 0.7–0.8; if fine images are getting swapped for no good reason, push it back up toward 1.
  • alternative_image - the fallback image shown when the threshold trips. This is required, not optional, so you always need something wired in here, even if it's just a static placeholder loaded once with a Load Image node.

One IMAGE output. It's not a save or preview node itself (is_output_node is false) - wire it into a normal Save Image or Preview Image node downstream like you would anywhere else in the graph.

How to install it

Search ComfyUI-NSFW-Detection in ComfyUI Manager and install from there, or do it by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/trumanwong/ComfyUI-NSFW-Detection
cd ComfyUI-NSFW-Detection
pip install -r requirements.txt

Restart ComfyUI after either route. The README doesn't spell out exactly which ML libraries requirements.txt pulls in, just that the node "uses a machine learning model to classify images" - so budget for a real pip install pass, not a trivial one, and expect it to bring its own classifier weights along for the ride.

Common issues & troubleshooting

Dependency conflicts on install. This is a general ComfyUI custom-node problem, not unique to this pack: every node's requirements.txt installs into the same shared Python environment, with no isolation between packs. If you've got a large custom_nodes folder already, an ML-heavy pack like this one is a plausible place for a version conflict to surface. If install fails or ComfyUI won't boot afterward, check what package versions got bumped.

Nothing ever gets swapped, or everything does. That's the score threshold, not a bug - see above. Walk it down in small steps rather than guessing wildly; 0.9 to 0.7 is a big jump in sensitivity.

Forgot to wire alternative_image. It's required, so the graph won't queue without something plugged in. Keep a cheap static placeholder loaded once at the top of your workflow and reuse it everywhere you need this node.

Don't treat this as a compliance guarantee. It's a probabilistic classifier, not a legal filter - it will have both false positives (fine images swapped) and false negatives (something slips through). Treat it as one layer of defense, tune the threshold conservatively for your use case, and don't build a "this is guaranteed safe" claim on top of a single classifier score.

CategoryNSFWDetection

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
scoreFLOAT0.900–1
alternative_imageIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE