Nodes/comfyui-toml-prompt/StringToBoolean
ComfyUI Node

StringToBoolean

It turns \"true\" into a real boolean — but only that word

By morino-kumasan·Created 2 years ago·Updated 2 days ago· 2
StringToBoolean
    • BOOLEAN
    ◄text—►
    ◄default_value—►

    StringToBoolean is a two-input, one-output adapter: you hand it a string, it hands back a BOOLEAN. On its own that sounds like nothing. It only makes sense once you know why it exists - it's the glue in a pack built around the idea that your prompts, model names and sampler settings should live in a text file, not in widgets.

    That's a real itch. If the prompt is a widget you type into, every experiment is a mouse trip. If it's a .toml on disk, you edit it in a real editor, diff it, keep versions, and hit Queue. The catch: everything read out of a file arrives as a STRING, while plenty of ComfyUI inputs want an INT, a FLOAT or a BOOLEAN. That's the job of this little node family, and StringToBoolean is the smallest member.

    How it actually works

    Read the source and it's four lines:

    def parse_value(self, text: str, default_value: bool):
        if text == "":
            return (default_value,)
        r = text.lower()
        return (r == "true" or r == "ok",)
    

    So there are exactly three outcomes:

    • Empty string → you get back whatever you set in default_value. This is the useful one: a missing key in your prompt file falls back silently to the node's own default instead of blowing up.
    • "true" or "ok", any capitalisation → True. Yes, ok counts. The author is Japanese and ok is presumably a hand-typed convenience.
    • Anything else → False. Not an error, not a warning. "yes", "1", "on", "True " with a trailing space, "TRUE!" - all quietly become False.

    That last point is the gotcha, and it's worth sitting with. There's no .strip(), so a stray space from a copy-paste or a sloppy YAML value is the difference between your branch running and your branch being skipped. Its siblings StringToInt and StringToFloat do int(text) / float(text) and throw a visible node error on garbage; the boolean one fails into False without telling you. A silent wrong answer is worse than a crash, so be strict in the file: enable_break = "true".

    The inputs and output that matter

    Two required inputs, that's all of it:

    • text (STRING) - the value you're converting. Right-click it and Convert widget to input when you want to wire it from upstream instead of typing it, which is the normal case.
    • default_value (BOOLEAN) - the fallback used when text is empty. Set it to the value you want when the key is absent, i.e. True if the feature should be on by default.

    Output is a single BOOLEAN socket. Wire it into any boolean input - a switch, a toggle on some loader or encode node, anything that takes a real bool.

    Where it earns its keep in the pack's own design: the sample t2i workflow loads a .toml with PromptLoader, PromptDecode outputs a JSON blob of your [_exports] section (model, width, steps, cfg, sampler, …), a JSON-extract node pulls individual keys out, and then StringToInt / StringToFloat / StringToBoolean turn them into the types the sampler and encoder nodes demand. Here it feeds the enable_break input of MultipartCLIPTextEncode - the "split the prompt on BREAK tags" toggle. TOML can't hand a Python bool to a widget, so someone has to convert. That's this node.

    Install

    No models, no pip step. The repo's requirements.txt is empty - the README's pip install -r requirements.txt line is harmless ceremony, and the file itself is 0 bytes.

    ComfyUI Manager: search comfyui-toml-prompt, install, restart. Or by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/morino-kumasan/comfyui-toml-prompt
    

    then restart ComfyUI. The node shows up as StringToBoolean under the utils category in the Add Node menu.

    One thing to know before you follow the README: it's stale. It still says git clone [email protected]:morino-kumasan/comfyui-utils.git - the repo was renamed to comfyui-toml-prompt since (the git remote points there, and ComfyUI loads it as custom_nodes.comfyui-toml-prompt). Use the HTTPS clone above; the README's SSH form fails on any machine without a GitHub key.

    Troubleshooting

    My branch never fires and I see no error. Check text character by character - quotes and whitespace included. Only "true" and "ok" (case-insensitive) are truthy, and the empty string falls back to your default_value rather than to False.

    The node returns the default no matter what I put in the file. Either the key isn't reaching it (typo in the key name - the extract node hands back "" for a missing key, which is the fallback case) or the .toml edit didn't re-run. In this pack the loader hashes file contents in IS_CHANGED, so a saved edit does re-trigger the graph; if you're feeding text from somewhere else, remember ComfyUI only re-executes nodes whose inputs it thinks changed.

    Do you actually need it? If the value never changes, no - drop a core PrimitiveBoolean and skip the string round-trip. If it's a "true"/"false" line in a prompt file you edit between runs, this is the shortest path between those two worlds.

    Last note on what that boolean usually feeds: BREAK splitting only means anything on CLIP-encoded models - SD 1.5, SDXL, Illustrious, Pony - where the encoder chunks prompts at 77 tokens and BREAK picks the cut. On an LLM-encoded model there's no boundary to break against, so the flag does nothing.

    Categoryutils

    Inputs (2)

    NameTypeDefaultDescription
    textSTRING—
    default_valueBOOLEAN—

    Outputs (1)

    NameTypeDescription
    BOOLEANBOOLEANBOOLEAN.