Prompt Cleaner V2
Scrub unwanted words and phrases out of a prompt, cleanly
- STRING
Here's a boring but real problem: your source prompt is a mess. It's got "man, woman, world" boilerplate injected by some prompt-expansion node, or a phrase you're sick of seeing in every output, and you want it gone - everywhere, case-insensitively, without nuking the rest of the sentence structure. PromptCleanerV2 is a tiny text node from DJZ-Nodes that strips either a comma-separated list of words or a single exact phrase from a prompt string. It's not glamorous, but it's the kind of plumbing you end up using more than you expect.
How it works
Two modes, decided by whether you fill in phrase_to_remove:
- Word mode (default): split words_to_remove on commas, lowercase everything, then tokenize the input text into words and punctuation (using a regex that preserves
, . ( )as separate tokens). Every word matching the removal list - case-insensitively - is dropped, and the survivors are rejoined with single spaces. Because punctuation is kept as tokens, you don't lose your commas or weights syntax, which is the subtle thing that makes this better than a naivestr.replace. - Phrase mode: if
phrase_to_removeis non-empty, it takes priority and does a case-insensitive literal removal of the whole phrase from the text, preserving the surrounding formatting. This is for "I want every(masterpiece:1.2)gone" type edits where word-level removal would leave fragments behind.
The node logs the before/after to the console, which is nice for debugging - you can see exactly what got scrubbed. Inputs are text (multiline), words_to_remove (default "man, woman, world"), and phrase_to_remove (default empty). Output is a single STRING, ready to feed the CLIP encoder.
Where it fits
- Cleaning the output of wildcard/prompt-expansion systems that inject boilerplate tags.
- Removing a banned subject or a token you've burned on (the classic: "masterpiece" spam).
- Sanitizing caption text from a dataset before using it as prompt material (it pairs well with
CaptionsToPromptListin the same pack).
Installing
Part of DJZ-Nodes (Drift Johnson / MushroomFleet):
cd ComfyUI/custom_nodes
git clone https://github.com/MushroomFleet/DJZ-Nodes
cd DJZ-Nodes
pip install -r requirements.txt
Or search "DJZ-Nodes" in ComfyUI Manager. Pure stdlib (re + logging), no deps.
Gotchas
Word mode rejoins with single spaces, so double-spaces and some formatting quirks can appear - cosmetic, but noticeable if you're fussy. And the word list is a plain comma split with no trimming of multi-word entries, so "high quality, film" would try to match "film" but leave "high quality" untouched as a phrase; that's what phrase_to_remove is for. It's case-insensitive by design, which is right for prompts, but if you genuinely need a case-sensitive scrub this isn't the tool. For the 95% case - "get this recurring word out of my prompt" - it just works.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| words_to_remove | STRING | man, woman, world | — |
| phrase_to_remove | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |