ComfyUI Node

to BOOLEAN

Turn any old value into a clean true/false

By StableLlama·Created about a year ago·Updated about 20 hours ago· 48
to BOOLEAN
  • input
  • BOOLEAN

ComfyUI's boolean sockets are picky, and sooner or later you'll have a number, a string, or a whole node output sitting there that needs to become a clean true/false. to BOOLEAN is the converter - one input, one boolean out, and the rules it follows are Python's standard truthiness rules, which are worth learning because they're probably not what you assume.

It's part of Basic data handling, StableLlama's zero-dependency pack. This is one of those "you don't need it until you need it" nodes, but when a comparison node hands back something that isn't quite a boolean, or a custom node's output won't slot into a BOOLEAN socket, this is the adapter.

How it works

The conversion is Python's bool(input), and the truthiness table has some traps for people coming from other languages:

  • FalseFalse, TrueTrue
  • 0, 0.0, "", [], {}, None → all False
  • Any non-empty string is True - including the literal "False". Yes, really. bool("False") is True, because it's a non-empty string and Python doesn't parse it.
  • 1, 42, -1, "hello", [0], {"a": 1} → all True

That "False" string case is the classic footgun. If some node produces the text "false" and you cast it expecting a boolean, you get True. If that's your situation, you want a string comparison node first, not a cast.

The input and the output

  • input (ANY) - anything you want normalized to a boolean.
  • BOOLEAN (output) - the truthiness result.

One in, one out. Wire it in front of if/elif/else or any logic node when the source isn't a clean boolean.

Installing it

Install Basic data handling via ComfyUI Manager (search "Basic data handling"), or:

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

Restart ComfyUI. No dependencies, no models - a clean install.

Troubleshooting

  • "I cast the string 'False' and got true!" Working as Python works. Read the truthiness table above. If you're parsing text into booleans, compare the string to "true"/"1" explicitly instead of casting.
  • "My zero came out as false and I wanted true." 0 is falsy in Python, full stop. If zero is a meaningful value in your context (like "batch of zero is fine"), don't cast it to a boolean - keep the number and compare with != 0 or similar.
  • "The socket still won't take it." The cast produces a real BOOLEAN-typed output, so anything that accepts booleans should accept it now. If it won't, check the receiving node is actually wired to this output and not to the original input.
CategoryBasic/cast

Inputs (1)

NameTypeDefaultDescription
input*

Outputs (1)

NameTypeDescription
BOOLEANBOOLEAN