DP Prompt Token Compressor
Trim a bloated prompt down to a token budget
- compressed_prompt
- token_count
- compression_info
If you write prompts the way most people do - start focused, keep adding "just one more" descriptor - you eventually blow past what the text encoder actually pays attention to, and everything past that point gets truncated or ignored. This node is a shortcut for the fix: feed it a prompt, tell it a token budget and which model family you're targeting, and it hands back a shorter version that tries to keep the important words and cut the filler.
Why this is a real problem, not a hypothetical one
CLIP-based encoders - the ones behind SD 1.5, SDXL, and Flux's CLIP-L half - process text in 77-token chunks. Go over, and depending on your frontend you either get silent truncation or an automatic chunk split that can scramble which words are attending to which. Cramming in masterpiece, best quality, ultra detailed, 8k, highly detailed, sharp focus... at the front of every prompt is exactly the kind of thing that eats your budget before you've described anything you actually care about.
One honest caveat before you reach for this on everything: the model_type choices here are sd1, sd2, sdxl, and flux - the CLIP-family lineup. The 77-token wall does not exist on 2026's LLM-encoded models (Z-Image, Anima, Flux 2 Klein, Krea 2) - their attention budget is looser and governed differently, and community testing puts the practical drift point around 75-100 effective tokens rather than a hard cutoff. This node is built for the CLIP era. If you're writing for one of the newer LLM-encoded checkpoints, compressing for a 77-token wall that doesn't apply there will cut things you didn't need to cut.
How it works
You set target_tokens (defaults to the classic 77), pick model_type so it knows which tokenizer behavior to target, and choose preservation_mode to steer what survives the cut: balanced, subject_focus (protect the main subject description over stylistic modifiers), or style_focus (the reverse - keep the aesthetic language, trim subject detail).
Inputs and outputs
Required:
target_tokens(1-225, default 77) - the budget you're compressing down to.model_type-sd1,sd2(default),sdxl, orflux.preservation_mode-balanced(default),subject_focus, orstyle_focus.
Optional: prompt (multiline text) - the prompt to compress.
Three outputs: compressed_prompt (the trimmed text, ready to wire into your positive-prompt input), token_count (an INT so you can confirm it actually landed under budget), and compression_info (a STRING with details on what changed - useful for sanity-checking the cut rather than just trusting it blind).
Installing it
ComfyUI Manager: search ComfyUI-Desert-Pixel-Nodes, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/DesertPixelAi/ComfyUI-Desert-Pixel-Nodes
Restart ComfyUI - text-only processing, nothing to download.
Where people get tripped up
Setting target_tokens to exactly 77 on SDXL and expecting that to match SDXL's real capacity is the most common mismatch - SDXL runs two text encoders concatenated, so its effective per-encoder budget isn't quite the same single-77 math as SD 1.5. Treat 77 as a reasonable conservative default rather than a precise ceiling for SDXL specifically, and use token_count on the output to verify rather than assume.
The other trap is preservation_mode mismatch with intent: if your prompt is mostly a character description with a couple of style tags tacked on and you pick style_focus, you'll likely lose the subject detail you actually needed and keep aesthetic words that were doing less work. Match the mode to what the prompt is actually for, and check compression_info after a run before trusting the output blind - it's there specifically so you don't have to.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| target_tokens | INT | 771–225 | — |
| model_type | COMBO | sd2 | 4 options: sd1, sd2, sdxl, flux |
| preservation_mode | COMBO | balanced | 3 options: balanced, subject_focus, style_focus |
| promptopt | STRING | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| compressed_prompt | STRING | — |
| token_count | INT | — |
| compression_info | STRING | — |