ComfyUI Node

Sample Tags

Pull a random handful of tags from a list, no repeats

By nkchocoai·Created 3 years ago·Updated about a year ago· 26
Sample Tags
    • STRING
    tags
    tags_delimiter
    seed0
    max_k1
    min_k1

    Paste in a pool of tags, tell it how many to grab, and Sample Tags hands you back a random subset - no duplicates, count controlled by a range rather than a fixed number. It's wildcard-style randomization, but as a visible node with actual controls instead of {a|b|c} syntax buried inside your prompt text.

    How it works

    tags is a multiline block of tags, split by whichever tags_delimiter you pick - newline or comma. The node then samples somewhere between min_k and max_k of them, without repeats, and joins the picks back into a string. seed controls the draw: same seed against the same tag list gives you the same subset every time, so it's reproducible if you need it to be, or wire a randomizing seed control for fresh variety each queue.

    Inputs and outputs that matter

    • tags - your pool, multiline, split by the delimiter you choose.
    • tags_delimiter - new line or , - pick whichever matches how you formatted the tags field.
    • seed - controls the random draw.
    • min_k / max_k - the range of how many tags get sampled, default 1/1 (exactly one). Bump max_k up for more variety per pull.

    Output is a single STRING - the sampled tags, joined.

    Installing it

    ComfyUI Manager → search ComfyUI-PromptUtilities → install → restart. Or:

    cd ComfyUI/custom_nodes && git clone https://github.com/nkchocoai/ComfyUI-PromptUtilities
    

    Pure Python, no models or extra dependencies. It'll be sitting under the PromptUtilities category once you restart.

    How this compares to the more established wildcard route

    If you've spent any time in ComfyUI, you've probably already met wildcards through Impact Pack - its __wildcard__ file syntax and inline {a|b|c} random-choice syntax are what "a great many workflows depend on without crediting," as the community's own read on it puts it, and that's the far more established route for random tag pools. Sample Tags isn't trying to replace that. Its actual edge is the k-of-n range: pick anywhere from 1 to 4 tags per pull instead of committing to exactly one, and have the tag pool sitting as a visible textbox on the node rather than tucked away in a separate wildcard file you have to go find and edit.

    Where people get burned

    The main one: your delimiter has to actually match how you wrote the tags field. Pick , as the delimiter but write your list one-per-line, and you'll get one giant "tag" containing newlines instead of a clean split - or the reverse. Double-check the output on a small test list before trusting a big pull. Also worth testing: what happens if min_k exceeds how many tags you've actually got after splitting - the README doesn't document the failure mode, so don't assume it clamps gracefully, verify it on a short list first.

    CategoryPromptUtilities

    Inputs (5)

    NameTypeDefaultDescription
    tagsSTRING
    tags_delimiterCOMBO2 options: new line, ,
    seedINT00–18446744073709550000
    max_kINT11–18446744073709550000
    min_kINT10–18446744073709550000

    Outputs (1)

    NameTypeDescription
    STRINGSTRING