Text Length
The boring node that saves you from silently truncated prompts
- length
- length_text
Text Length counts the characters, words, or lines in any string and hands you the number as both an integer and a string. It's about as exciting as it sounds, and that's the point - it's a measurement node you drop into a workflow when you need a number that describes some text, not a fancy generator.
Where this earns its keep in real workflows: validating prompts before they hit the sampler. Most CLIP text encoders truncate long prompts, and the truncation is silent - you get an image that quietly ignores everything past the cut. A word count wired into a conditional lets you catch "this prompt is way too long" before you burn a generation on it. Same idea for dynamic prompts assembled by wildcards or templates: Text Length tells you whether the assembled string is empty, suspiciously short, or blowing past a token budget. It's also handy for filename building - "if the tag list is under 5 words, use a longer filename" kind of logic.
How it works
It's plain Python under the hood. Characters mode is just len(text), words splits on whitespace and counts the non-empty pieces, lines splits on newline characters. No models, no VRAM, no dependencies beyond what ComfyUI already ships. If you feed it a string from any source - a text node, an LLM's output, a filename - you get a number back instantly.
The inputs that matter
text- the string to measure. Multiline, so paste freely; just remember newlines count as characters in characters mode.count_mode- pickcharacters,words, orlines. Defaults to characters.
Outputs and wiring
length(INT) - the actual count. Wire this into a compare or conditional node to branch on prompt length, or into anything that wants a number.length_text(STRING) - the same count as a string, for when you're building text like "Prompt: 42 words" or stuffing it into a filename.
Installation
Install the whole pack via ComfyUI Manager (search "DebugPadawan's ComfyUI Essentials"), or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git
Then restart ComfyUI. There are no model downloads and nothing heavy - the pack's requirements list numpy, torch, and opencv-python for its image and math nodes, but this one is pure Python stdlib and needs none of them.
Gotchas
The lines mode has a quirk worth knowing: an empty string counts as one line, because splitting an empty string on \n yields a list containing one empty element. So if you're using Text Length to detect "is this prompt empty?", check the word count or character count instead - an empty string gives you 0 characters but 1 line. That's a real trap, and it's the kind of thing that makes a "should be trivial" conditional fire the wrong way.
Other than that there's not much to break. If the number looks wrong, it's almost always a misunderstanding about what your input string actually contains (trailing newlines, a space that isn't a space) rather than a node bug. This is a small, no-drama utility from a small pack - it does one thing, and if it ever misbehaves the error is in your input, not the environment.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| count_modeopt | COMBO | characters | 3 options: characters, words, lines |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| length | INT | — |
| length_text | STRING | — |