To Bool | Basic
Coerce anything into true or false, with a built-in inverter
- any
- BOOLEAN
Boolean sockets are picky: they want a true or false, and they'll refuse a number or a string outright. ToBool ("To Bool | Basic") is the adapter that makes anything boolean-able. It takes a value of any type - the input socket is the wildcard * that accepts whatever you plug in - applies Python's truthiness, and outputs a BOOLEAN.
The mechanism is bool(any): numbers become false only at 0, non-empty strings become true, empty strings become false, and so on. There's also an optional invert toggle (default false); flip it and the result is flipped before it leaves the node - a built-in NOT so you don't need a second node.
The inputs that matter
- any - whatever you want to coerce. Accepts INT, FLOAT, STRING, BOOLEAN, or anything else that comes down the wire.
- invert - optional; when
true, negates the result.
Why you'd reach for it
This is the cleanup node for mixed-type graphs. The classic case: some other node hands you a 1 or a 0, or a string like "true", and you need to feed a boolean switch. Instead of restructuring upstream, drop a ToBool on the wire. It's also the polite way to convert a number into a condition - 0 → false, anything else → true - which is genuinely useful when a node signals state through a count.
Two truthiness traps to know about, because they're the difference between "this works" and "silently backwards." First, the string "false" is true. Any non-empty string - including "false", "0", and "no" - evaluates to true. If you're converting text output, don't expect "false" to mean false. Second, empty values are false: empty string, zero, and empty collections all convert to false. That's usually what you want, but it's worth stating.
Installing it
Standard pack install - pure Python, zero dependencies:
cd ComfyUI/custom_nodes
git clone https://github.com/akatz-ai/ComfyUI-Basic-Math
Restart ComfyUI, find it under Basic Math ➕ → Conversion as "To Bool | Basic". Or use ComfyUI Manager → **Install Custom Nodes → search "ComfyUI-Basic-Math"`.
The gotchas
The "false"-string behavior above is the one that bites. If you're ever converting text flags from a node that outputs "true"/"false" as strings, route it through ToBool knowing you'll get true for both - you'd want StringComparison against the literal text first if that distinction matters. And remember the | Basic suffix on the menu name, same as every node in this pack.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| any | * | — | |
| invertopt | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| BOOLEAN | BOOLEAN | — |