Text Truncate Protect
Cut text down to size without slicing a word or a bracket in half
- truncated_text
- statistics
- final_length
- truncated_chars
A blunt character-limit truncation is fine for most text and quietly destructive for prompts: it cuts mid-word, and worse, it can slice straight through an open parenthesis or a <lora:...> tag, leaving you with a prompt that's both shorter and syntactically broken. Text Truncate Protect, from the illumorae pack (CorvaeOboro's text tools), truncates to a character limit with guardrails - it can hold word boundaries, paragraph boundaries, and enclosure boundaries, so the text that comes out is still valid prompt-shaped text.
Where does that matter in practice? Two places. Keeping a prompt under a hard character budget (a filename limit, or the budget of a model with a small context - pair it with Text Token Count from the same pack to know the real number). And sanitizing auto-assembled prompts: if a script concatenates tags and blows past a limit, you want the trim to respect the structure, not destroy it.
How it works
The node truncates to character_limit (default 500) with a threshold (default 50) that sets how far it's allowed to search for a safe boundary near the limit. Three independent protections:
- protect_words - truncate at a space/newline, preserving whole words (hyphenated words included).
- protect_paragraphs - truncate only at newline boundaries.
- protect_enclosures - never cut inside an enclosure pair;
enclosure_types(all,parentheses,braces,brackets,angle_brackets) picks which pairs count. This is the one that keeps(cat:1.3)and<lora:...>intact.
If no safe point exists inside the threshold window, it picks the closest legal one it can find. The stats come out the other end so you don't have to guess.
Inputs and outputs
- text - multiline input.
- character_limit, threshold - the budget and the search slack.
- The three protection toggles plus
enclosure_types.
Outputs: truncated_text (STRING), statistics (STRING describing what happened), final_length (INT), and truncated_chars (INT). The two integers are the genuinely useful part - wire truncated_chars somewhere or just read it to know how much you lost.
Installing it
ComfyUI Manager → search "illumorae" → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/CorvaeOboro/ComfyUI_illumorae
Restart. No models, no downloads.
Troubleshooting
If output is longer than your character_limit, that's the protection doing its job - it walked to the nearest safe boundary beyond the cutoff, which can overshoot by up to the threshold. Lower the threshold if you want a tighter fit. And a heads-up: enclosure protection only helps if your enclosures are actually balanced; an unclosed paren still gets treated as an opening. Enable protect_enclosures and check the statistics output the first few times - it tells you exactly where it cut and why.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| character_limit | INT | 5001–100000 | — |
| threshold | INT | 500–1000 | — |
| protect_wordsopt | BOOLEAN | false | — |
| protect_paragraphsopt | BOOLEAN | false | — |
| protect_enclosuresopt | BOOLEAN | false | — |
| enclosure_typesopt | COMBO | all | 5 options: all, parentheses, braces, brackets, angle_brackets |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| truncated_text | STRING | — |
| statistics | STRING | — |
| final_length | INT | — |
| truncated_chars | INT | — |