Nodes/ComfyUI-MDSNodes/String Selector by Key (8 Strings)
ComfyUI Node

String Selector by Key (8 Strings)

Eight prompts, one lookup, zero spaghetti

By MarwanDSAI·Created 3 months ago·Updated about 15 hours ago· 3
String Selector by Key (8 Strings)
    • value
    • slot
    ◄key►
    ◄key1►
    ◄value1►
    ◄key2►
    ◄value2►
    ◄key3►
    ◄value3►
    ◄key4►
    ◄value4►
    ◄key5►
    ◄value5►
    ◄key6►
    ◄value6►
    ◄key7►
    ◄value7►
    ◄key8►
    ◄value8►
    ◄default►
    ◄case_sensitivefalse►

    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_sensitive off, both the needle and the slot key are stripped of surrounding spaces and lowercased - so portrait , Portrait and portrait all match. Turn it on for exact work.
    • No match returns default on value, and 0 on slot.

    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.

    CategoryMDSNodes/text

    Inputs (19)

    NameTypeDefaultDescription
    keySTRINGLookup name.
    key1optSTRINGSlot 1 name. Match this against the key input.
    value1optSTRINGSlot 1 text. Returned on value when key matches key1.
    key2optSTRINGSlot 2 name. Match this against the key input.
    value2optSTRINGSlot 2 text. Returned on value when key matches key2.
    key3optSTRINGSlot 3 name. Match this against the key input.
    value3optSTRINGSlot 3 text. Returned on value when key matches key3.
    key4optSTRINGSlot 4 name. Match this against the key input.
    value4optSTRINGSlot 4 text. Returned on value when key matches key4.
    key5optSTRINGSlot 5 name. Match this against the key input.
    value5optSTRINGSlot 5 text. Returned on value when key matches key5.
    key6optSTRINGSlot 6 name. Match this against the key input.
    value6optSTRINGSlot 6 text. Returned on value when key matches key6.
    key7optSTRINGSlot 7 name. Match this against the key input.
    value7optSTRINGSlot 7 text. Returned on value when key matches key7.
    key8optSTRINGSlot 8 name. Match this against the key input.
    value8optSTRINGSlot 8 text. Returned on value when key matches key8.
    defaultoptSTRINGFallback text. Returned on value when key matches none of key1 to key8. Slot output is 0.
    case_sensitiveoptBOOLEANfalseOff: case and surrounding spaces are ignored.

    Outputs (2)

    NameTypeDescription
    valueSTRINGMatched multiline text from the selected slot, or default if nothing matched.
    slotINTMatched slot number 1 to 8. 0 means no match and default was used.