type_AnyCast
Force any value into INT, STRING, LIST or dict — the type-wrangler
- ANY
- data
ComfyUI is strict about types until a node outputs any, and then it's your problem. type_AnyCast is the escape hatch: it takes any value and coerces it to whatever TYPE you pick - STRING, INT, FLOAT, LIST, SET, TUPLE, DICTIONARY, BOOLEAN, or a UTF-8-cleaned string. The "your node gave me a string where an integer belongs" problem has a one-node solution, and this is it.
It's from the data drawer of ComfyUI-Apt_Preset, a pack that uses any types liberally - which is exactly why it ships its own cast node. When you start mixing any-typed outputs with strongly-typed inputs, you will eventually need this.
How it works
ANY is the value, TYPE is the destination. The coercion rules are pragmatic rather than strict:
- INT / FLOAT - a string like
"42"or"3.7"parses properly (int conversion fails gracefully to 0 rather than crashing). - BOOLEAN - strings
"true","1","yes"becomeTrue; everything else is Python's truthiness. - LIST / SET / TUPLE / DICTIONARY - built from whatever shape the input is. A string fed to DICTIONARY gets tried as JSON first, then as a Python literal, so
'{"a": 1}'becomes a dict without a detour through a code node. - STRING - just
str(). UTF8_STRING - re-encodes to clean UTF-8, useful when you've inherited text with encoding artifacts.
A None input becomes the type-appropriate empty: 0 for INT, "" for STRING, False for BOOLEAN, empty container for the collection types. So casting never explodes on missing values - it degrades to empty, and you decide whether that's a feature or a mask for a bug.
Inputs and outputs
- ANY - the value.
- TYPE - the ten-way enum.
anytypeis there if you want to pass through untouched. - Output: data - the cast result, any-type.
Use it wherever two nodes disagree on shape: an INT widget that demands a number but you're feeding it a string output, a node that needs a LIST but got a tuple, a text parser handing you a dict-in-a-string.
Installing it
Part of ComfyUI-Apt_Preset. ComfyUI Manager → search ComfyUI-Apt_Preset, or:
cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset
Restart; install.bat on Windows for the pack's requirements. Pure Python coercion - nothing heavy here.
Common issues
The trap is silent degradation. Cast a badly-formed string to INT and you get 0, not an error - if a downstream value is mysteriously zero, check whether a cast swallowed a parse failure. Same with DICTIONARY on garbage: it returns {}. That's forgiving by design, but it can hide upstream bugs, so cast at the edge where the bad data originates, not right before the consumer. And remember the pack's cast is its own thing - it only resolves mismatches for this pack's any-typed outputs, not a general fix for every node ecosystem's type conventions.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| ANY | * | — | |
| TYPE | COMBO | 10 options: anytype, STRING, INT, FLOAT, LIST, SET, +4 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| data | * | — |