ComfyUI Node

Any Cast

Relabel or convert a value when ComfyUI's type system is in your way

By godmt·Created 2 years ago·Updated about a month ago· 16
Any Cast
  • ANY
  • *
TYPE

ComfyUI enforces socket types - a wire from a STRING output only connects to a STRING input, and so on. Most of the time that's a feature; it catches mistakes before they blow up mid-run. Occasionally it's just in your way: you've got a wildcard * output from a generic node and you know exactly what's flowing through it, but ComfyUI's type checker doesn't, and it won't let the wire form. Any Cast is the escape hatch - it outputs a value labeled as whatever type you pick, and for the basic scalar types it actually converts the underlying value too.

How it works

Connect any value and pick a TYPE from the dropdown - the full list runs to seventeen choices covering *, STRING, INT, FLOAT, BOOLEAN, and a run of ComfyUI-specific types like IMAGE, LATENT, MASK, NOISE, SAMPLER, SIGMAS, and GUIDER. What happens next depends on which type you picked, and this distinction matters a lot: for STRING, INT, FLOAT, and BOOLEAN, the node does a real Python-level conversion - feeding a float into a STRING cast genuinely calls something like str() on it, and feeding a numeric string into an INT cast genuinely tries to parse it. For everything else - IMAGE, LATENT, MASK, and the rest - there's no conversion happening at all. The node just relabels the socket. It doesn't reshape a tensor, doesn't validate dimensions, doesn't do anything to the actual data; it just tells ComfyUI "trust me, this is an IMAGE" and lets the wire connect.

That second behavior is powerful and genuinely risky in the same breath. It's the right tool when you know the data is correct and the type system is being needlessly strict - a common situation with generic nodes that output * deliberately, or when routing through a Pack/Unpack pair where the underlying value's real type got lost along the way. It's the wrong tool if you're guessing. Cast an INT to IMAGE and the wire will connect just fine; the crash happens downstream, the moment something tries to actually use it as a tensor, and the error message at that point won't mention this node at all.

The inputs and outputs that matter

  • ANY - the value to relabel or convert.
  • TYPE - the ComfyUI type to output as. Only STRING, INT, FLOAT, and BOOLEAN trigger real Python conversion; everything else is a relabel.

One output, typed * but displayed on the graph as whatever TYPE you selected, carrying the (possibly converted, possibly just relabeled) value.

How to install it

Search "ComfyUI-List-Utils" in ComfyUI Manager and install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/godmt/ComfyUI-List-Utils.git

Restart ComfyUI. No dependencies beyond the base pack, no models involved.

Common issues & troubleshooting

Wire connects fine but a downstream node crashes immediately on run. That's the relabel-not-convert behavior for non-scalar types catching up with you. Check that the underlying data genuinely matches the type you cast to - this node has no way to warn you if it doesn't, since it isn't inspecting the data, just changing the label.

Expected a numeric conversion and got garbage or an error instead. Conversion only happens for STRING/INT/FLOAT/BOOLEAN, and even then it follows normal Python conversion rules - casting the string "abc" to INT will fail the same way int("abc") fails in plain Python. Make sure the source value is actually convertible before relying on this.

Not sure why you'd need this instead of just fixing the upstream node's output type. Sometimes you can't - the upstream node might be from a different pack with a deliberately generic * output, or you're mid-refactor and don't want to rewire everything yet. Any Cast is meant as a pragmatic patch for exactly that situation, not a permanent architecture choice.

Categorylist_utils

Inputs (2)

NameTypeDefaultDescription
ANY*Value to relabel or convert.
TYPECOMBOComfyUI type shown on the output socket. STRING, INT, FLOAT, and BOOLEAN also attempt Python conversion.

Outputs (1)

NameTypeDescription
**The value output as the selected TYPE.