ComfyUI Node

Contains

Turn a keyword into a workflow fork

By marco-zanella·Created about a year ago·Updated about a year ago· 0
Contains
    • result
    haystack
    needle
    case_insensitivetrue

    The question this node answers is the one you'll ask more than any other while building conditional workflows: does this text contain that piece of text? If your prompt mentions "portrait", if your LoRA filename has "v3" in it, if your checkpoint tag includes "turbo" - this node turns any of those facts into a boolean you can branch on.

    It's part of ComfyUI-BooleanExpression, a zero-dependency logic pack by Marco Zanella. ComfyUI gives you no if/else natively; conditional behavior comes from feeding boolean nodes like this into a Conditional Branch. And of all the string tests in the pack, contains is the workhorse - it's how you gate behavior on the content of a prompt instead of its exact spelling.

    How it works

    The mechanism is Python's substring test, needle in haystack, with an optional lowercase pass first. No service calls, no models, nothing to cache. It's the kind of node you can wire up while a generation is running and not feel guilty.

    Three required inputs:

    • haystack - "The string." This is the text being searched.
    • needle - "The string to search." The substring you're looking for inside the haystack.
    • case_insensitive - defaults to True.

    One edge case to know: if needle is empty, the node always returns true, because an empty string is technically a substring of everything. That's Python semantics, not a bug - but if your needle can be blank, guard it.

    The output is a single result boolean. It feeds the pack's Conditional Branch, the And/Or/Xor/Not nodes, or any other BOOLEAN input you point it at.

    A real pattern

    Prompt routing is the classic. ComfyUI's own conditioning is a single string, and people build "one workflow, many outputs" graphs by tagging the prompt and branching:

    • Prompt contains "portrait" → square latent, portrait-optimized prompt.
    • Prompt contains "landscape" → wide latent.
    • Model name contains "xl" vs "flux" → different schedulers or CFG defaults.

    This is basically the pack's own "conditional format prompt" example workflow, where arithmetic nodes pick an aspect ratio and branches pick the prompt - same shape, but with text as the trigger. A favorite trick: use it to sniff a filename. If filename contains "v3", run the newer upscaler; otherwise keep the old one. It's crude, but it works, and it's honest.

    Install

    ComfyUI Manager is the easy path - search ComfyUI-BooleanExpression and hit install. Or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/marco-zanella/ComfyUI-BooleanExpression.git
    

    Then restart ComfyUI. The node appears under Boolean Expressions → String Comparisons. There are no pip dependencies and no model downloads - the pack's requirements.txt is empty and the whole thing is stdlib Python. If a shared workflow loads with a red "Contains" node, you either haven't restarted or haven't installed the pack yet; Manager will flag it as missing on load.

    CategoryBoolean Expressions/String Comparisons

    Inputs (3)

    NameTypeDefaultDescription
    haystackSTRINGThe string.
    needleSTRINGThe string to search.
    case_insensitiveBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    resultBOOLEAN