Compare (NH)
Turn any two values into a true/false for the rest of your graph
- a
- b
- result
- a_passthrough
- b_passthrough
At some point every workflow stops being "generate and look" and becomes "generate, then decide." That decision usually reduces to a boolean - and booleans are born from comparisons. Compare (NH) is the node that makes them: it takes two values of almost any type, compares them with an operator you pick, and hands the true/false result to whatever logic you've built downstream.
You'll reach for it when you want a workflow that reacts to its own state: "if the counter has passed 10, use the slow upscaler," or "if this filename contains 'raw', skip the enhancement branch."
How it works
Inputs are deliberately loose:
- a and b - any type, thanks to the
*wildcard. Strings, numbers, whatever. - op - the comparison:
is(equal),not(not equal),>,<,>=,<=, orin(substring/membership). - type_cast (optional, default
auto) - how to coerce the values before comparing:autotries float first and falls back to string, or you can forceint,float, orstring. This is the setting that saves you from the classic "5" vs 5 problem where one side is a string and the other isn't.
The in operator is the sleeper feature: it checks membership in a list, dict keys, or substring in a string. Checking whether a prompt contains "night" is one wire away from gating a whole branch.
Outputs are result (the BOOLEAN) plus a_passthrough and b_passthrough, which echo both inputs back so you can compare and forward the values without a reroute node. Handy - compare a filename, then still use that filename downstream.
Where it shines
The canonical ComfyUI pattern is Compare → If/Else (NH) or Any Switch (NH) → two different downstream paths. A compare feeding an if/else is the closest ComfyUI gets to an if statement in your graph. It's also the natural partner for Counter (NH): current > max_value as a loop-exit condition, driving a Gate Switch (NH).
One honest note: if either value is None (unwired), the node returns False rather than erroring. That's usually desirable - an unconnected branch shouldn't silently pass a comparison - but it means "no data" and "not equal" look identical downstream. Keep that in mind when you design the logic.
Installing
Part of NH-Nodes, one-time install:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt
Or search NH-Nodes in ComfyUI Manager and restart. No models, no downloads - pure comparison logic.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| a | * | — | |
| b | * | — | |
| op | COMBO | 7 options: is, not, >, <, >=, <=, +1 | |
| type_castopt | COMBO | auto | 4 options: auto, int, float, string |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| result | BOOLEAN | — |
| a_passthrough | * | — |
| b_passthrough | * | — |