Nodes/ComfyUI-Apt_Preset/text_StrMatrix
ComfyUI Node

text_StrMatrix

Cartesian-product your prompt lists into a matrix of strings

By cardenluo·Created 2 years ago·Updated a day ago· 324
text_StrMatrix
  • a
  • b
  • c
  • d
  • string_Matrix
  • string_lsit
fstring{a}_{b}_{c}_{d}
max_count4

Prompt sweeps have a shape problem: you have three styles and four subjects and you want every combination, but building that in the graph means six branches of copy-paste. text_StrMatrix does the combination math for you. Feed it lists for a, b, c, d, give it an fstring template, and it produces every combination as a list of strings. It's a prompt-sweep generator dressed as a data node.

It's part of ComfyUI-Apt_Preset, the cardenluo pack whose whole pitch is "fewer nodes, clearer workflows." This node is the pack's take on combinatorial prompting, and it's one of the more clever things in the prompt drawer.

How it works

Here's the detail that matters: the four optional inputs a, b, c, d are any-type lists. The node computes the cartesian product across them - every a paired with every b, and so on - formats each combination into your fstring template, and returns the results as a list of strings.

The fstring default is {a}_{b}_{c}_{d}, which is the classic filename-adjacent style: red_metal_rim_light reads like a prompt fragment you'd then join with actual words. Change it to {a} {b}, {c} lighting if you want something closer to a sentence. Any input you don't connect is treated as a single empty slot, so the product just doesn't expand along that axis.

max_count caps the total number of combinations (default 4, up to 999). That's your safety valve: three lists of 10 are 1000 combos by default math, and you almost never want that in one run. Raise it deliberately, leave it low otherwise.

Inputs and outputs

  • fstring - the template with {a}, {b}, {c}, {d} placeholders.
  • max_count - combination cap.
  • a / b / c / d - optional any-type lists. Wire them from any list output: a wildcard batch, a text splitter's list_output, or the pack's own list nodes.
  • Outputs: string_Matrix (a list of strings - the combo list) and string_lsit (a LIST type, same data; the typo is the author's, not yours).

Installing it

Same pack, one install. ComfyUI Manager → search ComfyUI-Apt_Preset, or:

cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset

Restart ComfyUI; on Windows, install.bat pulls the pack's requirements. Nothing exotic needed for this node itself - it's pure string formatting.

Common issues

The two things that bite: forgetting the inputs are list-typed (a plain string won't expand - connect it to a list output, not a text node), and blowing past max_count without noticing. Because the output is a list of strings, the downstream node has to accept lists - wire string_Matrix into a node with a list input or use the pack's type_ converters if you need each combo on its own wire. And since it's part of a fast-moving mega-pack, pin the pack version if a workflow you rely on breaks after an update.

CategoryApt_Preset/prompt

Inputs (6)

NameTypeDefaultDescription
fstringSTRING{a}_{b}_{c}_{d}
max_countINT41–999
aopt*
bopt*
copt*
dopt*

Outputs (2)

NameTypeDescription
string_Matrix*
string_lsitLIST