Prompt Cleaner (FeiMao-326)
A last-pass scrub for messy prompts — dedupe, fix commas, drop empty brackets
- text
If you assemble prompts from multiple sources - an LLM, a wildcard, a template, some tags you typed in 2024 - they arrive with scars. Duplicate tags, , , double commas, stray () left behind when a wildcard picked nothing, inconsistent spacing. This node is the janitor: it takes your messy text, normalizes the punctuation, drops the duplicates, and hands back a clean comma-separated tag list ready for the text encoder.
How it works
Inputs are text (multiline), plus two toggles: remove_duplicate_tags and clean_brackets, both on by default. The pipeline runs in a specific order:
- Newlines are turned into commas and multi-comma runs collapse to a single
,- so multi-line prompt blocks become one flat tag list. - The text is split on commas, each tag trimmed.
- With
remove_duplicate_tagson, duplicates are removed case-insensitively while preserving first-seen order.Masterpiece, masterpiecebecomesMasterpiece, notmasterpiece. - With
clean_bracketson, empty bracket pairs like(),( ),[]are stripped out, and any comma runs created by that removal get collapsed again.
The result is a single text string with the tags joined by ", " and leading/trailing commas trimmed. It's a destructive-ish transform - if your prompt legitimately contains (word:1.2) weight syntax, note that only empty brackets are removed, so weighted terms survive. But this node is clearly built for the modern tag-list world, not the SD1.5 (word:1.2) world, and it assumes commas are your structure.
Where it fits
The author's framing is exactly right: use it as the "final touch" before KSampler. If an LLM is generating or rewriting prompts, its output will contain exactly the kind of junk this cleans - duplicate adjectives, weird whitespace, artifacts from template substitution. Slap one of these between your prompt-assembly section and the CLIP Text Encode and your negative space stops being "silently worse prompts."
One honest limitation: "cleaning" here means structural cleanup, not semantic quality. It won't fix a tag that's wrong for your checkpoint, and it can't tell 1girl from 2girls. Pair it with a real prompt-engineering pass (matching tags to the model's vocabulary) rather than expecting it to save a badly-written prompt.
Inputs and outputs
text(STRING, multiline) - the prompt to clean.remove_duplicate_tags(BOOLEAN) - dedupe case-insensitively, keep first occurrence.clean_brackets(BOOLEAN) - strip empty(),(),[].text(STRING) - the cleaned prompt.
Installing
It's one of the sixteen nodes in the FeiMao-326 pack (category "FeiMao-326"), so install the pack once:
cd ComfyUI/custom_nodes
git clone https://github.com/FeiMao-326/Comfyui-General-API-Node.git
cd Comfyui-General-API-Node
pip install -r requirements.txt
Restart ComfyUI, then Add Node → FeiMao-326 → Prompt Cleaner. ComfyUI Manager users can search "Comfyui-General-API-Node" instead. Dependencies are just openai, numpy, Pillow, requests - nothing heavy.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| remove_duplicate_tags | BOOLEAN | true | — |
| clean_brackets | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |