Nodes/Dynamic Prompt Nodes/Dynamic Prompt (Random)
ComfyUI Node

Dynamic Prompt (Random)

Roll the Dice on Your Prompts — Deterministically

By cesasol·Created 6 months ago·Updated 4 months ago· 0
Dynamic Prompt (Random)
    • prompt
    template
    seed0

    You already know the trick: wrap a few alternatives in {brown|blonde|black} and let the sampler explore instead of you hand-typing forty prompts. Dynamic Prompt (Random) is that trick turned into a proper node - it implements the old A1111 sd-dynamic-prompts syntax natively, so the {a|b|c} you used in WebUI just works in ComfyUI. No external generator, no API, nothing to install beyond the pack. If you've ever envied Impact Pack's wildcard setup but wanted the full syntax from the A1111 era, this is the node to start with.

    The pitch is variety with reproducibility. Build a template like a {young woman|old man|dog} in a {rainy|sunny|snowy} street, 35mm film and each run samples a different combination. The famous use case from the community is character reference libraries: batch a fixed subject through different settings, camera language and moods, and you get the same person across a whole set with zero training runs.

    How it works

    The node parses your template into an AST, then evaluates it using Python's random.Random(seed). That last detail is the whole game: the same seed always produces the same sampled prompt. Randomness here isn't chaos, it's a deterministic lookup table keyed by the seed. The node's IS_CHANGED returns the seed too, which means ComfyUI only re-executes it when the seed changes - so leave the seed alone and you get the exact same prompt back every run, which is fantastic when you're chasing a look.

    Beyond {a|b|c}, the parser understands the full sd-dynamic-prompts bag: {2$$...} to pick exactly two, {3::rare|1::common} for weighted odds, wildcard files via __animals__, and variables with ${x=value}. If your template starts with __, the node also gives you a wildcard dropdown in the UI to insert the name without typos.

    The inputs that matter

    Honestly there are only two, and they're both in the required list:

    • template - your prompt with {...} variants and __wildcard__ references. Multiline, so go to town.
    • seed - INT, default 0, up to 2^31−1. Bump it to reroll; keep it fixed to reproduce.

    The single prompt (STRING) output wires straight into a CLIPTextEncode node's text input, replacing your static prompt box.

    Installing it

    Search Dynamic Prompt Nodes in ComfyUI Manager and install, or do it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/cesasol/dynamic_prompt_nodes
    cd dynamic_prompt_nodes
    pip install -e .
    

    It's pure Python with only lark and pyyaml as dependencies - no model downloads, no PyTorch additions, nothing heavy. Wildcard files (.txt or .yaml) live in ComfyUI/custom_nodes/dynamic_prompt_nodes/wildcards/ or ComfyUI/models/wildcards/.

    Where people get burned

    The number one surprise is the reproducibility working too well: you hit Queue expecting a new roll and get the identical prompt, because the seed didn't move. That's not a bug - that's the design. Connect a primitive or a seed node with randomize-on-queue to the seed input and it rerolls properly. Second gotcha: a wildcard that silently stays as literal __name__ text means the file isn't in a watched directory or the name doesn't match - check the path, and remember nested YAML keys use / (__styles/painting__). And know that within a single batch execution the node runs once, so all images in one batch share the sampled prompt; if you want a different roll per image, feed the Combinatorial node's list output instead.

    CategoryDynamic Prompts

    Inputs (2)

    NameTypeDefaultDescription
    templateSTRING
    seedINT00–2147483647

    Outputs (1)

    NameTypeDescription
    promptSTRING