TextShuffleAndTruncate
Shuffle your tags and cut the prompt to fit the encoder
- clip
- shuffled_text
- text_words
- text_clip_l
- text_clip_g
- text_t5
Two jobs, one node. It shuffles the order of the words (or tags) in your prompt, and it truncates the prompt so it actually fits inside your text encoder instead of getting silently chopped. If you work with long booru-tag prompts or you're trying to shake a model out of a rut, this is a genuinely handy little tool.
Why bother shuffling? Because token position matters. Encoders weight earlier tokens more heavily, and a model can get stuck leaning on whatever tag happens to sit at the front. Reordering on a seed lets you explore the same prompt from different angles without rewriting it - a poor man's prompt-augmentation. And why truncate deliberately? Because the classic CLIP context window is 77 tokens; go past it and the tail gets dropped whether you meant it to or not. Doing the cut yourself, at a word or token count you choose, means you know exactly what the model saw.
How it works
You feed it text and a separator (a space, by default). It splits on that separator, shuffles the pieces using your seed, then trims down to your word and token limits. If you also connect a CLIP, it can measure length against the real tokenizers and hand back versions trimmed per encoder - which matters when a workflow uses CLIP-L, CLIP-G and T5 together (SD3.5, Flux) and each has its own idea of how many tokens fit.
The inputs and outputs that matter
text(STRING) - the prompt to process.separator(default a single space) - what counts as a boundary between shufflable chunks. Set it to,for comma-separated tags.truncate_words_to(default 77) andtruncate_tokens_to(default 77) - the two limits. The 77 defaults are a nod to CLIP's context window.seed- controls the shuffle. Fix it to reproduce an order; increment it to explore.clip(optional CLIP) - plug this in to get accurate per-encoder token counts.
Outputs: shuffled_text (the reordered, truncated prompt - the one you'll usually route to your encoder), text_words, and three encoder-specific strings, text_clip_l, text_clip_g and text_t5, for wiring straight into a multi-encoder setup.
How to install it
Comes with RES4LYF. ComfyUI Manager: search RES4LYF, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/ClownsharkBatwing/RES4LYF/
cd RES4LYF
pip install -r requirements.txt
Embedded pip for portable builds. Restart, hard-refresh with F5.
Common issues
The one that surprises people: shuffle changes the image. If you're A/B testing some other setting and forgot the seed here is moving, you'll chase a difference that's really just tag order - so pin the seed when you want a controlled comparison. Second, the per-encoder outputs only reflect real token counts if you actually connect a CLIP; without it, the token truncation is best-effort on a generic split. And if you set the separator wrong - leaving it as a space on a comma-tag prompt - it'll shuffle individual words inside your tags and turn "blue eyes" into nonsense. Match the separator to how your prompt is written.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| separator | STRING | — | |
| truncate_words_to | INT | 771–10000 | — |
| truncate_tokens_to | INT | 771–10000 | — |
| seed | INT | 00–18446744073709550000 | — |
| clipopt | CLIP | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| shuffled_text | STRING | — |
| text_words | STRING | — |
| text_clip_l | STRING | — |
| text_clip_g | STRING | — |
| text_t5 | STRING | — |