Nodes/ComfyUI-Aimidi-nodes/Move Tag To Top
ComfyUI Node

Move Tag To Top

Put your quality tags where the model actually reads them

By AiMiDi·Created 2 years ago·Updated 2 years ago· 0
Move Tag To Top
    • STRING
    move_tag_number1
    move_tag
    tag_text

    Move Tag To Top hoists specific tags to the front of a comma-separated tag string. You tell it which tags to move and how many of them are allowed to move; it finds them, yanks them out of wherever they sit, and drops them at position 0. It's the single most useful tag node in this pack, and here's why it matters.

    On every SDXL-lineage model - Illustrious, NoobAI, WAI, Pony - earlier keywords get stronger attention. That's not folklore, it's how the CLIP encoder works: the first tokens you feed it carry more weight. So the tags that control overall composition and quality (masterpiece, best quality, very aesthetic on Illustrious, score_9, score_8_up on Pony) deserve the front of the string. But WD14 taggers and caption sources don't sort by importance - they dump tags in whatever order they were generated. This node is the fix: run a tagger dump through it and tell it which tags you want leading.

    How it works

    The node splits your tag_text on commas, then walks through the tags you listed in move_tag. For each one that exists in the string, it removes the original occurrence and inserts the tag at the front, and increments a counter. It stops once that counter hits move_tag_number. So the number isn't "how many tags to move" in the sense of a batch - it's the cap on how many moves actually happen. Set it to 1 and only the first matched tag in your list gets hoisted.

    Two details worth knowing. A tag that appears multiple times in the source gets collapsed to a single front copy - deduplication is a side effect. And matching is exact after whitespace trimming, so masterpiece won't match masterpiece, best as one unit. Comma-separated lists, always.

    Inputs and output

    • move_tag (required, multiline): the tags to move, comma-separated.
    • move_tag_number (required): how many of them may be moved, default 1.
    • tag_text (optional): the string to operate on.
    • STRING output: the reordered string.

    The typical chain: tag source (like Load Images Pair Batch) → Merge Tag to combine → Move Tag To Top for ordering → the sampler. It plays especially well with the rest of this pack, which shares the same comma-separated convention.

    Installing it

    Nothing special - the pack has no requirements.txt, no model downloads, and uses only libraries ComfyUI already ships. The README is empty, but that's fine; the source is a dozen lines. Install via ComfyUI Manager (search ComfyUI-Aimidi-nodes) or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/AiMiDi/ComfyUI-Aimidi-nodes
    

    Restart ComfyUI; a blue ComfyUI Aimidi Nodes: Loaded message means it's live.

    Common issues

    The most common failure: you set move_tag_number and expect that many tags moved, but the node stopped early - which happens when a listed tag isn't in the source string at all (it only counts successful moves). Also, remember the front-insertion order quirk shared with Add Tag: when multiple tags move, the last one listed lands first. And if your quality tags never make it to the front, verify they're actually present in the source - a WD14 dump may not contain masterpiece if the tagger didn't score it.

    CategoryAimidi Nodes

    Inputs (3)

    NameTypeDefaultDescription
    move_tag_numberINT1
    move_tagSTRING
    tag_textoptSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING