Nodes/comfyui_tag_filter/TagRandomCategory
ComfyUI Node

TagRandomCategory

Want a random prop? ask the category, not the list

By sugarkwork·Created 2 years ago·Updated 6 months ago· 89
TagRandomCategory
    • tags
    category
    negative_category
    count1
    seed1234

    TagRandomCategory is the smarter cousin of TagRandom: instead of shuffling a list you wrote, it keeps a whole dictionary of categorized Danbooru tags in the pack and draws random ones from whatever category you name. Feel like a random prop in the shot? Type props. Need a random location? Type location. It turns "I don't know what to add" into a single text field, which is exactly the niche the author built it for.

    What it actually does

    The pack ships a category map of tens of thousands of Danbooru-style tags (the current code reads tag_category_v3.json, roughly 67k tags, each mapped to a list of categories like expression, color, hair_style). This node builds a pool of every tag whose category list contains what you asked for, then samples from it. The README's own framing is the best description: "I want some small prop" → props; "I want some kind of location" → location.

    Two details make it more useful than a plain random pick:

    • negative_category - draw from clothing but exclude anything that's also tagged color, so you get clothes without fighting the palette.
    • Seeding - same seed, same selection, so you can lock in a roll you like.

    Mechanically it samples count tags per category listed (with replacement), then de-duplicates and joins them with commas. Note the dedup: list three categories with count 2 and you can get up to six tags, but a tag that lives in two of your categories is emitted once, not twice.

    The inputs that matter

    • category - what to draw from, comma-separated if you want several. Matching is forgiving: lowercase, spaces become underscores, so hair style finds hair_style.
    • negative_category - tags belonging to these categories get excluded.
    • count - how many per category, 1–100.
    • seed - the reproducibility knob.

    Output is a single tags STRING, ready for a text concat or CLIPTextEncode.

    Where people get burned

    The author says it straight: if you feed every element of the workflow from this node, you get images that make no sense - "which is, of course, its own kind of interesting." That's the real failure mode. The randomness is per-category and uncoordinated, so a location draw and a props draw have no idea what each other picked. Fine for brainstorming, chaos for a character you need to keep consistent.

    The other practical gotcha is the dedup shortfall. Because selection uses choices (with replacement) and then dedups, you can ask for count 3 and get back 2 if the random draws collided. Not a bug - just don't build a workflow that assumes an exact count.

    Install

    Same pack as the rest of comfyui_tag_filter - ComfyUI Manager, search "comfyui_tag_filter". Or by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/sugarkwork/comfyui_tag_fillter
    

    Restart after. The repo has no dependencies and no models to download; the entire engine is those category JSON files, so this installs in seconds.

    Categorytext

    Inputs (4)

    NameTypeDefaultDescription
    categorySTRING
    negative_categorySTRING
    countINT11–100
    seedINT12340–9223372036854776000

    Outputs (1)

    NameTypeDescription
    tagsSTRING