Nodes/ComfyUI_StarNodes/⭐ Star Text Filter
ComfyUI Node

⭐ Star Text Filter

The string-whisperer for when your LLM won't shut up

By Starnodes2024·Created 2 years ago·Updated about 14 hours ago· 102
⭐ Star Text Filter
    • STRING
    text
    filter_type
    start_wordINPUT
    end_wordINPUT

    If you've ever piped an LLM's output into a prompt field, you know the complaint: it comes back with preamble ("Here is your prompt:"), trailing commentary ("I hope this helps!"), and inconsistent spacing - and every one of those is a token your image model has to interpret. Star Text Filter (StarTextFilter) is the scrubber for that problem: it takes any text and applies one of six cleaning operations, so you can strip the chaff off LLM output (or scraped text, or a badly-formatted prompt block) before it hits the sampler.

    How it works

    One input text, one output STRING, and a filter_type dropdown that picks the operation:

    • remove_between_words - delete everything between start_word and end_word (the defaults are literally "INPUT" / "INPUT", so set them). Great for cutting the middle out of a template.
    • remove_before_start_word - drop everything before the first occurrence of start_word, keeping from there to the end.
    • remove_after_end_word - drop everything after end_word, keeping up to and including it.
    • remove_empty_lines - collapse runs of blank lines. Perfect for cleaning pasted text.
    • remove_whitespace - delete all whitespace, everywhere. Destructive, rarely what you want, but it exists.
    • strip_lines - trim leading/trailing whitespace from each line without joining them. The everyday workhorse for tidy prompt blocks.

    The word-based modes use regex under the hood (with the words escaped, so special characters won't break them), and they're friendly about missing anchors: if start_word or end_word isn't found, the node returns your text untouched rather than an empty string. That's a thoughtful detail - a broken anchor produces the original text, not a blank prompt that generates a blank image.

    The inputs that matter

    • text - multiline, whatever you're cleaning.
    • filter_type - pick the operation.
    • start_word / end_word - the anchors for the three word-based modes. Only meaningful there; ignored by the line/whitespace modes.

    One STRING out, wire it anywhere text flows.

    Where it earns its place

    Three common patterns:

    • LLM output → prompt. The killer use. Ollama and other local models love to wrap their answer in explanation; remove_before_start_word with the right anchor, or remove_after_end_word, turns "Sure! Here's a stunning prompt: [content] I hope this helps!" into just the content.
    • Scraped text cleanup. The pack's Star Web Scraper hands back raw headline dumps; a remove_empty_lines + strip_lines chain makes them presentable.
    • Prompt template assembly. If you build prompts from parts (via Star Text Input, say) and want the joined result tidy, one filter at the end fixes stray whitespace everywhere.

    Honest notes

    It's a single-operation node - for a multi-step cleanup you chain two or three of them, or route through the pack's text concatenation node. And remove_whitespace is a trap if you're not careful: it strips everything, so "hello world" becomes "helloworld". Use it only when you genuinely want a whitespace-free string. For everything else, strip_lines is the one you'll reach for most.

    Install

    Part of the StarNodes pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Starnodes2024/ComfyUI_StarNodes
    

    or ComfyUI Manager → search Starnodes, restart, find it under ⭐StarNodes/Text And Data. No dependencies beyond the standard library. Pure text in, pure text out - about as safe and predictable as a StarNodes node gets.

    Category⭐StarNodes/Text And Data

    Inputs (4)

    NameTypeDefaultDescription
    textSTRING
    filter_typeCOMBO6 options: remove_between_words, remove_before_start_word, remove_after_end_word, remove_empty_lines, remove_whitespace, strip_lines
    start_wordSTRINGINPUT
    end_wordSTRINGINPUT

    Outputs (1)

    NameTypeDescription
    STRINGSTRING