Nodes/ComfyUI DataBeast/DB String Expression
ComfyUI Node

DB String Expression

Build prompts with one expression instead of five text-concat nodes

By hanoixan·Created 2 years ago·Updated 2 years ago· 2
DB String Expression
    • output
    expression
    a
    b
    c
    d

    String concatenation is the most tediously manual thing in ComfyUI: you chain text nodes and concat nodes until the wires outnumber the content. DBStringExpression does it in one node with a Python expression - the string-flavored sibling of DBFloatExpression, and the node you'll reach for when your batch data needs to become a prompt.

    How it works

    Four string inputs - a, b, c, d - plus one expression, evaluated as Python with only those four variables in scope. The result comes back as a STRING. The README's own examples are the ones you'll use constantly:

    a + b
    f"{a}_{b}"
    

    The second one is the workhorse. In a DataBeast batch, DBGetItem pulls "A puppy wearing a" and your data's color value as separate items, DBConvertToString strips them to plain strings, and f"{a}_{b}" fuses them into a full prompt. Because DBGetBatchList drives iteration, that prompt is rebuilt for every item in the batch - which is the entire reason this node is worth having.

    What actually works, and what doesn't

    Realistic expectations matter here. The README limits expressions to the passed-in variables, and the whole pack runs expressions through RestrictedPython. In practice that means concatenation and f-strings are the reliable operations - a + b, f"{a} {b} {c}", maybe a + b + c chains. Don't lean on fancy string methods like .upper() or .replace(); RestrictedPython is picky about attribute access, and this pack's philosophy is explicitly "limited to a, b, c, and d." When you need a transformation, do it in the data file's db_exec blocks rather than fighting the expression sandbox.

    Also - the silent-failure pattern. An expression that errors returns... 0 (yes, a number, it's a copy of the float node's default), so a broken formula can hand you a numeric string downstream instead of the text you expected. Typos are quiet. Test expressions in a Python REPL first.

    Installing

    It ships with ComfyUI DataBeast, which is not in ComfyUI Manager yet:

    cd ComfyUI/custom_nodes
    git clone https://github.com/hanoixan/ComfyUI-DataBeast
    cd ComfyUI-DataBeast
    pip install -r requirements.txt
    

    Restart and it's under the DataBeast category. Dependencies are just pyyaml and RestrictedPython - no models to download. Pack's still marked alpha, and V0.2 reshuffled the DBGet*/DBConvert* API, so treat any workflow you save against it as somewhat provisional.

    CategoryDataBeast

    Inputs (5)

    NameTypeDefaultDescription
    expressionSTRINGPython string expression taking any of inputs a,b,c,d.
    aSTRINGInput a.
    bSTRINGInput b.
    cSTRINGInput c.
    dSTRINGInput d.

    Outputs (1)

    NameTypeDescription
    outputSTRING