Nodes/LF Nodes/Switch String
ComfyUI Node

Switch String

A boolean switch for text that doesn't make you squint at wires

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
Switch String
  • ui_widget
  • string
  • string_list
on_true
on_false
booleanfalse

Sometimes your workflow needs to pick between two pieces of text based on a condition - two prompts, two negative prompts, two filenames, two API strings. You could string together a switch node from another pack or wrestle with a Python script node, but LF_SwitchString does the narrow thing cleanly: on_true, on_false, and a boolean condition. If the boolean is true you get on_true; otherwise on_false. That's the whole node, and honestly that's why it's good.

Where it earns its keep is in batch and A/B workflows. Pair it with a primitive that flips per run (or a LF_Boolean node with randomization enabled) and you can toggle between two prompt styles, two seed strings, or a "high detail / low detail" pair without editing the graph. Same idea as the classic two-way text switch in other packs, but this one ships with a progress-bar-style widget (KUL_PROGRESSBAR) and keeps the LF Nodes look.

The inputs that matter

  • on_true / on_false - both are multiline strings, so you can drop multi-line prompts in rather than fighting a single-line field.
  • boolean - the condition. Defaults to false, so out of the box you'll get on_false until you wire something in. Feed it from any boolean source: a LF_Boolean node, a comparison result, or an LLM's structured output via LF_GetValueFromJSON.

Outputs are string (the chosen value) and string_list (same thing as a list, for nodes that want lists). Wire string into your prompt encoder or filename builder and move on.

A small reality check

This is one of those nodes where the name sounds like it does more than it does. It's not a text router, it doesn't support more than two branches, and the condition can't be a string comparison - it must be an actual boolean. If you need multi-way routing, you chain several of these or grab a multi-switch node from a different pack. For exactly two options, though, this is the node.

Installing it

Standard LF Nodes install:

cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/comfyui-lf

or ComfyUI Manager → LF Nodes → install → restart. No dependencies, no models.

Where people get burned

  • Forgetting the default. boolean starts as false, so the first time you wire this in and see on_false come out, it's not broken - you just haven't connected (or flipped) the condition yet.
  • Multiline strings and the empty default: if on_true starts empty and you flip the boolean, you get an empty string silently. Fill both branches before you queue.
  • The pack itself is legacy - migrated to lf-nodes in early 2025 - so treat this as stable, finished code. It won't gain features, and it doesn't need to.
Category✨ LF Nodes/Logic

Inputs (4)

NameTypeDefaultDescription
on_trueSTRINGValue to return if the boolean condition is true.
on_falseSTRINGValue to return if the boolean condition is false.
booleanBOOLEANfalseBoolean condition to switch between 'on_true' and 'on_false' values.
ui_widgetoptKUL_PROGRESSBAR[object Object]

Outputs (2)

NameTypeDescription
stringSTRING
string_listSTRING