String Hash ๐
ComfyUI Node Guide
- hash
This is a narrow, purpose-built node and it's worth understanding the purpose before you decide whether you need it: it's for building cache-key filenames out of text that would otherwise be a filesystem nightmare. Feed it a prompt, a caption, or any string that came out of an upstream node, and it hands back a short, deterministic hex string - safe to drop straight into a filename, with none of the spaces, slashes, or unicode that made the original text unusable as one.
The mechanism. It's literally sha256(text), truncated to however many hex characters you ask for. Same input text, same output hash, every time, on any machine - that determinism is the entire point. If you're caching the result of an expensive step (an LLM call, an image generation) keyed on the prompt that produced it, you want a filename that's the same the next time someone runs the identical prompt, so the cache actually hits instead of silently regenerating everything. A raw prompt string as a filename would break on the first space or slash it contains; a hash of that string never will.
Where it fits in this pack specifically. The README calls it out as the companion to a sibling node, ImageHash|Mie (not covered here), for the case where what you're hashing is already a string rather than an image - the example given is a SAM3 prompt word, but it applies to any text-derived component of a cache key: a translated caption from the Translator node, a formatted string out of StringFormat, a model name from an LLM connector. Anywhere you'd otherwise be tempted to slugify a string by hand, this does it more reliably.
Inputs that matter. text is required - a single-line string, the thing you're hashing. There's a deliberately forgiving edge case worth knowing: if text is empty or unconnected, you don't get a crash, you get a constant sentinel value (a string of zeroes matching your chosen length). That means a workflow that sometimes has nothing to hash still produces a valid, filename-safe string rather than erroring the whole run - useful if this node sits in a path that isn't always populated. length is optional, defaulting to 12, and clamped to a 4โ64 range - anything you set outside that gets pulled back in rather than rejected.
Output. hash - lowercase hex, exactly length characters. As a worked example straight from the README: text="human" with the default length of 12 returns "79a5478768d2". Change length and you get a longer or shorter slice of the same underlying SHA-256 digest - a shorter hash is more filename-friendly but has a (still very low at 12+ characters) higher chance of collision if you're hashing a huge number of distinct strings; go longer if you're at real scale.
Install. Search "ComfyUI_MieNodes" in ComfyUI Manager, or cd ComfyUI/custom_nodes && git clone https://github.com/MieMieeeee/ComfyUI-MieNodes and restart ComfyUI. No dependencies, no models - this is standard library hashlib, nothing more.
Troubleshooting. If two runs you expected to produce the same hash don't, check for invisible differences in the input text - trailing whitespace, a different line ending, or a subtly different string from an upstream node (a translation that came back slightly reworded, for instance) will all produce a completely different hash, since even a one-character change scrambles the whole digest. That's not a bug, it's what a cryptographic hash is supposed to do - but it's the first thing to check when a cache you expected to hit doesn't. And if you're seeing the all-zero sentinel value unexpectedly, trace back to confirm text is actually receiving a non-empty string upstream.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | โ | |
| lengthopt | INT | 124โ64 | โ |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| hash | STRING | โ |