Nodes/ComfyUI Complex Prompt Nodes/Complex Prompt Set Variable By Choice
ComfyUI Node

Complex Prompt Set Variable By Choice

A lookup table for prompt variables — match one value, store another

By ArtemKo7v·Created 4 months ago·Updated 4 months ago· 1
Complex Prompt Set Variable By Choice
  • vars
  • vars
  • wasSet
variable_name
source_variable
choices
seed0
trimfalse

Complex Prompt Set Variable By Choice is the smartest node in the Complex Prompt pack, and it's the one that makes the pack feel like actual logic rather than just text juggling. It reads the current value of one variable, looks it up in a JSON choice map you provide, and stores the matched value under a different variable name. Set gender once, and this node turns it into a coherent name, a wardrobe, a whole prompt fragment. It's a lookup table for prompt content.

How it works

The flow is: read source_variable from your vars (a leading $ is accepted, so both gender and $gender work), look up its value as a key in the choices JSON map, and store the matched value under variable_name. The match is an exact string compare, so male won't match Male and a numeric 3 from JSON won't match the string key "3" unless you write it that way.

Two escape hatches make it practical. If no exact key matches, a __default__ key is used when present. If there's no match and no default, the node stores nothing and reports wasSet = false. The README's example says it best:

{
  "male": "$title {John|Bill|Ted}",
  "female": "$title {Anna|Sarah|Sofia}",
  "__default__": "$title Alex"
}

Notice the matched value isn't just stored raw - it goes through the same expansion as Set Variable. Dynamic syntax {John|Bill|Ted} gets rolled to one pick (seeded), $title resolves against your existing vars, and trim optionally strips whitespace. So the value you store can itself be a mini-prompt built from other variables. That's where the power is: this node doesn't just copy, it derives.

The choices field is forgiving about braces - full JSON {"male": ...} or a bare object body without the outer {} both parse.

Inputs and outputs

  • variable_name - where the matched value gets stored.
  • source_variable - the existing variable whose value drives the lookup.
  • choices - the multiline JSON map, keyed by source values.
  • seed - feeds wildcard expansion inside the matched choice.
  • trim - BOOLEAN, strips whitespace from the stored result.
  • vars - the ArtemKo7vComplexPromptVars object; unlike the other Set Variable node, this one's vars is effectively required because there's nothing to match against without it.

Outputs are vars (the updated object) and wasSet (true when a match or default was stored, false when the source variable was missing or nothing matched). That wasSet flag is your branch signal - it's the difference between "the lookup silently did nothing" and "I know the lookup failed and can route around it." If a source variable or match disappears, that false propagates cleanly.

Installing it

Same pack, one install for all five nodes. ComfyUI Manager → search "ComfyUI Complex Prompt Nodes", or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ArtemKo7v/ComfyUI-Complex-Prompt
cd ComfyUI-Complex-Prompt
pip install -r requirements.txt

Restart ComfyUI after. Deps are just dynamicprompts and simpleeval - no model files, nothing heavy.

Where it shines (and where it bites)

This is the node for coherent character variation: pick a gender once, and every name, outfit, and style string stays consistent across the batch because they all derive from the same source variable. The bite is the exact-match rule. It's case-sensitive and type-sensitive, so take a second to make sure your source values and map keys line up byte-for-byte. And remember __default__ is the literal fallback key - misspelling it is the most common way people end up staring at wasSet = false. For a node with barely a dozen settings, it packs a surprising amount of structure; the README walks through the choice-map syntax if you want to see it all.

CategoryArtemKo7v

Inputs (6)

NameTypeDefaultDescription
variable_nameSTRING
source_variableSTRING
choicesSTRING
seedINT00–18446744073709550000
trimBOOLEANfalse
varsoptArtemKo7vComplexPromptVars

Outputs (2)

NameTypeDescription
varsArtemKo7vComplexPromptVars
wasSetBOOLEAN