String Switch
A prompt A/B switch that doesn't burn compute on the branches you didn't pick
- text
You want to test three prompts against the same seed, and your instinct is to build three branches - each with its own CLIP encode and its own sampler - then mute two of them. That works, but it's clumsy and, if each branch chains expensive generation, you're paying to evaluate graph you don't need. String Switch is the cleaner pattern: route up to eight string inputs through one node and pick which one comes out with an integer.
The clever bit isn't the switching, it's the laziness. The node declares every input as lazy and implements check_lazy_status, which tells ComfyUI's execution engine which upstream nodes actually need to run. Only the branch feeding the selected input gets evaluated. That's the difference between a switch and a mute button: a muted branch still got queued and computed; a lazy switch never runs the unselected branches at all.
How you'll use it
The canonical case is prompt testing. Build one branch that assembles "photorealistic portrait, golden hour" and another that assembles "studio lighting, teal backdrop," feed both into input_1 and input_2, and flip selected between 1 and 2 with a fixed seed. Same everything else, different prompt, no branch-muting housekeeping.
Where it gets more interesting is when the strings are expensive to produce - a node that queries an API, a long regex pipeline, a style assembler with ten string ops chained behind it. With lazy evaluation, flipping the selector genuinely skips that work. That's the scenario where this node beats the stock alternatives.
The inputs and outputs that matter
selected- the only required input. A 1-based integer, 1 through 8, picking which input passes through. Default 1.input_1throughinput_8- all optional strings. Yes, eight slots is a lot; the realistic setups use two or three.- Output:
text- the chosen string, passed through as-is. Wire it into your CLIP text encoder (positive or negative).
One small behavior note: if the selected input is empty/unconnected, you get back an empty string rather than an error - so it degrades gracefully, which is what you want in a partially-built workflow.
Installing it
Part of MoonPack, installed like the rest:
cd ComfyUI/custom_nodes
git clone https://github.com/moonwhaler/comfyui-moonpack.git
Or ComfyUI Manager → MoonPack → install, restart. Under MoonPack/string. No models, no extra Python dependencies.
Verdict
If you're only ever testing one prompt at a time by hand-editing the box, you don't need this. The moment you're comparing variants - or wiring string-producing pipelines that cost real work - the lazy evaluation is the feature that earns the install. It's the rare "utility" node that actually changes how you structure a graph.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| selected | INT | 11–8 | 1-based index of the input to pass through. |
| input_1opt | STRING | String input #1 | |
| input_2opt | STRING | String input #2 | |
| input_3opt | STRING | String input #3 | |
| input_4opt | STRING | String input #4 | |
| input_5opt | STRING | String input #5 | |
| input_6opt | STRING | String input #6 | |
| input_7opt | STRING | String input #7 | |
| input_8opt | STRING | String input #8 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |