π§Ή String Cleaning
Strip Think Tags, Punctuation and Stray Whitespace
- cleaned_string
If you pipe an LLM's output into a prompt box, you get LLM formatting with it: Okay, here's an enhanced prompt: on the front, a <think> block nobody asked for, markdown bullets, three line breaks, and a closing bit of encouragement. π§Ή String Cleaning is the node that flattens all of that into one usable line. It's the least glamorous node in this pack and probably the one you'll use most if you run any text-generating branch.
The <think> use case is the author's own headline example, and it's the one that bites in practice: reasoning models emit a scratchpad before the answer, you don't want the scratchpad near CLIP, and the pack's Groq LLM node feeds straight into this.
How it works
It's a stack of independent booleans plus a few find-and-replace boxes, applied to input_string as one pass. Nothing happens unless you tick something, so it's safe to leave inline.
The toggles: collapse_sequential_spaces (many spaces β one), strip_leading_spaces / strip_trailing_spaces (per line), strip_empty_lines, strip_leading_symbols / strip_trailing_symbols (leading punctuation , . ! ? : ; per line), strip_newlines, and replace_newlines_with_period_space - which turns any run of line breaks into a single . , the trick for feeding a paragraph to a tag-based model without losing the sentence boundary.
The string fields are where the real power is, and they're all one-entry-per-line:
strip_inside_tags- character pairs like()[]{}; removes the bracketed content entirely.Hello (world) and [text]βHello and.strip_between_start/strip_between_end- matched pairs, line for line.<think>β¦</think>is the canonical use, and it removes the markers along with the content. Both boxes must have the same number of lines.strip_leading_custom/strip_trailing_custom- literal strings removed from the start or end of each line.Chapteron every line, gone. A single space works too.strip_all_custom- removes the string everywhere, not just the edges.remove_text_before/remove_text_after- chop to (and including) a marker, so you can throw away a preamble or a trailing sign-off.multiline_find/multiline_replace- straight find-and-replace, processed in order.
The whole thing outputs one string. That's the trade: you can't use it as a filter chain and see the intermediate steps, so when output looks wrong, tick the boxes one at a time until you find the culprit.
Inputs and outputs
Everything above is a required input except the optional ones are absent - the schema declares them all required, so each box exists whether you use it or not. The only output is cleaned_string, a STRING, which goes into a CLIP Text Encode, a Save Text File, or a String Concat.
Install
ComfyUI Manager β search "ComfyUI-mnemic-nodes" β install β restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/MNeMoNiCuZ/ComfyUI-mnemic-nodes
No downloads, no keys. The pack's heavier dependencies belong to its other nodes.
Common issues
Content between tags survives. Check both start and end boxes have the same number of lines, in matching order. A missing counterpart doesn't strip.
Everything vanished. strip_all_custom with a common word in it, or a remove_text_after marker that appears early in the text. Untick and re-test.
The output is one long line and you wanted that. That's strip_newlines or replace_newlines_with_period_space. Use the second one for prompts - sentence breaks read better to an encoder than a run-on.
A line-break-related rule isn't applying. The custom strip fields work per line and can't remove line breaks themselves.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | The text to clean, in operation order. Example: ' red fox' with Trim Line Starts then Collapse Spaces becomes 'red fox'. | |
| operation | COMBO | Replaces consecutive spaces with one space. Keeps tabs and line breaks. Example: 'red fox' -> 'red fox'. | |
| extra_operationsopt | STRING | [] | Additional cleaning steps in order. Example: trim line starts, then remove empty lines. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| cleaned_string | STRING | Text after all operations, in order. Example: 'red fox' becomes 'redfox' with Remove All Spaces. |