ComfyUI Node

PromptLimit

Cut a prompt down to its first N tags — order matters, so this keeps what counts

By Inzaniak·Created 3 years ago·Updated 3 months ago· 26
PromptLimit
    • STRING
    prompt
    separator,
    limit0

    PromptLimit does one thing: it chops a prompt down to its first N tags. Give it a booru-style tag pile from a Ranbooru node and a limit of, say, 30, and you get back the first 30 tags, re-joined with your separator. That's the whole node.

    It sounds almost too trivial to be useful, but in the workflow it ships in, it earns its keep. A raw booru post can carry dozens of tags - real Danbooru posts average around 30, and Ranbooru passes them all through. That's often more than you want in a prompt, and it's definitely more than the SDXL-lineage CLIP encoders handle comfortably at their 77-token boundary. Trimming is the natural move.

    How it works

    Split on the separator, slice off the first limit items, rejoin. The interesting default: limit is 0, which the code treats as "no limit" - the prompt passes through untouched. Set it to 1–100 and the truncation kicks in.

    Why keep the first N and not the last or a random N? Because in CLIP-encoded models, earlier tags get stronger attention. The KB's own guidance on the anime SDXL line is that order matters and the important concepts should go first. So truncating from the front preserves the highest-weight concepts and cuts the long tail of noise - exactly the right shape for turning a raw booru dump into a focused prompt. Put this node after Ranbooru (or any prompt source) and before your CLIP Text Encode.

    Inputs and outputs

    • prompt - STRING, the prompt to truncate.
    • separator - STRING, default ,. Must match how your prompt is delimited; booru output is comma-separated, so the default is right.
    • limit - INT, 0–100, default 0 (no limit).

    Output: STRING, the truncated prompt.

    Installing it

    It ships in the Ranbooru pack: ComfyUI Manager, search "Ranbooru", or

    cd ComfyUI/custom_nodes
    git clone https://github.com/Inzaniak/comfyui-ranbooru
    

    then restart. No requirements.txt - the pack only uses ComfyUI's bundled Python packages - and nothing to download.

    Common issues

    The classic mistake is a separator mismatch: if your prompt uses , (comma-space) but you set separator to ,, every tag after the first gets a leading space, and the truncation boundary lands in odd places. If you're feeding a multiline prompt, set the separator to a newline instead. Also keep in mind that a limit of 0 means "unchanged" - if you set the limit thinking 0 means "keep zero tags", you'll be confused. And one honest caveat: this node is built for the comma-tag style of the booru/anime SDXL world. On an LLM-encoded checkpoint your prompt is an instruction, not a tag bag, and chopping it to N tokens this way is the wrong tool for that job.

    CategoryRanbooru Nodes

    Inputs (3)

    NameTypeDefaultDescription
    promptSTRING
    separatorSTRING,
    limitINT00–100

    Outputs (1)

    NameTypeDescription
    STRINGSTRING