Complex Prompt Set Variable
Store a prompt variable once, reuse it everywhere — with real logic attached
- vars
- vars
- wasSet
Complex Prompt Set Variable is the workhorse of the Complex Prompt pack. It creates or updates one entry in a ArtemKo7vComplexPromptVars object - think of it as a named slot you fill once and reference everywhere. Chain a few of these together, feed the result into the main Complex Prompt node, and suddenly one prompt can be "a portrait of $person near $vehicle" where you've already decided who and what those are, per generation. No more editing text boxes by hand between batches.
How it works
The pipeline on value is the interesting part. The value you type can itself contain dynamic prompt syntax, so {Ada|Grace|Katherine} gets expanded to a single pick (seeded). Then any $variables already in your vars object get substituted in. Finally, if trim is on, whitespace, newlines, and tabs get stripped from both ends - which matters when your value is a multiline block and you don't want stray newlines leaking into your final prompt. Only after all that does it store the result under variable_name.
The condition is the real feature
That's the node's personality. The condition input is an optional expression evaluated with the simpleeval library against your current variables, and if it doesn't evaluate truthy, the variable is not stored. The syntax is friendly: && and || work as and/or, ! as not (except in !=), comparisons like ==, <, > work, and int(), float(), str() are available for conversions. A variable reference is just $name, no braces needed:
($style == "cinematic") && ($count >= 2)
Two behaviors worth knowing: a missing variable makes the condition evaluate to false (so the store is skipped rather than erroring), and comparisons try numbers first, falling back to string comparison if the conversion fails. It's a small scripting language hiding inside a prompt pack.
Inputs and outputs
- variable_name - the key you'll reference as
$variable_name. - value - multiline; expanded and substituted before storage.
- condition - the gate. Empty means always store.
- seed - feeds the wildcard expansion in
value. - trim - BOOLEAN, strips whitespace before storing.
- vars (optional) - the object to extend; feed the previous Set Variable's output in to chain.
Two outputs, and the second one is the sleeper hit:
- vars - the updated
ArtemKo7vComplexPromptVarsobject, chained forward. - wasSet - a BOOLEAN that's
truewhen the variable was stored andfalsewhen the condition blocked it. Wire that into a switch or conditional router and you've got actual workflow branching: "if this condition held, we set a variable, take path A; otherwise path B." That's how this pack stops being just a prompt tool and becomes light logic.
Installing it
Via Manager: search "ComfyUI Complex Prompt Nodes" and install. By hand:
cd ComfyUI/custom_nodes
git clone https://github.com/ArtemKo7v/ComfyUI-Complex-Prompt
cd ComfyUI-Complex-Prompt
pip install -r requirements.txt
Restart ComfyUI. Dependencies are dynamicprompts>=0.31.0 and simpleeval>=1.0.7 - small, no models. If you hand-clone and skip the pip step you'll get an ImportError for simpleeval the first time a condition runs; that's the install step, not your condition.
The trap that catches everyone
Chain your vars. This custom type travels by value through the graph, so if you forget to wire the vars output from one Set Variable into the next, each node starts from an empty dict and your variables silently vanish - they show up as literal $name text in the final prompt. That's actually a useful diagnostic: literal $name in output means the substitution never saw a value. And keep variable_name to identifier-safe characters ([A-Za-z_][A-Za-z0-9_]*). The README is honest that invalid names aren't rejected at input time - they're just unreferencable. Name it like a Python variable and you'll never hit it.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| variable_name | STRING | — | |
| value | STRING | — | |
| condition | STRING | — | |
| seed | INT | 00–18446744073709550000 | — |
| trim | BOOLEAN | false | — |
| varsopt | ArtemKo7vComplexPromptVars | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| vars | ArtemKo7vComplexPromptVars | — |
| wasSet | BOOLEAN | — |