Nodes/ComfyUI-RyuuNoodles/Clean String Adv. 🐲
ComfyUI Node

Clean String Adv. 🐲

The janitor for prompts that came out of a spreadsheet

By DraconicDragonΒ·Created about a year agoΒ·Updated 2 months agoΒ· 12
Clean String Adv. 🐲
    • text
    β—„input_textβ–Ί
    β—„stripbothβ–Ί
    β—„trailing_commasremoveβ–Ί
    β—„newlinesoffβ–Ί
    β—„collapsespaces + commasβ–Ί
    β—„remove_duplicate_tagsfalseβ–Ί
    β—„caseoffβ–Ί

    Every serious ComfyUI user ends up with a prompt from somewhere ugly: a spreadsheet of Danbooru tags with stray double spaces, a caption list with trailing commas, a copy-paste from a forum post with blank lines everywhere. Clean String Adv. is the node that takes that mess and normalizes it into something a prompt encoder won't choke on. It's a string filter pipeline in a single node, and it's genuinely handy for batch workflows.

    What it does

    One multiline input_text in, one cleaned text out. Between those it applies up to six independent filters, each with its own control:

    • strip - off / left / right / both. Which sides of whitespace to trim. Default both.
    • trailing_commas - off / remove / add / add + space. The add + space mode is the nice touch: it adds a comma if none exists, and adds a space after an existing comma-without-space. Default remove.
    • newlines - off / remove empty / collapse lines. Collapse joins everything into one line - the classic move when you're feeding a single-line prompt encoder. Default off.
    • collapse - off / spaces / spaces + commas. Squashes apple, banana into apple, banana. Default spaces + commas.
    • remove_duplicate_tags - a boolean that dedupes comma-separated entries, so apple, banana, apple, orange becomes apple, banana, orange. This one is the star for anyone cleaning tag lists.
    • case - the big one, ten options: off, lowercase, uppercase, capitalize (per-sentence), capitalize_1st_letter, camelcase, pascalcase, snakecase, kebabcase, titlecase.

    The order of operations matters and is fixed: strip β†’ trailing comma β†’ newlines β†’ collapse β†’ dedupe β†’ case. So you can, say, collapse lines and lowercase a whole batch of prompts in one pass.

    Why you'd use it

    Prompt hygiene is real. The prompt-engineering docs hammer on token waste: quality-tag spam and duplicate words cost you tokens you could spend on actual content, and on LLM-encoded models there's an attention cap around 75-100 effective tokens. Cleaning a tag list before it hits the encoder is free quality. It's also the right tool when you're generating filenames or metadata strings from prompts - the case modes exist for exactly that.

    Inputs and output

    • input_text - the raw string (multiline).
    • Output: text - the cleaned string.

    Everything is widget-driven, no connections needed beyond the text. It's marked experimental in the code, but for string filtering there's not much to break.

    Installing it

    Part of the RyuuNoodles pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/DraconicDragon/ComfyUI-RyuuNoodles
    

    Restart ComfyUI, or use ComfyUI Manager (search "RyuuNoodles"). No models, no extra dependencies.

    Gotchas

    The case transformations can surprise you on punctuation-heavy text - camelcase on a sentence with commas produces stuff like appleBananaOrange.Juice, which is fine for filenames and nonsense for prompts. And remove_duplicate_tags operates on comma-separated entries, so if your prompt is prose rather than tags, it does nothing useful. Match the filter to the input format, and you're good.

    CategoryRyuuNoodles 🐲/Text

    Inputs (7)

    NameTypeDefaultDescription
    input_textSTRINGText input to be cleaned.
    stripCOMBObothControl which side(s) of whitespace to strip from the input string.
    trailing_commasCOMBOremoveRemove or add a comma at the end of the input string. Will not add a comma if one already exists, but will add a space if 'add + space' is chosen and a comma exists but no space.
    newlinesCOMBOoffControl how newlines are handled off = keep all lines remove empty = drop blank lines collapse lines = join all lines into one
    collapseCOMBOspaces + commasCollapse multiple consecutive spaces into one, or collapse both spaces and commas into a single occurrence depending on the selected option. Example: 'apple, banana, apple, orange.' β†’ 'apple, banana, orange.'
    remove_duplicate_tagsBOOLEANfalseRemove duplicate tags/words separated by commas, handling spaces around commas and ensuring only unique entries remain. Example: 'apple, banana, apple, orange' β†’ 'apple, banana, orange'
    caseCOMBOoffChange the case of the string. Examples with input 'apple, banana, orange.': off = no change ('apple, banana, orange. juice') lowercase = all lowercase ('apple, banana, orange. juice') uppercase = ALL UPPERCASE ('APPLE, BANANA, ORANGE. JUICE') capitalize = Capitalize the start of every sentence (after punctuation or empty lines) and lowercase the rest ('Apple, banana. Orange. Juice') capitalize_1st_letter = Capitalize only the first letter of the input string ('Apple, banana. orange. juice') camelcase = likeThisExample ('appleBananaOrange.Juice') pascalcase = LikeThisExample ('AppleBananaOrange.Juice') snakecase = like_this_example, always lowercase ('apple_banana_orange._juice') kebabcase = like-this-example, always lowercase ('apple-banana-orange.-juice') titlecase = Every Word Capitalized ('Apple, Banana, Orange. Juice')

    Outputs (1)

    NameTypeDescription
    textSTRINGβ€”