ComfyUI-Complex-Prompt
ComfyUI node for working with complex prompts with support for variables, randomness, and basic logic.
Nodes
Complex Prompt
Takes a multiline text prompt and expands dynamic prompt variants using dynamicprompts.
It can also accept optional ComplexPromptVars input and replace $variable_name
tokens after dynamic prompt expansion.
Example:
a {red|green|blue} car
Outputs one randomly selected variant, such as:
a green car
With variables:
$person in a {red|green|blue} car
If person exists in vars, $person is replaced with its value.
Variable tokens are preserved while dynamicprompts is parsing the prompt.
The seed input is randomized after generation and is passed to dynamicprompts.
Complex Prompt Set Variable
Creates or extends an ComplexPromptVars object.
varsis optional. If it is not connected, the node creates a new object.variable_nameis the key.valueis multiline text expanded throughdynamicprompts, then$variable_nametokens are replaced from the inputvarsbefore it is stored.conditionis optional. If it is set, the variable is only stored when the expression evaluates to true.seedis randomized after generation and is passed todynamicprompts.wasSetis true when the variable was stored and false when the condition prevented the update.
Condition example:
(($var1 == "1") && ($var2 == "2")) || ($var3 < 10)
Conditions are evaluated with simpleeval. $variable tokens are resolved from
the input vars; missing variables make the condition false.
Complex Prompt Parse JSON
Creates or extends a ComplexPromptVars object from a JSON string.
json_textmust be a JSON object.- Object keys become variable names.
- String and number values are copied into
vars. - Boolean, null, object, empty array, and unsupported values are ignored.
- If a value is a non-empty array of strings or numbers, one item is selected
randomly using
seed. varsis optional. If it is not connected, the node creates a new object.
Example:
{
"person": "Ada",
"color": ["red", "green", "blue"],
"age": 37
}
This can produce variables such as:
person = Ada
color = green
age = 37
Configuration
The configuration file is stored at:
ComfyUI/user/default/ComfyUI-Complex-Prompt/config.json