Nodes/ComfyUI NSFW Filter/ComfyUI_NSFW_Godie
ComfyUI Node

ComfyUI_NSFW_Godie

The Word Filter That Keeps Your Formatting

By chenpipi0807·Created about a year ago·Updated about a year ago· 3
ComfyUI_NSFW_Godie
    • STRING
    text
    replacement_char*

    Reality check up front: if you googled "NSFW filter" hoping this node stops a model from generating explicit images, that's not what it does. ComfyUI has no built-in prompt filter, and people have been asking for one on r/comfyui since 2024, mostly so they can bolt a guardrail onto a shared or classroom instance. This is that guardrail - except instead of a neural classifier, it's a plaintext word list and some careful string surgery. It scrubs text. Nothing more, nothing less.

    Honestly, it's a tiny node, and the search traffic agrees - it's not one you'll miss if it's absent. But it's also one of the rare custom nodes that cannot break your environment, and it does one job cleanly.

    What it actually does

    When the node first runs, it loads nsfw.txt from its own folder (about 350 lines in the shipped copy - a mix of single words like sex and naked, and spaced phrases like panties aside). Lines with a space get treated as phrases; everything else as a single word. Both lists are lowercased.

    Filtering happens in two passes:

    1. Phrases first. Each phrase is matched case-insensitively with a regex and replaced, char for char. "open the clothes" becomes "***************" - same length, punctuation untouched.
    2. Single words next. The text is split on punctuation and whitespace, and any token whose lowercase form is in the list gets replaced char-by-char. SeX***, Naked,*****, - the comma survives.

    Because every replaced character maps one-for-one to the replacement character, the output string is the same length as the input. Line breaks, capitalization, commas, em-dashes - all preserved. That matters if the scrubbed string goes on to a CLIP encoder or gets logged somewhere a human reads. The list itself is cached for an hour so a batch of prompts doesn't re-read the file every call.

    The inputs and outputs

    Only two inputs, both strings:

    • text (required, multiline) - the raw prompt, caption, or whatever string you want scrubbed.
    • replacement_char (optional, default "*") - the character used. Two hidden behaviors live in the code: leave it empty and it silently falls back to *, and pass "XXX" and only the first character is used. So don't bother getting clever.

    One output: a STRING with the filtered text. Wire it straight into a CLIPTextEncode (or its successor) where your raw prompt would have gone. The node is flagged as an output node, so the result also renders right on the node even if you don't connect it anywhere.

    Installing it

    ComfyUI Manager: search "NSFW Godie" and hit install. Or the manual route:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/chenpipi0807/ComfyUI_NSFW_Godie
    

    Then restart ComfyUI. That's the whole install - the requirements.txt is empty of actual dependencies, and the node imports only os, re, and time from the standard library. No model downloads, no GPU footprint, no pip conflicts. This is the node you install when every other custom node is busy breaking something.

    Making it yours - and the gotchas

    You customize the word list by editing nsfw.txt in the node's folder. Add or delete a line, done. But the README glosses over two things the source doesn't:

    • The list is cached for an hour. Edit nsfw.txt and the node keeps using the stale list until the cache expires or you restart ComfyUI. It's a deliberate perf choice, but it reads as "my edit didn't work" the first time.
    • Single words are whole-token matches; phrases are substring matches. So sexy and sexuality survive because sex never matches inside them, but a phrase like panties aside will also chew up any text that merely contains it. For a scrubber that's arguably a feature - over-blocking is the safe failure mode.

    Also keep in mind this runs before sampling, so it has zero influence on what the model draws. It's text hygiene, not output censorship. If you genuinely need to filter generated images, you want a safety checker downstream of the VAE decode, not this.

    When to reach for it

    Use it when you run a ComfyUI instance other people touch - a server, a classroom, an auto-posting pipeline - and you want a deterministic, offline, no-API prompt scrubber. The name is a bit of a lie: it calls nothing and needs no key. For your own personal prompts, honestly, a text search does the same job; this earns its keep the moment it's wired into a workflow someone else will run.

    Categorytext

    Inputs (2)

    NameTypeDefaultDescription
    textSTRING
    replacement_charoptSTRING*

    Outputs (1)

    NameTypeDescription
    STRINGSTRING