String Logic
Branching a workflow on a text comparison
- if
- else
- is_true
- is_false
ComfyUI graphs aren't naturally great at "do X if Y, otherwise do Z" - the canvas is built around data flowing forward, not conditional branching. String Logic is comfyui_LLM_party's answer to that gap, specifically for text: compare two strings one of eight ways, and get back both a boolean you can gate on and pre-routed if/else string outputs, so you don't have to build your own branching plumbing every time you need a decision based on text.
option is the single required field, and it's an enum covering eight comparisons: contains / doesn't contain, "relates to" / "doesn't relate to," equals / doesn't equal, and two null checks (is null / is not null). The straightforward ones are exactly what they sound like - A contain B checks a literal substring match, A equal B checks exact equality, and the null checks let you test stringA alone without needing stringB at all (handy for "did my LLM actually return something" checks). A relate to B and its negation are the vaguer pair - the schema doesn't spell out the exact matching logic, and it's reasonable to guess it's a looser, more semantic comparison than a straight substring or equality check, but don't take that as confirmed; if the distinction matters for what you're building, test it directly with known inputs rather than assume.
stringA and stringB are both optional inputs - which string(s) you need to fill depends on which option you picked, since the null checks and single-string comparisons don't need stringB at all. Four outputs come back: is_true and is_false are the plain booleans for gating other nodes, while if and else are a nice touch most simple comparison nodes skip - they pass through pre-selected string values depending on the result, so you can wire a single node's output directly into whatever needs "the value if true" or "the value if false" without a separate switch node in between.
A natural use inside this pack: run the moderation-text node, then String Logic on its flagged_categories output to check whether it contains a specific category you care about and route accordingly - or check an LLM's assistant_response for a keyword like "ERROR" and branch a retry path off of it.
Installing it means installing the pack as a whole: search "comfyui_LLM_party" in ComfyUI Manager, or git clone https://github.com/heshengtao/comfyui_LLM_party into custom_nodes and restart, then run pip install -r requirements.txt from inside the pack folder using ComfyUI's own Python (portable installs need python_embeded\python.exe -m pip install -r requirements.txt, not your system pip).
There's not much to break here since it's a pure text comparison, but two things are worth checking if a branch isn't firing the way you expect: string comparisons are almost certainly case-sensitive, so "Error" and "error" won't match under A equal B even though they read the same to you, and LLM output in particular is inconsistent about capitalization run to run - consider lowercasing both sides upstream if that's biting you. And if you picked one of the "relate to" options expecting fuzzy/semantic matching and getting results that look more like a literal check (or vice versa), that's worth testing directly rather than assuming, since it's the one comparison type this node's documentation doesn't make fully explicit.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| option | COMBO | A contain B | 8 options: A contain B, A not contain B, A relate to B, A not relate to B, A equal B, A not equal B, +2 |
| stringAopt | STRING | — | |
| stringBopt | STRING | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| if | STRING | — |
| else | STRING | — |
| is_true | BOOLEAN | — |
| is_false | BOOLEAN | — |