Comes before
String ordering without a dictionary
- result
"Comes before" answers a question you didn't know you had: does this string sort earlier than that one? It's first < second on text, true when the first string comes first in dictionary order. For a long time I figured this was academic - who needs to order strings in ComfyUI? - and then I needed to bucket a list of names by alphabetical range and realized there was no clean way to do it. This is that clean way.
It's part of the string-comparison family in marco-zanella's ComfyUI-BooleanExpression pack, a dependency-free logic collection. The display name is friendly ("Comes before"); the class name is the mathy one: BooleanExpression.StringComparison.AlphabeticalLessThan.
How it works
Three required inputs:
first- the first string (default empty)second- the second string (default empty)case_insensitive- a BOOLEAN toggle, defaulting totrue
Output is result, a BOOLEAN: first < second on the (optionally lowercased) strings. Mechanism is Python's < - lexicographic comparison by Unicode code point. With case_insensitive on, both strings are lowercased first, which turns a code-point ordering into something that reads like a real dictionary for plain text. "apple" < "banana" returns true. Exactly what you'd expect.
One honest caveat about the "alphabetical" branding: Python's string < isn't quite dictionary order. It's code-point order, which matches for plain lowercase ASCII but sorts uppercase before lowercase ("Z" < "a"). The case-insensitive default fixes the common case; if you're sorting filenames or mixed-case text against your OS's file manager, you'll see differences. For typical workflow text, it's close enough that you won't notice.
When you'd use it
String ranges and buckets, mostly. "Names A–M take this path, N–Z take that path" is two comparisons - a Comes before check for the top of the range and a Comes before or equal to (or Comes after) for the bottom. It also composes with the pack's string "Equal to" for exact-match routing. You'll go months without touching it, and then a workflow needs sorted labels and it's suddenly the only node that does the job.
Installing it
No models, no dependencies, pure Python - the pack's requirements.txt is empty. ComfyUI Manager, search ComfyUI-BooleanExpression, or:
cd ComfyUI/custom_nodes
git clone https://github.com/marco-zanella/ComfyUI-BooleanExpression.git
Restart ComfyUI, and it's under Boolean Expressions → String Comparisons.
Gotchas
- Boundary values fall outside the strict check. "Comes before" is false when strings are equal - if your range should include the boundary name itself, that's "Comes before or equal to" or "Comes after or equal to" on the other end.
- Case-insensitive by default. Flip the toggle if you need exact byte ordering. And remember it's not locale-aware collation, so don't trust it to match your file explorer's sort.
- Both branches downstream still compute. Value-producing node, not a control-flow switch - unselected input chains upstream still run. Free for strings.
Thin node, real job. If you sort or range over text in a workflow, this is the piece you were missing. If you never sort text, you can ignore it entirely - and come back when you do.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| first | STRING | The first string. | |
| second | STRING | The second string. | |
| case_insensitive | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | BOOLEAN | — |