π² Categorized Random Prompt Formatter
Random prompts that still follow your rules
- random_prompt
- used_seed
Everyone's tried the "just mash random tags together" approach to prompt variety, and it produces exactly what you'd expect: word salad. The π² Categorized Random Prompt Formatter is the version that actually works, because it randomizes within categories you define, not across the whole universe of tags. It's the node in this pack that gets by far the most attention, and for good reason - it's the one that does something you can't trivially do with a wildcard file.
Feed it a template like <|quality:1|>, <|character:1|>, <|hair_style:2|>, <|setting:1|>, and it picks one tag from your quality category, one from character, two unique ones from hair_style, one from setting, and joins them into a finished prompt. Same structure every time, different content each run. That's the whole trick: it samples from your YAML categories instead of inventing syntax.
How it works
Categories live in a plain YAML file (a prompt_categories.yaml ships with the pack). Each category is a list of tags, and the node resolves them at runtime - including hierarchical includes like $other_category and inline expansion like $colors $items, which the README documents in detail. The template is just text with <|category|> placeholders dropped in wherever you want them:
<|category|>picks 1 random tag.<|category:N|>picks N unique random tags (if fewer exist, you get all of them; N=0 gives none).- It also understands the dynamic-prompt syntax
{red|blue|green}and even weighted picks like{0.2::red|0.8::blue}inside your template or inside tags - the same{a|b|c}convention Impact Pack made famous.
One thing the README undersells: the code supports a probability suffix, so <|character:1:0.5|> only includes a character about half the time. Handy for "sometimes there's a second subject" prompts.
The inputs that matter
You'll set three things and ignore the rest:
category_definition_file- name or path of your YAML. Defaults toprompt_categories.yaml, which the node looks for next to the pack, then in ComfyUI'sinput/folder. You can wire in theoutput_yaml_pathfrom the pack's Wildcard Importer node here.output_template- the structure with<|category:N|>placeholders. This is your whole creative control; the rest is plumbing.seed- the default-1rolls a fresh random seed every run, which is what you want while exploring. Set any other number and the exact same prompt comes back every time - that's your reproducible baseline for batch jobs or bug reports. (The README talks about seed 0 meaning "random", but the code keys off-1; either way, the point is a fixed number locks the output.)
Outputs: random_prompt (the string you feed into a CLIP Text Encode positive input) and used_seed (the seed that actually ran - wire this to a text display if you roll a good one and want to keep it).
Installing
ComfyUI Manager (search "ComfyUI-Prompt-Formatter"), or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/xLegende/ComfyUI-Prompt-Formatter
Restart ComfyUI. That's the whole install: the only dependency is PyYAML, which is basically always already present, and there are no model files to download - this is pure text processing, CPU-only, runs in a millisecond.
Common gotchas
The failure mode that'll trip you up is silence. If the node can't find your YAML - or a category in the template doesn't exist - it prints a warning to the ComfyUI console and returns an empty string. You get a blank prompt, no error bubble. So when your random prompt comes out empty, check the console first, then the filename, then whether the category name in your template exactly matches a key in the YAML (matching is case-insensitive by default, so the typo is usually a missing category, not a casing one).
Also note it samples from sorted() tags internally, so "random" isn't uniform-order-sensitive across categories - don't read anything into the ordering. It's a small, honest utility, and for a pack with essentially zero community chatter, it's the node people actually reach for.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| category_definition_file | STRING | prompt_categories.yaml | β |
| output_template | STRING | <|quality:1|>, <|character:1|>, <|setting:1|> | β |
| seed | INT | -1-1β18446744073709550000 | β |
| output_delimiteropt | STRING | , | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| random_prompt | STRING | β |
| used_seed | INT | β |