ComfyUI Node

NSFWScore

Score an image for NSFW content and filter it in code

By iamandeepsandhu·Created 2 years ago·Updated 2 years ago· 11
NSFWScore
  • image
  • FLOAT

The name oversells it a bit. NSFWScore doesn't block, blur, or censor anything - it looks at an image and hands you back a single number: how confident a classifier is that the picture is not-safe-for-work, on a scale from 0 to 1. What you do with that number is entirely your problem. It's a sensor, not a gate.

That framing matters, because it decides who this node is for. If you're a hobbyist generating on your own machine, you already know what you made - you don't need a model to tell you. The people who actually reach for this are the ones running ComfyUI as a backend: a SaaS image generator, a Discord bot, a public API, anything where a stranger's prompt produces an image that then gets shown to other strangers. When the announcement thread went up, the one-line case for it in the comments was blunt - "any non-NSFW business using ComfyUI workflows in the backend definitely needs this." That's the whole pitch. You want to catch a bad output before it reaches a user, automatically, without a human in the loop.

How it works

Under the hood it wraps a small pretrained image classifier - the kind of lightweight model you pull from HuggingFace - and runs your image through it. The pack is a friendlier repackaging of trumanwong's ComfyUI-NSFW-Detection, which the author credits directly. First time the node runs, transformers fetches the model weights, caches them, and every run after that is local and fast. The output is just the model's confidence, surfaced as a plain float you can act on.

The inputs and outputs that matter

There's almost nothing to configure, which is the point:

  • image (IMAGE) - the only input. Wire your generated image straight in, usually from a VAE Decode or a loader.
  • FLOAT - the only output. A confidence score where higher means more likely NSFW.

The author's recommendation is to treat 0.95 as your threshold - anything at or above that, call it NSFW; below, let it through. That's deliberately conservative. Set the bar high and you cut down on false positives (a shirtless gym photo getting flagged), at the cost of occasionally missing something borderline. Tune it for your own tolerance once you've watched it run on real traffic.

Here's the trap beginners fall into: the score alone does nothing. Vanilla ComfyUI has no clean if/else, so dropped inside the graph, that FLOAT is just a number you can stare at. This node isn't really meant to live in the visual editor at all. As the author puts it, it's "more likely to be used when you are using workflow as an API" - you export the API-format workflow, read the FLOAT back out of the execution response in your own code, and branch there: reject, re-roll, watermark, or ship. That external if (score > 0.95) is where the actual filtering happens.

Installing it

Two paths. In ComfyUI Manager, search the pack title - NSFW Check for ComfyUI - install, restart. Or from a terminal:

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

then restart ComfyUI. The pip install step is not optional here - unlike a pure quality-of-life pack, this one has real Python dependencies for the classifier, so a git clone without it will just fail to load the node.

Where it bites

A few things worth knowing before you rely on it:

  • First run needs internet. The model downloads on the first execution. On a locked-down or air-gapped box - or a serverless worker with no outbound network - that first run fails until the weights are present. Warm the cache once somewhere with connectivity.
  • You have to wire the output somewhere to see it. It's not an output node, so on its own it renders nothing in the UI. Feed the FLOAT into a display/show-any node if you want to eyeball the score while building.
  • It's a probability, not a verdict. No small classifier is perfect - expect the occasional false positive and false negative. The 0.95 threshold is a lever to trade one for the other, not a guarantee. Treat it as a first-pass filter that dramatically cuts your risk, not a compliance-grade content check you can bet the business on unattended.
CategoryNSFWScore

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
FLOATFLOAT