Nodes/ComfyUI-lhyNodes/String Format
ComfyUI Node

String Format

String Format, the Quiet Workhorse

By lihaoyun6·Created 12 months ago·Updated 13 days ago· 20
String Format
    • string
    format
    value1
    value2
    value3
    value4
    value5
    value6

    Every workflow eventually needs to build a string from parts. A prompt that's "base style + subject + lighting quality", a filename that embeds the model and seed, a negative that shares a common prefix across runs. String Format (class StrFormat) is the lhyNodes take on the humble template node: you write a template containing {} placeholders, provide up to six values, and it slots them in order and hands you the finished string.

    It's Python's str.format() wearing a ComfyUI hat. The format input is a multiline text box - put your template there, with {} where values should go. Then value1 through value6 fill those placeholders left to right. So a template like {}{}, masterpiece with values "cat" and "sitting on a windowsill" produces cat sitting on a windowsill, masterpiece. Same semantics as Python, which means you can also use index placeholders like {2} if you want to reorder or repeat values - a genuinely useful trick most people discover later.

    The inputs that matter

    • format - the template, with {} placeholders. Multiline, so multi-line prompts work fine.
    • value1value6 - the six slots. Each is a string input, and here's the part that makes this node sing: they can be wired from other nodes. Convert a value to an input and pull in a LoRA name (there's a LoraName node for that), a resolution, a seed turned into text - and now the composed prompt/filename updates itself whenever its parts change.

    Output: string, the formatted result, ready for a CLIP Text Encode, a Save Image prefix, or whatever consumes text.

    Where it shines and where it doesn't

    The killer use is prompt assembly with a single point of change: keep the constant parts of your prompt in the template, wire the varying parts in as values, and you never edit five prompt boxes again. It's also the natural partner for the pack's model-name nodes - LoraName, UNETName, VAEName all output strings, and String Format is where those strings get composed into filenames or log lines.

    The limitation is the fixed six slots and the single output. Need more than six parts, or want to toggle parts on and off? That's what String Format (Advanced) in the same pack is for - it adds a per-value enable switch. And if you're doing complex conditional logic, a template node is the wrong tool entirely; this is for assembly, not computation. Keep your placeholders balanced too - an unmatched {} raises a Python format error that surfaces as a node failure, and that's the most common beginner stumble.

    Installing it

    Part of lhaoyun6/ComfyUI-lhyNodes. Install via ComfyUI Manager by searching for lhyNodes, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/lihaoyun6/ComfyUI-lhyNodes.git
    python -m pip install -r ComfyUI-lhyNodes/requirements.txt
    

    Restart ComfyUI. The pack's shared requirements are ultralytics, opencv-python, numpy, and yarl; this node is pure string handling, no models, no downloads.

    It's not flashy, but it's one of those nodes you'll find yourself reaching for constantly once it's installed - the quiet workhorse of the pack. If your prompts are starting to repeat themselves across nodes, this is the first place to consolidate.

    CategorylhyNodes/String

    Inputs (7)

    NameTypeDefaultDescription
    formatSTRING
    value1STRING
    value2STRING
    value3STRING
    value4STRING
    value5STRING
    value6STRING

    Outputs (1)

    NameTypeDescription
    stringSTRING