length
Length — the string node you'll actually reach for, constantly
- INT
Every other string node in this pack is a specialist. length is the one that answers questions you ask on every workflow: how long is this string, is it empty, does it fit? You feed it any string and it hands you a real INT - the number of characters - that you can feed into comparisons, padding decisions, and conditional logic.
Concrete reasons you'll reach for it: checking whether a prompt is empty before sampling (length 0), deciding whether to truncate a long string before it hits a field with a limit, computing padding widths, or splitting a string at its midpoint. It's also the natural companion to the is* family - isspace can't tell you a string is empty, but length can.
How it works
This is Python's len() for strings: it counts characters. No magic, no config. "hello" → 5, "" → 0, "héllo" → 5 (Unicode characters count as one each, not one per byte). The node is a thin wrapper around len(string) - which is exactly what you want from a utility node: predictable, boring, correct.
Inputs and outputs
One required input, string (default ""), and one INT output. The INT wires into this pack's comparison nodes (equal, greater-than, NumberInRange) to make decisions, or into any node that wants a width or count - the pack's own ljust / rjust nodes take a width input, so a dynamic "pad to match the longest string" setup is just length → width.
Installing it
Part of the Basic data handling pack by StableLlama. ComfyUI Manager, search "Basic data handling", install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
The pack is pure Python with zero dependencies and no downloads - no models, no wheels. That's its whole reputation: it installs clean and rides along in shared workflows without pulling in dependency conflicts. The node sits under Basic/STRING.
Common issues
The one real misunderstanding is what "length" counts. It counts characters, not tokens - a 1,000-character prompt is not 1,000 tokens, and a long prompt may still exceed a model's context window. If you're using length as a proxy for "will this fit", know that it's a rough proxy, not the model's tokenizer. It's also not bytes: non-ASCII text counts as its visual characters. And the obvious one - length 0 means the string is empty, which is the cleanest emptiness check in this whole pack, since a ComfyUI blank text field is "", not None.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |