Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee_StringDetector
ComfyUI Node

EmAySee_StringDetector

Does this string have text in it?

By EmAySee·Created about a year ago·Updated 4 months ago· 2
EmAySee_StringDetector
    • int
    detected_value1
    text_input

    Despite the name, EmAySee_StringDetector doesn't detect anything about what a string says. It answers one yes/no question: is this string non-empty? If yes, it outputs the integer you told it to; if no, it outputs 0. That's the entire trick, and once you see it, it's actually a handy little conditional.

    The use case is ComfyUI's eternal problem: string nodes don't have built-in "if this is empty, do the other thing" logic. Say an LLM node upstream sometimes returns a blank string - maybe the model bailed, maybe the workflow branch wasn't wired up. You want to detect "did we get text or not" and flip a value in response. That's what this node is for: wire the string into text_input, and you get an INT out that says "1" (or whatever detected_value is) when there's content, and "0" when the input is empty or not connected at all.

    How it works

    It's about as simple as a node can get, which is worth saying because you'll be tempted to overthink it:

    def detect(self, detected_value, text_input=None):
        if text_input is not None and text_input != "":
            return (detected_value,)
        return (0,)
    

    text_input is an optional STRING input, and it's marked forceInput - meaning you can't type into it, you have to wire something into it. That's a deliberate choice: this node is meant to sit downstream of another node, not to be hand-typed. Leave it disconnected and you always get 0.

    The inputs that matter

    • text_input (optional) - the string you're testing for content.
    • detected_value (INT, default 1) - the integer emitted when there is text. This is your "true" value; set it to whatever downstream logic wants.

    The single output is int, and it's the thing you're after: feed it into a switch, a math node, an if-style node, or anything that takes an INT.

    Where it fits in a workflow

    The author's own pattern - and the reason this node exists in a pack full of text utilities - is turning "did the LLM produce output" into a signal that other nodes can branch on. For example: an Oobabooga prompt-expansion node returns text; you detect whether that text came back non-empty; if it did, use the expanded prompt; if not, fall back to the raw prompt. Without a detector like this you're manually testing string outputs, which ComfyUI makes awkward.

    Installing it

    Same pack, same drill: ComfyUI_EmAySee_CustomNodes from ComfyUI Manager, or git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes into custom_nodes/, then restart. No dependencies, no models.

    The honest take

    Is this node over-engineered for what it does? A bit - you could reproduce its logic with a STRING-to-INT comparison in a few other packs, and the whole "detector" framing is doing a lot of work for a truthiness check. But it's free, it's tiny, and if you're already in this pack, the wiring is right there. The one trap to watch: it tests non-emptiness, not "does it contain anything meaningful". A string of spaces or a single newline counts as content, so if your upstream model likes returning whitespace, strip it before it gets here.

    CategoryEmAySee/Logic

    Inputs (2)

    NameTypeDefaultDescription
    detected_valueINT1-1000000–1000000
    text_inputoptSTRING

    Outputs (1)

    NameTypeDescription
    intINT