D2 Prompt Sanitizer
Turn messy prompts (long_hair, ,, , double spaces) into clean tag soup
- prompt
You know the feeling: you grab a prompt from a Danbooru tag dump, an old A1111 image, or a shared workflow, and it arrives with long_hair, , ,, cascades, commas glued to the next tag, and maybe a LoRA <lora:foo:1> in the middle of it all. D2 Prompt Sanitizer is the tidy-up pass. You drop it between your text source and the prompt encoder, and it normalizes the string without you hand-editing forty tags.
It's a text-formatting node, not a generation node - feed it any string, get a cleaned string out. In the D2 ecosystem it slots right before D2 Prompt or D2 KSampler, but it works fine ahead of a plain CLIPTextEncode too.
What it actually fixes
Five toggles, all on by default, each doing one thing:
underscore_to_space-long_hair→long hair. This is the big one for tag-based prompts.space_after_comma- normalizes whitespace around commas to a single", "soa , bbecomesa, b.remove_extra_comma- collapses,,/, ,runs into one comma and strips commas at the start of a line.protect_lora- leaves<lora:my_lora:1>untouched. Without this, the underscore conversion would mangle LoRA syntax.protect_score- leaves Pony quality tags likescore_9/score_8_upintact. Same reason: those underscores are part of the tag name.
The protection toggles are the part worth understanding. The sanitizer isn't just blindly replacing _ with spaces; it stashes <...> and score_N matches, does its comma/space work, then puts them back. So turning protect_lora off genuinely would corrupt your LoRA call - leave it on unless you know why you don't want it.
The output
One output, prompt - the cleaned string. That's it. Output node it is not; you keep wiring prompt into your encoder or D2 Prompt.
The processing order matters if you're chasing a weird result: underscore conversion happens before comma cleanup, and protected text is restored last. So score_9, won't end up as score 9 , - the score tag gets stashed before any of the comma surgery.
Installing
Part of the D2-nodes-ComfyUI pack - install the pack, not the node.
- ComfyUI Manager → search "D2-nodes-ComfyUI" → Install → restart.
- Or
cd ComfyUI/custom_nodes && git clone https://github.com/da2el-ai/D2-nodes-ComfyUI, then restart.
Requirements are just piexif and charset-normalizer, no model files. Watch the pack's one big gotcha: v32.0.0+ requires the newer ComfyUI (V3 schema) - on an older install use a pre-32.0.0 release.
Notes and gotchas
This node won't add commas between tags that never had them - it fixes existing separators, it doesn't invent structure. If your input is 1girl long hair with spaces as separators, the result is 1girl long hair, not 1girl, long hair. Also: don't expect it to dedupe tags; that's a different toggle that lives in a newer version of the pack than the one you'll see listed here. If your prompts keep coming in with duplicate tags, pair the sanitizer with a dedupe pass in your prompt pipeline.
For a string utility node it's genuinely the one I'd reach for - it's deterministic, off-by-default-friendly (every transform can be disabled), and it costs nothing to leave in the graph.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | — | |
| underscore_to_space | BOOLEAN | true | — |
| space_after_comma | BOOLEAN | true | — |
| remove_extra_comma | BOOLEAN | true | — |
| protect_lora | BOOLEAN | true | — |
| protect_score | BOOLEAN | true | — |
| newline_mode | COMBO | keep | 5 options: keep, add_comma, to_comma, to_space, remove |
| remove_duplicate_tags | BOOLEAN | false | — |
| strip_trailing_comma | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| prompt | STRING | — |