Nodes/ComfyAngel/Text Permutation 🪽
ComfyUI Node

Text Permutation 🪽

Turn {cat,dog} on {chair,sofa} into four prompts

By ThepExcel·Created 8 months ago·Updated about a month ago· 14
Text Permutation 🪽
    • texts
    • combined
    • count
    templatea {red,green,blue} {cat,dog} sitting on a {chair,sofa}
    separator,
    output_delimiternewline
    trim_optionstrue

    Text Permutation is the headline utility in ComfyAngel: the node that expands a template with inline {option1,option2} groups into every combination. Write one line like a {cat,dog} on a {chair,sofa}, and it hands you a list of four complete prompts - "a cat on a chair", "a cat on a sofa", "a dog on a chair", "a dog on a sofa" - ready to feed a batch workflow.

    If you've ever hand-written twelve prompt variants for a comparison grid, you know why this exists. It's the same family of convenience as wildcard/dynamic-prompt systems, but with one difference that some people genuinely prefer: the output is an explicit enumerated list you can see and count, rather than a thing that resolves magically at queue time. You know exactly how many prompts you're about to run before you run them. Pair it with the pack's own Loop Start / Loop End nodes - the README's example literally does Text Permutation → Loop Start → generate - and you get a reproducible batch sweep without Auto Queue gymnastics.

    How it works

    Under the hood it's a regex plus a cartesian product. Every {...} group is found, split on the separator (default ,), each option is trimmed if trim_options is on, and itertools.product generates all combinations - multiplying the groups together, not adding them. Then each group's placeholder is replaced with the chosen option to build the finished strings.

    Inputs and outputs that matter

    • template - the only required input, with {a,b,c} inline options. It's a multiline box, so you can build long prompts in place.
    • separator - what splits options inside the braces, default ,. Change it if your options themselves contain commas.
    • trim_options - default true: strips whitespace around each option so { cat, dog } works like {cat,dog}.
    • output_delimiter - how the combined output is joined (newline default, comma, comma_space, pipe, semicolon, space).

    Three outputs: texts (the list of all combinations - the thing you loop over), combined (the same list flattened into one string with the output delimiter), and count (how many combinations you got).

    The trap: it multiplies

    The single most important thing to internalize is that options multiply. Three groups with five options each isn't 15 prompts, it's 125. Five groups of six is 7,776 - and there's a hard cap of 10,000 combinations. Past that the node raises a ValueError instead of generating, which is the pack's way of stopping you from accidentally exploding your own RAM. If you want a big sweep, do it in several templates rather than one monster. And if there are no braces at all, the template just passes through with a count of 1.

    Installing

    Install via ComfyUI Manager (search ComfyAngel) or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ThepExcel/ComfyAngel
    

    Restart ComfyUI. Pillow is the only dependency - no models to download.

    CategoryComfyAngel/Utility

    Inputs (4)

    NameTypeDefaultDescription
    templateSTRINGa {red,green,blue} {cat,dog} sitting on a {chair,sofa}
    separatoroptSTRING,
    output_delimiteroptCOMBOnewline6 options: newline, comma, comma_space, pipe, semicolon, space
    trim_optionsoptBOOLEANtrue

    Outputs (3)

    NameTypeDescription
    textsSTRING
    combinedSTRING
    countINT