Comfy-Org/ComfyUI · warning · ValueError

Expression cannot be empty.

Error message

Expression cannot be empty.

What it means

Raised by the Math Expression node's execute() when the expression string, after strip(), is empty. An empty expression cannot be evaluated (simple_eval would raise a syntax error), so the node fails fast with an explicit, friendly message instead.

Source

Thrown at comfy_extras/nodes_math.py:93

                "eval", "math",
            ],
            inputs=[
                io.String.Input("expression", default="a + b", multiline=True),
                io.Autogrow.Input("values", template=autogrow),
            ],
            outputs=[
                io.Float.Output(display_name="FLOAT"),
                io.Int.Output(display_name="INT"),
                io.Boolean.Output(display_name="BOOL"),
            ],
        )

    @classmethod
    def execute(
        cls, expression: str, values: io.Autogrow.Type
    ) -> io.NodeOutput:
        if not expression.strip():
            raise ValueError("Expression cannot be empty.")

        context: dict = dict(values)
        context["values"] = list(values.values())

        result = simple_eval(expression, names=context, functions=MATH_FUNCTIONS)
        # bool check must come first because bool is a subclass of int in Python
        if not isinstance(result, (int, float)):
            raise ValueError(
                f"Math Expression '{expression}' must evaluate to a numeric result, "
                f"got {type(result).__name__}: {result!r}"
            )
        try:
            float_result = float(result)
        except OverflowError:
            raise ValueError(
                f"Math Expression '{expression}' produced a result too large to "
                f"represent as a float: {result}"
            ) from None

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Type a valid expression, e.g. 'values[0] * 2' or 'a + b' with named Autogrow inputs.
  2. If the node is not needed, bypass (Ctrl+B) or delete it instead of running it empty.
  3. Check that a workflow variable substitution did not blank out the expression field.
Defensive patterns

Strategy: validation

Validate before calling

if not expression or not expression.strip():
    raise ValueError("Expression cannot be empty — type a numeric expression like 'values[0] * 2'")

Type guard

def is_nonempty_expression(expr: str) -> bool:
    return isinstance(expr, str) and len(expr.strip()) > 0

Prevention

When it happens

Trigger: Leaving the expression widget blank and running the workflow; an expression consisting only of whitespace; a workflow-loading path that clears the widget; pasting a value that starts with a newline only.

Common situations: Newly added nodes run before the user types anything; templates with unfilled placeholders; frontends that submit default empty strings.

Related errors


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