Nodes/Basic data handling/compare length
ComfyUI Node

compare length

Is that prompt too long? compare length answers it, and hands you the real count

By StableLlama·Created about a year ago·Updated 4 days ago· 48
compare length
  • container
  • result
  • actual_length
operator==
length0

"How long is this thing?" is a surprisingly common question in a ComfyUI workflow - did my prompt exceed the model's token-friendly length, is my list empty, did my filename get too long? compare length answers it with a boolean you can feed straight into an if/else, and as a bonus it tells you the actual length so you don't have to guess.

It's part of Basic data handling, StableLlama's zero-dependency utility pack, and it lives in the comparison category alongside the ==, >, < style nodes - it's the one comparison that works on containers rather than raw values.

How it works

The node runs len(container) and compares it against the length number you provide, using whichever operator you pick. Simple and direct. The one edge case worth knowing: if the input is something that has no length - a number, say - the node can't measure it and returns False for the comparison and -1 for the actual length, rather than crashing.

Two outputs, which is the part people like:

  • result (BOOLEAN) - the answer to your comparison, e.g. "is this string longer than 500?"
  • actual_length (INT) - the measured length of whatever you fed in. Wire this into a display or a filename and you've got a live character/word count.

The inputs that matter

  • container (*) - a string, a list, a dict, anything len() understands.
  • operator (dropdown) - ==, !=, >, <, >=, <=. Defaults to ==.
  • length (INT, default 0) - the number to compare against.

A realistic use

Prompt-length policing is the one I see most: tokenize-adjacent tools have limits, and you can branch on "is my positive prompt over 500 characters?" and route to a summarizer or a fallback prompt when it is. The actual_length output also makes a nice live status readout if you're building a workflow dashboard.

Installing it

ComfyUI Manager → search "Basic data handling", or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart. No dependencies, no models.

Common issues

  • "It says False for everything." If the container is a number or some object without a __len__, you get False and -1 - the node can't measure it, so it fails safe rather than throwing. Cast it to a string first if you're trying to measure a numeric value's character count.
  • "Length counts characters, not tokens." Correct - this is character length. Tokens are a different, model-specific count, so don't use this to enforce exact token budgets. It's still fine as a rough guardrail.
  • "I want a range check." Chain two of these with a boolean and, or use the pack's NumberInRange node for that specific job.
CategoryBasic/comparison

Inputs (3)

NameTypeDefaultDescription
container*
operatorCOMBO==6 options: ==, !=, >, <, >=, <=
lengthINT0

Outputs (2)

NameTypeDescription
resultBOOLEAN
actual_lengthINT