Nodes/ComfyUI-PromptComments/Strip Comments πŸ’¬
ComfyUI Node

Strip Comments πŸ’¬

The prompt filter for text that arrives from somewhere else

By WebCrusaderΒ·Created a day agoΒ·Updated about 15 hours agoΒ· 0
Strip Comments πŸ’¬
    • text
    β—„textβ€”β–Ί
    β—„tidytrueβ–Ί
    β—„blank_linesβ–Ύβ–Ί

    The sibling PromptComments node is great, but it assumes you type the prompt yourself. What about when the prompt shows up on a wire - a wildcard picker, an LLM captioner, a LoRA stack that appends a note, a prompt-from-file node? Those sources don't have a red-highlighted editor, and if they let # or // through, the encoder eats whatever comes after. StripComments is the pass-through version of the same filter: you don't type in it, you feed it text, and it hands back the text with comments stripped and the edges tidied.

    Think of it as the "clean this before it hits the encoder" node. Same scanner as its sibling, same rules: a # or // only starts a comment when it's a word of its own - it must follow whitespace, and #/// also need whitespace after them - so C# minor, #hashtag, and https://example.com survive. /* ... */ blocks work and span lines; an unterminated /* comments out everything after it. Whichever marker comes first wins and runs to its natural end. Because the filtering happens in Python, the result is identical whether the graph runs from the UI or via the API.

    The three inputs that matter

    • text (STRING) - required, but it's a wire-only input (forceInput), so there's no textarea to type into. Connect a STRING from a wildcard picker, an LLM captioner, or any text node. If you open it expecting to type, the missing box is the design, not a bug.
    • tidy (BOOLEAN, default true) - the cleanup pass. It removes doubled commas, space ,, runs of spaces, a trailing comma, and a comma orphaned at the start of a line because the line above was commented out. Turn it off when you want the output left alone beyond the comment removal itself.
    • blank_lines (dropdown) - what to do with blank lines the source produced: collapse (default) keeps your gaps but never more than one in a row, keep preserves runs exactly as typed, remove deletes them. Leading and trailing blank lines are trimmed in every mode, and a line that was only a comment is removed entirely rather than leaving an empty hole.

    Output is a single text STRING - the filtered, tidied prompt. Wire it into a CLIP Text Encode and you're done.

    Where it earns its keep

    The genuinely useful case is an LLM captioner or wildcard system that annotates its own output. Let the model append /* candidate rewrite */ or a #-prefixed note to itself, and StripComments quietly discards it before the encoder. That lets you keep the annotation logic inside the thing generating the text instead of hand-editing after. It's also handy downstream of a file reader that stores drafts with comments, or anywhere you want a consistent "strip and tidy" guarantee across an entire workflow.

    Install

    Same pack, same steps as the sibling node:

    cd ComfyUI/custom_nodes
    git clone https://github.com/WebCrusader/ComfyUI-PromptComments
    

    Or ComfyUI Manager β†’ search "ComfyUI-PromptComments". Restart, then hard-refresh the browser (Ctrl+Shift+R / βŒ˜β‡§R) so the cached frontend bundle doesn't linger. No dependencies, no model files, nothing added to core.

    Gotchas

    • The text input can't be typed. Feed it from a node; the whole point is pass-through.
    • Wrong input type raises TypeError rather than silently passing garbage through - it will fail loudly, and that's the safer failure mode.
    • An unknown blank_lines value raises ValueError instead of falling back to a default. You can't typo your way into silent behavior.
    • tidy is on by default. If your downstream genuinely wants a doubled comma preserved, flip it off; otherwise the output is aggressively tidy.

    Small node, one job, no dependencies, and it does that one job without surprises. If your prompts already arrive on a wire, it's the difference between a captioner that can leave itself notes and one that can't.

    Categoryutils/text

    Inputs (3)

    NameTypeDefaultDescription
    textSTRINGβ€”
    tidyBOOLEANtrueβ€”
    blank_linesCOMBO3 options: collapse, keep, remove

    Outputs (1)

    NameTypeDescription
    textSTRINGβ€”