ComfyUI Node

DP Broken Token

Count CLIP tokens and split a long prompt at the 77-token line

By DesertPixelAi·Created 2 years ago·Updated about a year ago· 25
DP Broken Token
    • total_tokens
    • info
    • Text part 1
    • Text part 2
    • Text part 3
    max_tokens_part_177
    max_tokens_part_20
    prompt

    CLIP text encoders read your prompt in chunks of 77 tokens. Go over, and the prompt gets split at that boundary whether you planned the split or not - which can land a comma or a concept in an awkward place and quietly change your image. This node puts that boundary in your hands: it counts the tokens in your prompt and splits the text into parts at limits you set, so the "break" happens where you want it, not where the encoder happens to land.

    The name is a small joke about that failure mode - the token count "breaks" your prompt at 77, and this helps you control the break. It's from DesertPixelAi's Desert-Pixel-Nodes, a large quality-of-life pack. Nothing here generates images; this is prompt plumbing, essentially the classic BREAK keyword turned into a node with a token counter attached.

    How it works

    You feed in a prompt. The node tokenizes it, reports the total token count, and slices the text into up to three parts. max_tokens_part_1 (default 77, matching the CLIP chunk size) sets where the first part ends; max_tokens_part_2 sets the second cut; whatever's left becomes part three. You then encode each part deliberately - or use the count and info to decide whether your prompt is even over the limit in the first place.

    This is squarely a CLIP-era tool, and that's worth saying plainly. It's useful on SD 1.5, SDXL, and the Illustrious/Pony/NoobAI lineage, where the 77-token chunk boundary is real. On 2026 LLM-encoded models - Flux 2, Z-Image, Qwen-based checkpoints - there is no 77-token wall to break against, the prompt is read as one instruction, and this node has nothing to do. Know which encoder you're feeding before you wire it in.

    The inputs and outputs that matter

    • prompt - the optional multiline text to measure and split.
    • max_tokens_part_1 - where the first split lands. Default 77, the CLIP chunk size; that's the value you usually want.
    • max_tokens_part_2 - the second split point. Default 0, i.e. off, until you need a third part.

    Outputs: total_tokens (an integer - the count) and info (a string report of what it did), plus Text part 1, Text part 2, and Text part 3 (the split pieces). Wire total_tokens to a display to see at a glance whether you're over budget; encode the parts separately when you want full control over where the boundary falls.

    How to install it

    • ComfyUI Manager: search "Desert Pixel", install, restart. No downloads.
    • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/DesertPixelAi/ComfyUI-Desert-Pixel-Nodes, pip install -r requirements.txt if present, restart.

    Under the DP category.

    Common issues

    The trap is using it on the wrong model. On an LLM-encoded model the token math here doesn't correspond to any hard limit, and manually splitting a prompt into three parts can actively hurt, because you're chopping up an instruction the encoder wanted to read whole. If you're on Flux 2, Z-Image, or anything Qwen/Mistral-encoded, skip this node and just write a tight prompt - those models drift past roughly 75-100 effective tokens anyway, and the fix there is fewer words, not a manual break.

    On CLIP models, the usual surprise is that token count isn't word count - punctuation, rare words, and sub-word pieces all cost tokens, so a prompt that "looks short" can still be over 77. That's exactly what total_tokens is there to tell you; trust the number, not your eyeballing.

    CategoryDP/text

    Inputs (3)

    NameTypeDefaultDescription
    max_tokens_part_1INT770–2000
    max_tokens_part_2INT00–2000
    promptoptSTRING

    Outputs (5)

    NameTypeDescription
    total_tokensINT
    infoSTRING
    Text part 1STRING
    Text part 2STRING
    Text part 3STRING