Nodes/comfyui-sentence-filter/Sentence Filter ✂️
ComfyUI Node

Sentence Filter ✂️

Every sentence in your prompt, on a leash

By Slartibart23·Created 6 months ago·Updated 6 months ago· 0
Sentence Filter ✂️
    • text
    • sentences_deleted
    • sentences_replaced
    text
    delete_words
    replace_words
    replacement_sentence
    case_sensitivefalse

    You know the workflow you grabbed from a friend where every generation comes out with a sentence you didn't ask for - a www.example.com watermark shout-out, a baked-in LoRA tag, a template caption that no longer applies? Sentence Filter is the node that scrubs those out for you automatically. It's a text-in, text-out utility: feed it a string from anywhere in your graph, and it deletes whole sentences containing trigger words you list, or rewrites them into a replacement sentence, then hands the cleaned text to whatever comes next.

    It's a boring node, and that's the compliment. No model files, no API keys, no VRAM, no dependencies beyond Python's standard library. ComfyUI's whole selling point is that you can rewire the graph - and text utilities are the glue that makes the rewiring usable. This one is a cheap, zero-friction example of that: string in, string out, nothing else touched.

    The mechanism

    The node splits your text into sentences at periods and walks through them one by one. Two filters run per sentence:

    • Delete - if the sentence contains all the words in delete_words, the whole sentence is dropped.
    • Replace - if it contains all the words in replace_words, it's swapped for replacement_sentence.

    Deletion wins if a sentence matches both. Matching is case-insensitive by default (flip case_sensitive if you need exact), and it's substring matching, not word boundaries - so blonde also catches blonde-haired. A couple of thoughtful touches: dots inside URLs are protected before splitting so www.example.com doesn't become three "sentences", and a replaced sentence always gets a period appended, so don't type your own trailing one or you'll end up with ...

    Inputs & outputs

    You'll actually touch four inputs and maybe glance at the counters:

    • text (required) - the string to filter.
    • delete_words - comma-separated words. The trap: it's AND, not OR. blonde, straight, young only kills a sentence that contains all three. Missing one and the sentence survives. Want OR? Use one word at a time or chain two nodes.
    • replace_words plus replacement_sentence - for rewriting instead of deleting.
    • case_sensitive - off by default.

    Outputs are text (the cleaned string, ready to wire into a CLIPTextEncode or any other text consumer) plus sentences_deleted and sentences_replaced INTs, handy if you're batch-running and want to know how much got touched. On an empty input it short-circuits to empty output and zeroes - no error.

    Install

    The easy route: ComfyUI Manager, search "comfyui-sentence-filter", install, restart. Or from the terminal:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/Slartibart23/comfyui-sentence-filter.git
    

    Restart ComfyUI and the node appears under text › processing as "Sentence Filter ✂️". No model downloads, no pip install - the README says Python 3.13+, and beyond that it's pure standard library.

    Where people get burned

    • AND logic catches people every time. You list three words expecting "delete any sentence with any of these" and the node quietly keeps half your sentences. Read the trigger fields as must contain all and it makes sense.
    • Sentence splitting is period-based. Only URL dots are protected. A mid-sentence period like e.g. or Fig. 2 will split there, so your "sentence" boundaries aren't always what you think.
    • Replacement period doubling, as noted above - leave the trailing period off replacement_sentence.
    • Whitespace gets tidied. Double spaces collapse and leading/trailing whitespace is trimmed on the way out. Fine for prompts, worth knowing if you're feeding the text somewhere that cares about formatting.

    Is this the pack to build a workflow around? No. It's a single-purpose utility for one recurring annoyance, and it does that one thing cleanly. If you batch-generate from templates that accumulate junk sentences, or you distribute workflows and want the credits/watermarks stripped at the source, it earns its place. The author's handle is a Hitchhiker's Guide reference, which checks out for a node whose whole job is tidying up after someone else's mess.

    Categorytext/processing

    Inputs (5)

    NameTypeDefaultDescription
    textSTRING
    delete_wordsoptSTRING
    replace_wordsoptSTRING
    replacement_sentenceoptSTRING
    case_sensitiveoptBOOLEANfalse

    Outputs (3)

    NameTypeDescription
    textSTRING
    sentences_deletedINT
    sentences_replacedINT