Nodes/RES4LYF/TextShuffleAndTruncate
ComfyUI Node Runs on cloud

TextShuffleAndTruncate

Shuffle your tags and cut the prompt to fit the encoder

By ClownsharkBatwing·Created 2 years ago·Updated 17 days ago· 1,222
TextShuffleAndTruncate
  • clip
  • shuffled_text
  • text_words
  • text_clip_l
  • text_clip_g
  • text_t5
text
separator
truncate_words_to77
truncate_tokens_to77
seed0

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) and truncate_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.

CategoryRES4LYF/text

Inputs (6)

NameTypeDefaultDescription
textSTRING
separatorSTRING
truncate_words_toINT771–10000
truncate_tokens_toINT771–10000
seedINT00–18446744073709550000
clipoptCLIP

Outputs (5)

NameTypeDescription
shuffled_textSTRING
text_wordsSTRING
text_clip_lSTRING
text_clip_gSTRING
text_t5STRING