Replace String
The find-and-replace node for cleaning up LLM output
- string
LLMs rarely give you exactly the string you asked for. They wrap answers in a sentence, add markdown code fences around JSON, prepend "Sure, here's..." before the actual content, or leave in a placeholder token you meant to substitute yourself. Replace String is the plain, boring, extremely necessary node for cleaning that up - a straightforward find-and-replace on any string, no regex, no cleverness, just swap one substring for another.
What it does
Three required inputs, and they're exactly what the name promises: input_string is the text coming in, old_string is the substring to find, and new_string is what to replace it with. The single output, string, is the result. There's no is_enable toggle on this one, unlike most nodes in this pack - it's simple enough that there's presumably nothing worth bypassing; if you don't want the replacement, just don't wire the node into your chain.
Where it fits
This is glue, and it shows up constantly once you're building real pipelines with this pack. A few concrete patterns:
Stripping markdown fences an LLM added around code or JSON it wasn't asked to format that way - swap ```json and ``` for empty strings before the text hits a JSON-parsing node. Removing a boilerplate prefix a model consistently adds despite instructions not to (some models are stubborn about "Sure, here's the answer:" regardless of system prompt). Templating - build a prompt with a placeholder like {{topic}} baked in as static text, then use Replace String to substitute the real value at runtime instead of hand-writing a new prompt string every time. Any of these could technically be handled by prompting the model more carefully instead, but a deterministic string swap is more reliable than hoping an LLM follows a formatting instruction consistently across every run.
Installing it
Ships as part of the full pack - no standalone version:
- ComfyUI Manager: search "comfyui_LLM_party", install, restart ComfyUI.
- Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/heshengtao/comfyui_LLM_party, thenpip install -r requirements.txtinside your ComfyUI Python environment, restart.
This node needs none of the pack's heavier dependencies - it's pure string manipulation - so if it's the only node you're using from this pack, the install is fast regardless of which branch or config you pick.
Common issues
Since there's no regex support here - just literal substring matching - the most common frustration is expecting pattern-based replacement and not getting it. old_string has to match exactly, character for character, including whitespace and capitalization; if an LLM's output varies slightly between runs (different capitalization, an extra space), a hardcoded old_string that worked once may silently do nothing on the next run because it no longer matches. If you need to handle variable text rather than a fixed known string, this node isn't the right tool - you'd want something with actual pattern matching, which isn't what this node offers.
The other easy mistake is chaining multiple Replace String nodes and losing track of order - each one operates on the output of the last, so if two replacements could theoretically interact (one replacement's output text happens to contain the next node's old_string), the order you wire them in changes the result. Test with the actual variable LLM output you'll be running in production, not just a clean hand-typed example, since real model output is messier than what you'd type by hand while building the workflow.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | — | |
| old_string | STRING | — | |
| new_string | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |