Nodes/comfyui-MGnodes/Text Extractor Node
ComfyUI Node

Text Extractor Node

Strip the thinking out of your LLM's answer, inside ComfyUI

By meanin2·Created 2 years ago·Updated 12 months ago· 4
Text Extractor Node
    • Answer Text
    • CoT Content
    text_in

    Run any reasoning-flavored LLM inside ComfyUI - a DeepSeek-style model, an Ollama node, a Qwen "thinking" variant - and a chunk of what comes back is the model thinking out loud, wrapped in <think>...</think> tags. That's great when you want the chain of thought, and a real problem when you're feeding the output into a prompt, a caption, or a Booru-tag pipeline. Nobody wants "Hmm, the user probably wants a red car because..." leaking into the final prompt string.

    This node is a tiny, single-purpose shim from the comfyui-MGnodes pack that fixes exactly that. Text goes in, the reasoning is pulled out into its own output, and what's left is clean.

    How it works

    It's one regex, nothing more. The node finds every <think>...</think> block (with DOTALL so it spans newlines), strips them from the main text, and joins whatever was inside them with newlines into a second string. Multiple think blocks are handled fine. If there are no think tags at all, the text passes through untouched and the reasoning output comes back empty - so it's safe to drop into any pipeline even if your LLM doesn't do reasoning tags.

    The whole node is pure Python re. No numpy, no torch, no extra packages. It can't break your environment and it costs essentially nothing to run.

    Inputs and outputs

    One input, one real decision:

    • text_in (STRING) - the LLM output. Note it's forceInput: this is a wire-in connection, not a type-able box. You can't paste text into it, which trips up a few people the first time.

    Two outputs:

    • Answer Text - the input with all think blocks removed. This is the one you wire into your prompt builder, CLIP Text Encode, or whatever consumes the text.
    • CoT Content - the extracted reasoning, joined with newlines. Feed it to a text display to watch the model's logic, or pass it to a summarizer node if you want a condensed version.

    Installing it

    It ships in comfyui-MGnodes, so install is the same as the rest of the pack - ComfyUI Manager, search "MGnodes", or:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/meanin2/comfyui-MGnodes.git
    

    Restart ComfyUI after cloning. No models, no downloads, no dependencies beyond Python's standard library.

    Where it's limited

    It's dumb on purpose, and that's mostly fine, but know its edges:

    • Case-sensitive and shape-specific. It matches lowercase <think> exactly. Variants like <thinking> or a stray space before </think> won't match, and the tag stays in your answer text.
    • It only handles the one tag shape. Other markers - like DeepSeek's [Reasoning] or thinking tags with attributes - won't be stripped. If your model emits something else, this isn't the node for it.
    • It won't fix malformed output. If the LLM never closes a think block, the content just isn't extracted.

    Honest take: this is a utility you'll reach for once your LLM workflow actually produces these tags, and then you'll wonder why it isn't built into the LLM nodes themselves. For a three-line regex wrapped in a node, that's a fair deal.

    CategoryText

    Inputs (1)

    NameTypeDefaultDescription
    text_inSTRING

    Outputs (2)

    NameTypeDescription
    Answer TextSTRING
    CoT ContentSTRING