Comfy-Org/ComfyUI · error · ValueError

Cannot convert empty string to number.

Error message

Cannot convert empty string to number.

What it means

Raised by the number-conversion node when the input value is a string that is empty or contains only whitespace after .strip(). The node refuses to guess a numeric value for blank text rather than silently converting to 0.

Source

Thrown at comfy_extras/nodes_number_convert.py:56

                io.Int.Output(display_name="INT"),
            ],
        )

    @classmethod
    def execute(cls, value) -> io.NodeOutput:
        if isinstance(value, bool):
            float_val = 1.0 if value else 0.0
            int_val = 1 if value else 0
        elif isinstance(value, int):
            float_val = float(value)
            int_val = value
        elif isinstance(value, float):
            float_val = value
            int_val = int(value)
        elif isinstance(value, str):
            text = value.strip()
            if not text:
                raise ValueError("Cannot convert empty string to number.")
            try:
                float_val = float(text)
            except ValueError:
                raise ValueError(
                    f"Cannot convert string to number: {value!r}"
                ) from None
            if not math.isfinite(float_val):
                raise ValueError(
                    f"Cannot convert non-finite value to number: {float_val}"
                )
            try:
                int_val = int(text)
            except ValueError:
                int_val = int(float_val)
        else:
            raise TypeError(
                f"Unsupported input type: {type(value).__name__}"
            )

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Provide an actual numeric string such as '1.5' or '42'.
  2. Insert a default-value/string-handling node upstream so empty text becomes a chosen fallback before conversion.
  3. Validate string inputs are non-empty before connecting them to the converter.

Example fix

// before
NumberConvert(value="   ")
// after
NumberConvert(value="0")
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(value, str) and not value.strip():
    value = "0"  # or raise your own descriptive error before the node sees it

Prevention

When it happens

Trigger: Feeding a STRING input (e.g. from a text node or primitive) whose value is '', ' ', or '\t\n' into the number converter. Only the string branch with not text after stripping triggers this.

Common situations: UI text fields left empty and wired into a number input; prompt templates that render an empty placeholder; API workflows where a variable interpolates to nothing.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/c00266e221af1d53. Report an issue: GitHub.