String Default
Never feed an empty prompt to an encoder again
- result
- was_empty
String Default answers one boring, vital question: what happens when this string is empty? You give it a text and a default_value; if the text is empty, it returns the default. Otherwise the original text passes through untouched. It sounds trivial until you've had a workflow silently generate garbage because an upstream node returned "" and a CLIPTextEncode happily encoded the void.
It's from the TakkunRed ComfyUI-String-Function pack, and it's one of the few nodes there you'll want in almost every LLM-driven graph. The KB's coverage of LLM-in-the-graph workflows keeps coming back to the same structural fact: node output is not guaranteed to be non-empty. An LLM call fails, an extraction misses, a file read finds nothing - and suddenly your conditioning is running on empty air.
How it works
The logic is exactly the fallback pattern the plumbing docs describe for first-non-null switches like rgthree's Any Switch, but narrowed to a single field: check emptiness, substitute if empty, pass through otherwise. Two details make it more useful than a naive if not text:
trim_before_check(default False). When on, it strips whitespace before the emptiness check - so" "counts as empty and gets the default instead of sailing through as a "valid" string of spaces. Turn this on if your upstream comes from an LLM or a file read, both of which love trailing whitespace.- It reports
was_empty(BOOLEAN), so downstream logic can branch on whether the fallback actually fired - you can log it, or flip a switch that changes behavior when the default kicked in.
Inputs and outputs
text (required) and default_value (required) are the two you set. The only optional is trim_before_check. Outputs are result (STRING - either the original or the default) and was_empty (BOOLEAN).
A natural wiring: put a String Extract Prompt upstream, set default_value to a sensible safe prompt, and trim_before_check on. Now a failed extraction can't blank your generation - it falls back to something sane, and was_empty tells you it happened.
Installing it
Same pack, same zero-dependency story - pure Python stdlib, no models:
cd ComfyUI/custom_nodes
git clone https://github.com/TakkunRed/ComfyUI-String-Function
Or search "ComfyUI-String-Function" in ComfyUI Manager and restart. It sits under String Function.
Where people get burned
- It's a fallback, not a validator. It only substitutes on empty - it won't fix a string that's non-empty but garbage. Pair it with a String Trim (or the
trim_before_checktoggle) if whitespace is your failure mode. - The
was_emptyflag is the part beginners ignore, and it's the useful part. If you're debugging why you got the default, that boolean is your answer. - Remember
default_valueitself can be empty. If you leave both empty you've built a very fancy way to output nothing.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| default_value | STRING | — | |
| trim_before_checkopt | BOOLEAN | false | チェック前に前後の空白を除去する |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| result | STRING | — |
| was_empty | BOOLEAN | — |