Nodes/ComfyUI-lhyNodes/String Format (Advanced)
ComfyUI Node

String Format (Advanced)

String Formatting With a Kill Switch Per Slot

By lihaoyun6·Created 12 months ago·Updated 13 days ago· 20
String Format (Advanced)
    • string
    format
    value1
    switch1true
    value2
    switch2true
    value3
    switch3true
    value4
    switch4true
    value5
    switch5true
    value6
    switch6true

    String Format (Advanced) is what happens when the plain String Format node is 80% right but you need to disable parts of a prompt without deleting them. Same template-and-placeholders idea - write {} in the format box, fill the six value slots - but now every value has its own switch1switch6 toggle. Flip a switch off and that slot contributes an empty string, so the placeholder gets filled with nothing and the part simply disappears from the output.

    The mechanism is beautifully literal: each valueN is paired with a switchN (both default to true), and when a switch is off, that value is replaced with "" before formatting. So with a template like {}, {}, highly detailed and switch2 off, you get first value, , highly detailed - note the leftover comma. That's the one gotcha worth internalizing: disabling a slot removes the value but not the literal text around the placeholder. Put your separators inside the values ("cat, " rather than ", cat") or expect to see the punctuation linger.

    Why you'd reach for it

    The real payoff is building one reusable prompt template and flipping components on and off per run - without editing the template each time. Classic case: a style suffix, a quality tag, or a negative-prompt fragment you sometimes want and sometimes don't. Keep them all in the template, switch them off when you don't, and the same node serves both needs. It's also great for A/B testing: generate with a LoRA-name fragment wired into a slot, toggle its switch, and compare outputs without rewiring anything.

    Because the values are string inputs, they can be wired from other nodes just like the plain version - LoraName, UNETName, or any text source. The switches, though, are plain widgets, so in practice this node works best when you're the one flipping the switches between runs. If you wanted the switching itself automated by the graph, that's a different (and more exotic) tool.

    The inputs that matter

    • format - the multiline template with {} placeholders.
    • value1value6 - the slot contents.
    • switch1switch6 - the per-slot enable toggles. The whole point of this variant.

    Output: string, the composed result.

    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. Shared pack requirements are ultralytics, opencv-python, numpy, and yarl; no models or downloads involved.

    Honestly, most people are fine with the plain version - this is for when you start keeping "sometimes-on" prompt parts in a single template and want to switch them by hand without touching the text. When that's your workflow, the per-slot kill switch turns out to be exactly the right little feature.

    CategorylhyNodes/String

    Inputs (13)

    NameTypeDefaultDescription
    formatSTRING
    value1STRING
    switch1BOOLEANtrue
    value2STRING
    switch2BOOLEANtrue
    value3STRING
    switch3BOOLEANtrue
    value4STRING
    switch4BOOLEANtrue
    value5STRING
    switch5BOOLEANtrue
    value6STRING
    switch6BOOLEANtrue

    Outputs (1)

    NameTypeDescription
    stringSTRING