ComfyUI Node

SDXL Auto Break

Stop your prompt from silently truncating at 75 tokens

By alchemine·Created about a year ago·Updated 2 days ago· 2
SDXL Auto Break
  • clip
  • processed_text
text

Here's a quiet way prompts break on SDXL: CLIP encodes in chunks of 77 tokens, and the first and last slots are reserved for start/end markers. That leaves you 75 tokens per chunk, and everything past the boundary gets truncated - or worse, half-truncated mid-tag. Your long, lovingly ordered Danbooru tag prompt is fine on paper and subtly dead past token 75. SDXL Auto Break fixes that by inserting BREAK tokens for you, so each segment of your prompt gets its own full 75-token chunk.

Why you'd reach for it

BREAK is the CLIP-era escape hatch for exactly this problem. It forces a split at the 77-token chunk boundary, which is why it's the standard tool for long tag prompts on SDXL and the anime lineage (Illustrious, NoobAI, Pony). Doing it by hand means counting tokens, guessing where the boundary lands, and re-checking every time you edit the prompt. This node counts for you and places the breaks automatically - it's the difference between maintaining the break math yourself and never thinking about it.

One important scope note: BREAK is a CLIP thing. On modern LLM-encoder models (Flux and friends), there's no chunk boundary to break against and the token means nothing. This node is SDXL-only by design.

How it works

You feed it a CLIP and your text. It tokenizes each segment with the SDXL clip_g tokenizer, filters out the start/end/pad tokens, and counts the real ones. When a segment would cross 75 tokens, it walks back word-by-word to the last split point that stays under the limit, inserts \n\nBREAK\n, and recurses on the remainder - so a really long prompt gets multiple breaks. It deliberately uses the clip_g count (the source has a comment noting it stopped using the max of g and l), and it cleans stray commas around the inserted BREAK tokens afterward so you don't end up with , BREAK artifacts.

Inputs and outputs

  • clip - the CLIP from your SDXL checkpoint. Must expose clip_g/clip_l, which any SDXL CLIP does.
  • text - the prompt to auto-break.
  • processed_text - the re-segmented prompt. Wire this into a CLIP Text Encode (or into SDXL's separate positive/negative G/L encoders) and you're set.

There's no way to configure the target length - 75 is hardcoded, matching CLIP's usable-per-chunk budget.

Installation

This is one node in ComfyUI-Alchemine-Pack. Install via ComfyUI Manager (search "Alchemine") and restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/alchemine/comfyui-alchemine-pack
pip install -r requirements.txt

Then restart ComfyUI. Only hard dependency is python-dotenv; no models to download for the prompt nodes, no API keys.

Common issues

The two things that bite people: feeding a non-SDXL CLIP - if your CLIP doesn't have clip_g, this errors out, so keep it on the SDXL branch of your graph - and expecting magic on modern models. On Flux or an LLM-encoder checkpoint, BREAK is inert and auto-inserting it is just adding tokens. Also worth knowing: this node only counts clip_g tokens, and on some prompts clip_l runs longer, so the inserted breaks are sized to the g side. If you're chasing perfect alignment, pair it with SDXLTokenAnalyzer in the same pack to see both tokenizer counts side by side.

CategoryAlcheminePack/Prompt

Inputs (2)

NameTypeDefaultDescription
clipCLIP
textSTRING

Outputs (1)

NameTypeDescription
processed_textSTRING