Skip to content

To Bool

Converts an incoming value to a boolean. Tensors are treated as False only if all elements are zero; otherwise True. An optional invert flag flips the final result.
Preview

Usage

Use this node when you need a boolean signal from any prior output to drive logic branches or condition checks. Typical workflows include validating non-empty strings, non-zero numbers, or non-all-zero tensors before routing execution.

Inputs

FieldRequiredTypeDescriptionExample
valueTrueWILDCARDAny input value to evaluate as a boolean. For tensors, the result is False if all elements are zero, otherwise True. For other types, standard truthiness is used.A tensor, number, string, list, or any object
invertFalseBOOLEANIf True, inverts the computed boolean result.False

Outputs

FieldTypeDescriptionExample
resultBOOLEANThe computed boolean value after optional inversion.True

Important Notes

  • Tensors are considered False only when both their max and min are 0 (i.e., all elements are zero). Any non-zero element makes it True.
  • Non-tensor values use normal truthiness rules (e.g., empty string/list -> False; non-empty -> True; zero -> False; non-zero -> True).
  • If the node cannot convert a non-tensor value to bool due to a ValueError or TypeError, it defaults to True.
  • Any unexpected runtime error during processing results in False.
  • Setting invert to True flips the final boolean outcome.

Troubleshooting

  • Result is False for a tensor you expected to be True: Ensure the tensor contains at least one non-zero element. All-zero tensors evaluate to False.
  • Result is unexpectedly True for a custom object: If the object's boolean conversion raises an error, the node defaults to True. Implement a bool method or provide a different input type.
  • Result is False due to an internal error: Check upstream inputs for invalid or unsupported values (e.g., tensors with problematic states). The node returns False on unhandled exceptions.
  • Performance concerns with very large tensors: The check uses min/max; if performance is an issue, consider pre-reducing or summarizing the tensor before this node.