String Selector by Key (8 Strings)
Eight prompts, one lookup, zero spaghetti
- value
- slot
A keyed lookup table, implemented as a node. You give it a name, it hands back the matching block of text - one of eight, or a default if none match.
What it's for
The pattern this kills is the branching prompt bank. You're testing one model across five prompt styles, or running a workflow that takes a "pose" setting of standing / sitting / action, or you have per-model-family prompt scaffolding that differs between SDXL and a modern text-encoder model. Without a lookup, that's either five separate workflows or a folder of text files and a Load Text node.
With one, it's a key. Type portrait into the key input, get the 200-word portrait block out of value1. Change the key to fullbody, get slot 2. The eight slots live in the workflow, so the whole prompt bank travels with the JSON and there's no external file to lose.
The second output, slot, is the quiet star: it tells you which slot matched, as an integer. That's how you keep metadata honest - write slot into your metadata and every image in a comparison run records which prompt block produced it, without you maintaining a list.
How it works
The required input is key - a single-line string, and note that it's forced to be an input wire, not a text box. You can't type into it; something upstream has to supply it: a string primitive, a Get Value (Global), a filename-derived value, whatever.
Then eight optional pairs, key1/value1 through key8/value8. Keys are single-line, values are multiline. Plus default (multiline) and case_sensitive (default off).
The matching rules matter, and they're all stated in the node's own description:
- Slots are checked in order, and the first match wins. Slot 1 beats slot 8 if both keys match.
- An empty slot key is skipped, so unused slots cost you nothing.
- With
case_sensitiveoff, both the needle and the slot key are stripped of surrounding spaces and lowercased - soportrait,Portraitandportraitall match. Turn it on for exact work. - No match returns
defaultonvalue, and0onslot.
Outputs: value (STRING, multiline text) and slot (INT, 1–8, or 0 for no match). value goes into a text-encode node; slot goes into metadata, a filename, or a switch.
Installing it
ComfyUI-MDSNodes by MarwanDSAI. ComfyUI Manager: search ComfyUI-MDSNodes (or MDSNodes), install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/MarwanDSAI/comfyui-mdsnodes
# restart ComfyUI
Nothing to pip install; the repo's requirements.txt is empty and the README says no extra packages are needed. No downloads.
Search String Selector by Key (8 Strings), category MDSNodes/text.
Common issues
Nothing matches and you get the default. Nine times out of ten it's the ordering of the slots - a key you thought was unique is being shadowed by an earlier slot with the same value. The other time it's whitespace in a slot key that looks fine on screen; with case_sensitive on, trailing spaces are significant.
You expected the keys to be case-insensitive and they weren't. You turned case_sensitive on, probably while experimenting. When it's on, Portrait will not match portrait, and slot returns 0.
You can't type the key. By design - key is a forced input. Drop a string primitive or a Convert to String in front of it.
Values with newlines came out flattened. Multiline values survive intact through this node, so a flattened result is happening downstream, usually in something that treats the string as a single line - a filename template or a metadata field that doesn't expect newlines.
Inputs (19)
| Name | Type | Default | Description |
|---|---|---|---|
| key | STRING | Lookup name. | |
| key1opt | STRING | Slot 1 name. Match this against the key input. | |
| value1opt | STRING | Slot 1 text. Returned on value when key matches key1. | |
| key2opt | STRING | Slot 2 name. Match this against the key input. | |
| value2opt | STRING | Slot 2 text. Returned on value when key matches key2. | |
| key3opt | STRING | Slot 3 name. Match this against the key input. | |
| value3opt | STRING | Slot 3 text. Returned on value when key matches key3. | |
| key4opt | STRING | Slot 4 name. Match this against the key input. | |
| value4opt | STRING | Slot 4 text. Returned on value when key matches key4. | |
| key5opt | STRING | Slot 5 name. Match this against the key input. | |
| value5opt | STRING | Slot 5 text. Returned on value when key matches key5. | |
| key6opt | STRING | Slot 6 name. Match this against the key input. | |
| value6opt | STRING | Slot 6 text. Returned on value when key matches key6. | |
| key7opt | STRING | Slot 7 name. Match this against the key input. | |
| value7opt | STRING | Slot 7 text. Returned on value when key matches key7. | |
| key8opt | STRING | Slot 8 name. Match this against the key input. | |
| value8opt | STRING | Slot 8 text. Returned on value when key matches key8. | |
| defaultopt | STRING | Fallback text. Returned on value when key matches none of key1 to key8. Slot output is 0. | |
| case_sensitiveopt | BOOLEAN | false | Off: case and surrounding spaces are ignored. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| value | STRING | Matched multiline text from the selected slot, or default if nothing matched. |
| slot | INT | Matched slot number 1 to 8. 0 means no match and default was used. |