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
- Provide an actual numeric string such as '1.5' or '42'.
- Insert a default-value/string-handling node upstream so empty text becomes a chosen fallback before conversion.
- 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
- Default text primitives to '0' instead of empty when they feed number conversions.
- Validate string inputs are non-empty in API payloads before submitting prompts.
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
- Cannot convert string to number: {value!r}
- Cannot convert non-finite value to number: {float_val}
- Unsupported input type: {type(value).__name__}
- INVALID_TAG_FILTER
- UNSUPPORTED_MEDIA_TYPE
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/c00266e221af1d53.
Report an issue: GitHub.