ComfyUI Node

Tag Encode

Turn a scraped Danbooru post into a prompt, without the tags you don't want

By yffyhk·Created 3 years ago·Updated 2 years ago· 1
Tag Encode
    • STRING
    tags
    basic
    remove

    The name is a lie in the best way: Tag Encode doesn't touch a text encoder, a CLIP model, or anything that "encodes." It's a string-surgery utility that takes a comma-separated list of Danbooru tags, strips out the ones you don't want, prepends a base prompt, and hands you one clean string ready for the CLIP Text Encode node. It's one half of the comfyui_auto_danbooru pack - the other half, Get Danbooru, scrapes an actual post from danbooru.donmai.us and feeds it the tag list. Together they're a "recreate this post" pipeline; Tag Encode is the part that makes the scraped tags actually usable.

    Why bother? If you run an Illustrious or NoobAI family model, Danbooru's tag vocabulary is the language the model was trained on - a correct tag beats a sentence for pose, clothing, and camera, and it's the only prompting paradigm those models really speak. Scraping the community's own tags from a post is a fast way to get a composition you like, then regenerate it in your model's style. Tag Encode is the gatekeeper that decides which of those tags make it into the prompt.

    The three inputs that matter

    All three inputs are marked required, and the output is a single STRING. That's the whole node.

    • tags - the comma-separated tag string, marked forceInput, which means you can't type a value into it. It has to be wired from another node. That's deliberate: plug in the TAG output from Get Danbooru (or from any tagger - a WD14 caption works fine too).
    • basic - a multiline string prepended verbatim. This is where your masterpiece, best quality quality tags or a character anchor go.
    • remove - a multiline, comma-separated list of substrings. Any tag containing one of these gets dropped before the prompt is built.

    The output is basic followed by the surviving tags: masterpiece, best quality, 1girl, long hair, smile.

    Where people get burned

    There are three gotchas, and the first one will bite you in the first five minutes. Under the hood, remove splits the empty string into a list containing one empty string - and in Python, '' is a substring of everything. So leave the remove field empty and every single tag gets deleted. You'll get back just your basic string and wonder where the tags went. If you don't want to remove anything, don't leave it blank expecting a no-op; the author's remove() treats blank as "remove all." This is the closest thing the node has to a bug, and it's the one thing to remember.

    Second, removal is substring matching, not exact matching. Add hair to the remove list and you also kill long_hair, hairband, and blue_hair. Be specific - use the full tag names - or accept the collateral damage.

    Third, the surviving tags pass through a Python set() before being rejoined, so the original order is scrambled. Danbooru lists general tags first, then character, artist, and copyright. That ordering carries meaning - earlier tags get stronger attention - and this node shuffles it arbitrarily (while also deduping, which rarely matters since board tags are unique anyway). The content survives; the priority order doesn't.

    Install

    The pack's README is one line long, so this is standard fare: ComfyUI Manager → search comfyui_auto_danbooru, or

    cd ComfyUI/custom_nodes
    git clone https://github.com/yffyhk/comfyui_auto_danbooru
    

    then restart ComfyUI. No model downloads, no API key, no heavy dependencies. The requirements are numpy, torch, requests, beautifulsoup4, and pillow - and everything but BeautifulSoup already ships with ComfyUI. It's one of the lighter installs you'll do.

    One heads-up if you use the sibling Get Danbooru node: the pack scrapes Danbooru's HTML directly with requests + BeautifulSoup rather than calling an API, so the scraper is at the mercy of Danbooru's markup and rate limits. That's upstream of Tag Encode - this node itself only massages strings, and it will keep working no matter what happens to the scraper.

    Honest verdict: it's a small, personal-pack utility with a near-zero community footprint, and standalone it's a slightly quirky string filter. But once you know the empty-remove trap, the substring filtering is genuinely handy for batch-recreating posts - and for such a tiny pack, the code in nodes/nodes.py is short enough to read in one sitting if anything surprises you.

    CategoryDanbooru

    Inputs (3)

    NameTypeDefaultDescription
    tagsSTRING
    basicSTRING
    removeSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING