Nodes/ComfyRage/⚙️Pre
ComfyUI Node

⚙️Pre

The node that makes {random|wildcard} prompts survive real workflows

By rakkarage·Created 9 months ago·Updated 26 days ago· 0
⚙️Pre
    • SEED
    • STRING
    seed0
    pre({cat, {collar|}|dog, {collar|leash, ({viewer_holding_leash|})|}, {bone||}}), [[ornate_border], simple_background] // test

    Ever type {brown|blonde|black} hair straight into a CLIP Text Encode box and watch each run pick a different option? That's the bracket trick - old A1111 wildcard syntax that ComfyUI quietly still supports. It's a great way to batch 32 images of the same person across different looks with zero extra effort, and the community's been doing it for years. There's just one catch, and it's the one this node exists for: ComfyUI only expands that random syntax when the text is written directly into the CLIP text widget. The moment you refactor the prompt into a subgraph, route it through a reroute, or share a prompt between several encoders, the {...} stops expanding and the model literally sees the curly braces.

    The Pre node from the ComfyRage pack fixes that. It's a text preprocessor: you give it your prompt with all the random blocks, comments, and emphasis syntax, and it hands back the fully-expanded, cleaned-up string as a normal output you can wire anywhere. Same expansion ComfyUI would have done - but you get to see it and reuse it instead of hoping it happened invisibly.

    How it works

    Under the hood it's a small deterministic pipeline: strip /* */ and // comments, expand every {a|b|c} block, convert [de-emphasis] into real (weight) syntax, and tidy up spacing and commas. The useful detail is the seed input. Random choice uses Python's seeded RNG, so the same seed always produces the same expansion - exactly how ComfyUI's own random-syntax handling behaves, and the thing you need if you want to reproduce a generation. Bump the seed, get a different pick.

    The other thing worth knowing: it fails loudly. Unbalanced {, [, or ( raises a ValueError instead of silently mangling your prompt, and a random block with no | inside errors too. For a syntax that lives inside a text box, that "tell me I typo'd" behavior is genuinely nicer than the alternatives.

    Inputs and outputs that matter

    Only two inputs, and you'll touch both:

    • seed (INT) - drives which random option gets picked. Default 0; change it to shuffle the choices.
    • pre (STRING, multiline) - the raw prompt. This is where the whole prompt with {cat, {collar|}|dog, ...} and // comments lives.

    Outputs are SEED (INT, the same seed you passed) and STRING (the processed text). That STRING is the whole point: wire it into a CLIP Text Encode, or into ComfyRage's own Show or Debug node if you want to eyeball the result before it hits the encoder. Because the output is a normal wire, you can tee the same expanded prompt into several encoders - positive, negative, SDXL's L and H branches - without pasting it three times.

    Installing it

    It ships in the ComfyRage pack, and this is one of the friendlier installs in the ecosystem: zero pip dependencies, no model downloads, public domain license. ComfyUI Manager: search ComfyRage and hit Install, then restart. Or the manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/rakkarage/ComfyRage
    

    Restart ComfyUI and the nodes appear under the rage category.

    Where people get tripped up

    The seed gotcha is the real one. People expect {a|b} to keep changing forever; it doesn't if you've locked the seed elsewhere in the graph. Since Pre reuses whatever seed you feed it, if your workflow passes a fixed seed from a seed node, the random pick freezes too - that's a feature (reproducibility), just surprising the first time.

    Also remember Pre is a preprocessor, not a display node. It returns the expanded text; it doesn't show it to you on the node. If what you want is "expand it and show me the result," that's literally what the sibling PreShow node is for. Pre is for when you need the string to flow onward - which, honestly, is most of the time.

    Categoryrage

    Inputs (2)

    NameTypeDefaultDescription
    seedINT00–18446744073709550000
    preSTRING({cat, {collar|}|dog, {collar|leash, ({viewer_holding_leash|})|}, {bone||}}), [[ornate_border], simple_background] // test

    Outputs (2)

    NameTypeDescription
    SEEDINT
    STRINGSTRING