ComfyUI Node

String Strip

Scrape the boilerplate off LLM prompts before they hit the sampler

By bradsec·Created 2 years ago·Updated 2 months ago· 36
String Strip
    • modified_string
    input_string
    strings_to_remove
    match_casefalse
    match_whole_stringtrue
    preserve_punctuationtrue
    remove_extra_spacestrue

    If you've ever pasted an LLM's idea of a prompt into ComfyUI and watched it render the words "Sure, here is your prompt:" into the image, you know exactly why String Strip exists. It removes strings from text - a whole list of them, one per line, multi-word phrases allowed - and it's tuned for the specific garbage that language models add to image descriptions and prompts.

    The intended job is right in the README: cleaning text from Ollama, Claude, or ChatGPT before it reaches the sampler. Those models wrap their output in courtesies ("Here is a detailed description:", "Certainly! Let me..."), trailing notes, and markdown fences. String Strip is the machete. You type the offending phrases one per line - Here is a detailed description:, Certainly!, image/prompt: - wire in the LLM text, and out comes a clean prompt.

    How it works

    Each non-empty line of strings_to_remove becomes a removal rule, and the node applies them in longest-first order so a phrase like "This image is" gets removed before "is" can shred the rest of the sentence. Matching is case-insensitive by default, and match_whole_string (on by default) uses word boundaries so art doesn't tear apart artistic. Two cleanup flags ride along: preserve_punctuation keeps the commas and periods hugging the removed text instead of eating them, and remove_extra_spaces collapses the double-spaces that removals leave behind.

    The inputs that matter

    • strings_to_remove - one string per line. A multi-word phrase on a single line only matches that entire phrase, which is the right way to avoid nuking half the prompt.
    • match_whole_string - on by default. Flip it off if you genuinely want substring removal.
    • match_case - off by default; turn on for case-sensitive removal.
    • preserve_punctuation / remove_extra_spaces - both on by default, and you'll rarely touch them.

    Output: a single modified_string. Wire it into String Preview to confirm the result, then on to the sampler.

    Installation

    Zero Python dependencies (it's standard-library re under the hood), no model files. Via ComfyUI Manager: Manager > Custom Nodes Manager > search "ComfyUI_StringEssentials" > Install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/bradsec/ComfyUI_StringEssentials.git
    

    Restart, then find it under Add Node > utils > StringEssentials.

    Gotchas

    • This node only removes - it doesn't swap. For replacing text with new text, reach for String Multi Replace in the same pack. Deleting and replacing are separate tools here.
    • Word boundaries use regex \b. That's mostly great (art won't touch artistic) but note that underscores count as word characters, so photo won't match inside photo_realistic - something to remember if you're stripping tag-style text.
    • Case-insensitive by default. Here is in your list will remove HERE IS and here is. If the case distinction matters, set match_case on.
    • Everything you list is matched literally - regex metacharacters are escaped for you, so you can list (word:1.3) or [A1111:Forge:.5] without worrying about the brackets meaning anything. That's a deliberate feature: prompt syntax survives the cleaning.
    • If a removal isn't happening, the usual cause is match_whole_string blocking it because the phrase sits mid-word - or the phrase isn't actually verbatim in the text. Preview first, adjust after.

    For anyone routing LLM output into ComfyUI - which increasingly means everyone - this is the node that turns a garbage sentence into a sampler-ready prompt.

    Categoryutils/StringEssentials

    Inputs (6)

    NameTypeDefaultDescription
    input_stringSTRINGThe string to process
    strings_to_removeSTRINGEnter strings to remove (one per line). Can include multiple words or strings on one line like: 'This image is'. This will only match this entire string.
    match_caseBOOLEANfalseWhen enabled, matching is case-sensitive.
    match_whole_stringBOOLEANtrueWhen enabled, only whole-word matches are removed, not substrings inside other words.
    preserve_punctuationBOOLEANtrueWhen enabled, punctuation marks adjacent to matched text are preserved
    remove_extra_spacesBOOLEANtrueWhen enabled, collapses repeated spaces and trims the result after removal.

    Outputs (1)

    NameTypeDescription
    modified_stringSTRING