ComfyUI Node

Eval_AS

A tiny Python REPL inside your workflow — powerful, and a little spicy

By flyingshutter·Created 3 years ago·Updated about a year ago· 8
Eval_AS
    • INT
    • FLOAT
    • STRING
    int_prc0
    float_prc0
    str_prc0
    i10
    i20
    f10.0
    f20.0
    s1
    s2

    Eval_AS is the node you reach for when no amount of Math nodes will cut it. It evaluates a Python expression inside the graph, with access to six variables you can wire in, and hands back a clean INT, FLOAT, and STRING. It's the most flexible thing in flyingshutter's As_ComfyUI_CustomNodes pack - and also the one you should treat with respect, because it's eval(), and eval() runs arbitrary Python.

    How it works

    The node has three text boxes: int_prc, float_prc, and str_prc. Each one is evaluated as a Python expression, and each one feeds its matching output. The expressions get six variables to play with:

    • i1, i2 - optional INT inputs
    • f1, f2 - optional FLOAT inputs
    • s1, s2 - optional STRING inputs

    So int_prc might be i1 + i2 * 2, float_prc could be f1 / 3.5, and str_prc might be f"{s1} | {s2}". Any expression that evaluates to a number/string works, including Python builtins, so this one node replaces a small pile of Math, compare, and formatting nodes.

    The catch: each box must actually produce the type it feeds. If int_prc evaluates to 1.5, your INT output is lying about what it is, and downstream nodes will complain or quietly misbehave. Keep them typed straight: ints in the int box, floats in the float box, strings in the string box.

    Why you'd bother

    ComfyUI's stock math is per-node and per-operation. Eval_AS collapses that into one place and lets you write logic that would otherwise take three or four connected nodes: a conditional-ish clamp, a formatted string with padding, a math expression that changes per workflow. For parameter wrangling - turning a seed into a step count, or a float into a formatted label - it's genuinely handy.

    The security part, said plainly

    eval() runs whatever you type as Python code on your machine, with your user's permissions. That's fine when you wrote the expression. It is not fine when you download an unknown workflow that contains a pre-filled Eval_AS and just hit Queue. Custom nodes already execute arbitrary code on load - the ComfyUI ecosystem has no sandbox, as the community has learned the hard way - but a node whose entire purpose is running typed expressions is where you should be most deliberate. Only use expressions you wrote and understand. If you're not comfortable with that, skip this node; there are safer math nodes.

    Installing it

    Part of the As_ComfyUI_CustomNodes pack, which has no dependencies beyond what ComfyUI already ships:

    cd ComfyUI/custom_nodes
    git clone https://github.com/flyingshutter/As_ComfyUI_CustomNodes
    

    Restart ComfyUI, then find Eval_AS under ASNodes (or install via ComfyUI Manager by searching "As_ComfyUI_CustomNodes").

    Common issues

    • Wrong output type. int_prc returning a float, or str_prc returning a number, breaks the port contract. Cast explicitly (int(...), str(...)) inside the expression.
    • Unhandled errors. If an expression raises - divide by zero, a bad variable name - the node throws, and the run fails with a Python traceback in the console. There's no error handling, so write defensively (f1 if f1 != 0 else 1).
    • Unused optional inputs. s1 and s2 are strings by default, not numbers, so don't try arithmetic on them.

    Used carefully, this is the most useful node in the whole pack. Just remember what it is under the hood.

    CategoryASNodes

    Inputs (9)

    NameTypeDefaultDescription
    int_prcSTRING0
    float_prcSTRING0
    str_prcSTRING0
    i1optINT0
    i2optINT0
    f1optFLOAT0.0
    f2optFLOAT0.0
    s1optSTRING
    s2optSTRING

    Outputs (3)

    NameTypeDescription
    INTINT
    FLOATFLOAT
    STRINGSTRING