Nodes/comfyui_LLM_party/Custom String Format
ComfyUI Node

Custom String Format

Fill placeholders in a prompt template

By heshengtao·Created 2 years ago·Updated 11 days ago· 2,328
Custom String Format
    • format_string
    is_enabletrue
    string请帮我写一篇关于{主题}的文章。
    string_template{"主题":"人工智能"}

    Hardcoding a prompt directly into an LLM node's text box works fine until you want to reuse the same prompt shape with different values - a different topic, a different name, a different product. Custom String Format is the templating node in comfyui_LLM_party that solves that: write your prompt once with placeholders, and fill them in from a separate field without editing the template itself.

    This kind of prompt-assembly plumbing is a good chunk of what this pack is actually for - the README's pitch is building real LLM workflows (agents, RAG, multi-step tool calls) inside ComfyUI's graph, not just calling one API once, and templates like this are the connective tissue that makes a graph reusable instead of a one-off. It's also a reminder that this pack isn't the only route to LLMs-in-ComfyUI - you'll see comfyui-ollama and the Griptape nodes recommended alongside it - but it's the one that bundles this much prompt-engineering scaffolding out of the box.

    How it works

    string is your template, with placeholders wrapped in curly braces. string_template is a JSON object mapping those placeholder names to the values you want substituted in. The node does the substitution and hands back the filled-in text. The node's own default example makes the pattern clear: a template of 请帮我写一篇关于{主题}的文章。 ("Please help me write an article about {topic}.") paired with {"主题":"人工智能"} ({"topic":"artificial intelligence"}) produces "Please help me write an article about artificial intelligence."

    The inputs and outputs that matter

    • string (multiline) - your template text, with {placeholder} markers wherever a value should be dropped in.
    • string_template (multiline) - a JSON object where each key matches a placeholder name in string, and each value is what should replace it.
    • is_enable - the pack's standard bypass toggle.

    Output: format_string (STRING) - the filled-in result, ready to hand to an LLM node.

    How to install it

    Search comfyui_LLM_party in ComfyUI Manager and install, then restart. Manual install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/heshengtao/comfyui_LLM_party.git
    

    Then run pip install -r requirements.txt from the pack's own folder, using ComfyUI's bundled Python rather than a system interpreter, and restart ComfyUI. This node itself is pure text logic with no dependencies of its own; the install weight in this pack comes from the LLM, embedding, OCR and TTS libraries bundled in the same requirements.txt for its other nodes. If that collides with something already installed, fall back to the README's pinned requirements_fixed.txt.

    Common issues & troubleshooting

    A placeholder doesn't get replaced. This is almost always a naming mismatch - the key in string_template's JSON has to match the text between the curly braces in string exactly, including case. {Topic} in your template won't match a "topic" key.

    The node errors before it even substitutes anything. string_template has to be valid JSON - a trailing comma, a missing quote, or curly (smart) quotes pasted in from a word processor instead of straight ones will break the parse before your placeholders are even looked at. Paste into a plain text editor first if you're not sure.

    You need more than simple key-value substitution. This node does flat placeholder-fill, not conditional logic or loops. For anything more elaborate, you're better off building the final string upstream (with an LLM node or Python-side logic) and feeding the finished text straight into your prompt instead of fighting the templating syntax.

    Category大模型派对(llm_party)/文本(text)

    Inputs (3)

    NameTypeDefaultDescription
    is_enableBOOLEANtrue
    stringSTRING请帮我写一篇关于{主题}的文章。
    string_templateSTRING{"主题":"人工智能"}

    Outputs (1)

    NameTypeDescription
    format_stringSTRING