Skip to content

To Bool

Converts any input value into a boolean. For tensors, it returns False only if all values are zero; otherwise True. For non-tensor values, it follows standard truthiness rules and can optionally invert the result.
Preview

Usage

Use this node when you need a boolean flag derived from any upstream value to control logic flow. Common in conditional routing, gating, and enabling/disabling branches based on whether an input is effectively 'present' or 'non-zero'.

Inputs

FieldRequiredTypeDescriptionExample
valueTrueWILDCARDAny value to be evaluated for truthiness. Tensors are True if any element is non-zero; non-tensors use standard boolean conversion.0, "", [1,2,3], {"k": "v"}, , None
invertFalseBOOLEANIf True, flips the computed boolean result.False

Outputs

FieldTypeDescriptionExample
resultBOOLEANThe boolean evaluation of the input (optionally inverted).True

Important Notes

  • For tensors, the result is False only when all elements are exactly zero; any non-zero element makes it True.
  • If the input is a non-tensor object that cannot be directly converted to a boolean (raises a conversion error), the node treats it as True.
  • If an internal error occurs during evaluation, the node returns False.
  • Using invert=True simply flips the final boolean result.

Troubleshooting

  • Unexpected True for a tensor: Ensure the tensor does not contain any non-zero values; any single non-zero element will yield True.
  • Unexpected False result: If an internal error occurred (e.g., invalid or empty tensor for reduction), the node will return False; verify the input is valid.
  • NaN values in tensors: Presence of NaNs does not count as zero and will typically yield True; sanitize the tensor if needed.
  • Non-standard objects: If your custom object doesn't define clear truthiness and raises errors on bool conversion, it will be treated as True; consider providing a simpler proxy value.