Evaluate
Run arbitrary Python on your prompt strings, right inside the graph
- tag
Evaluate is a tiny Python sandbox-as-a-node: you feed it a string and a snippet of Python, and it runs your code on the string and returns the result. Out of the box it sorts comma-separated tags alphabetically, and it's genuinely the node to reach for when one of the pack's fixed-purpose tag processors doesn't do the exact thing you need.
Think of it as the "write a one-off transform" node. Sort tags, dedupe them, strip a pattern, reorder a prompt, convert formats - anything expressible as main(string) -> string. Because it's a real exec(), you can do arbitrarily fancy things, which is both the power and the reason you should read the security note below.
How it works
The node takes your input tag string and your code (a multiline Python snippet) and runs:
exec(compile(code, "<evaluate_code>", "exec"), ns)
main = ns.get("main")
out = main(tag)
So your code must define a function main(tag: str) -> str that takes the input string and returns the transformed string. The default snippet is a working example - sort comma-separated tags:
def main(tag: str) -> str:
tags = [t.strip() for t in tag.split(",") if t.strip()]
return ", ".join(sorted(tags))
Anything else you can write in a single function body works the same way: import at the top of the snippet, loop, regex, whatever. If main isn't callable or doesn't return a string, you get a clear error instead of silent garbage. It re-runs on every change to either input (that's the IS_CHANGED contract), so it behaves like a normal data-transform node in the graph.
Inputs and output
tag- the input string. Force-input, so wire it from another node.code- the Python snippet (multiline). Defaults to the sort-tags example.
The single output is tag - the string returned by main(tag). Wire it into your prompt encoder, a ProcessTags pipeline, or anywhere else that eats strings.
Install
Part of ComfyUI-Alchemine-Pack:
cd ComfyUI/custom_nodes
git clone https://github.com/alchemine/comfyui-alchemine-pack
pip install -r requirements.txt
Or via ComfyUI Manager (search "ComfyUI-Alchemine-Pack"). Only dependency is python-dotenv; no models, no downloads.
Common issues and the honest warning
This node executes arbitrary Python with your user's privileges on every run. That's the definition of a supply-chain risk. Only put code you wrote or trust into it, and never paste code from an untrusted workflow - the ComfyUI ecosystem has already had a nasty malware incident exactly like this (the LLMVISION node). Treat any "try this Evaluate snippet" from a stranger the way you'd treat running a random shell script.
Functionally, the two things that bite people: forgetting that main must be a top-level function in the snippet (nested def main inside an if won't be found), and assuming imports in the snippet are available - they're not pre-imported, so put import re at the top of your code if you need it. Both fail loudly, which is honestly the best case.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| tag | STRING | — | |
| code | STRING | def main(tag: str) -> str: tags = [t.strip() for t in tag.split(",") if t.strip()] return ", ".join(sorted(tags)) | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| tag | STRING | — |