Extract Substring
Pulling a clean value out of a messy LLM reply
- substring
- remaining_string
LLMs are chatty by default, and that's the whole reason this node exists. Ask a model for "just the prompt, nothing else" and half the time you still get "Sure! Here's a great prompt for you: ..." wrapped around the part you actually wanted. Extract Substring is a plain text-slicing utility for exactly that problem: give it a start marker and an end marker, and it hands back whatever's between them, cleanly separated from everything else.
It's about as simple as this pack's nodes get. input_string (required, multiline) is whatever text you're slicing - almost always the assistant_response output of an upstream LLM node. start_string and end_string are both optional, and how you use them changes the behavior: set both to grab everything between two markers, set only start_string to grab everything from that point to the end of the string, or leave both empty and you'll just get the input back unchanged. It outputs two things, not one: substring, the extracted text between your markers, and remaining_string, whatever's left over after removing the matched section - useful if you need both halves for different purposes rather than throwing the surrounding text away.
The practical pattern this enables is telling your LLM, in the system prompt, to wrap its actual answer in custom delimiters - something like "put your final prompt between [[START]] and [[END]]" - and then using this node to reliably pull just that section out regardless of how much preamble or explanation the model adds around it. It's a much more reliable approach than trying to strip boilerplate with a fixed set of string replacements, since models don't wrap their answers the same way every time, but they're generally good at respecting an explicit delimiter instruction if you ask clearly.
Installing it means installing the pack as a whole, since this ships alongside every other comfyui_LLM_party node: search "comfyui_LLM_party" in ComfyUI Manager, or git clone https://github.com/heshengtao/comfyui_LLM_party into custom_nodes and restart, then run pip install -r requirements.txt from inside the pack folder using ComfyUI's own Python (portable installs need python_embeded\python.exe -m pip install -r requirements.txt, not your system pip).
There's nothing exotic to troubleshoot here - it's a thin string operation, so if the output isn't what you expect, the fix is almost always in how you're asking the model to format its response, not in the node itself. Two things worth checking if extraction comes back empty: make sure your markers actually match the case and exact characters the model produces (models are inconsistent about whether they'll use the exact delimiter text you specified versus a close paraphrase of it), and remember that if start_string appears more than once in the input, you'll want to check exactly where the match lands rather than assume it's always the first occurrence.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | — | |
| start_stringopt | STRING | — | |
| end_stringopt | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| substring | STRING | — |
| remaining_string | STRING | — |