๐บ Categorize String
A keyword classifier that turns strings into category indexes
- category_index
Sometimes you don't want a model to decide what category a string belongs to - you want a deterministic rule that gives the same answer every time. Nilor Categorize String is a tiny keyword classifier: you define up to ten categories, each with a comma-separated list of keywords, feed it a string, and it returns the index of the first category that matches. That's the entire node, and for routing strings in an automated pipeline it's exactly the right tool.
How it works
The inputs are simple:
input_string- what you're classifying.number_of_categories- how many of the category slots are active (default 2, max 10).category_0โฆcategory_9- each a comma-separated keyword list, e.g.apple, red fruitandbanana, yellow fruit(the defaults).
The matching is deliberately naive: it lowercases everything, splits each category's string on commas, strips whitespace, and checks whether any keyword is a substring of the input. First matching category wins, and it returns its index as the category_index INT output. If nothing matches, you get -1.
The substring detail is where people get surprised in both directions. Because it's substring matching, apple will match "apple pie" - good. But it will also match "pineapple" and "applesauce", because those contain the letters apple. It's case-insensitive, but it's not a word-boundary match, so if your keywords are short or common, you'll get false positives. Keep keywords distinctive, and remember: no matches โ -1, which is a silent failure if you don't handle it.
When you'd reach for it
The classic use is routing in a batch pipeline: you have a filename or a caption string, and downstream behavior should depend on which "type" it is. Wire category_index into a if-style router or a select node, and the graph picks a different branch (different model, different upscaler, different prompt) per category. It also works as a quick tag normalizer - mapping arbitrary user input onto a fixed set of buckets before it hits anything that cares about consistent labels.
Two design notes. Categories are checked in index order, so the first one in the list wins ties - order your most specific category first. And unlike the pack's ๐บ Random String node, this one is fully deterministic: same input, same categories, same index, forever. That reproducibility is the whole point of using it over an LLM classifier, which would be overkill and non-deterministic for "is this filename a cat or a dog".
Install
ComfyUI Manager (search "Nilor Nodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/nilor-corp/nilor-nodes
cd nilor-nodes && pip install -r requirements.txt
Restart ComfyUI; find it under Nilor Nodes ๐บ โ Utilities. Pure stdlib, no extra dependencies.
Bottom line
This is a rule engine wearing a node costume, and that's fine - it's honest, fast, and predictable. Use it when you need deterministic string routing and a one-liner classification beats building the same matching logic out of text-processing nodes. Just respect the substring trap and the -1 sentinel, and it'll quietly do its job forever. If you need real semantic classification with synonyms and context, that's a different tool entirely - this one will happily call "grand theft auto" a car.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | โ | |
| number_of_categories | INT | 21โ10 | โ |
| category_0 | STRING | apple, red fruit | โ |
| category_1 | STRING | banana, yellow fruit | โ |
| category_2opt | STRING | โ | |
| category_3opt | STRING | โ | |
| category_4opt | STRING | โ | |
| category_5opt | STRING | โ | |
| category_6opt | STRING | โ | |
| category_7opt | STRING | โ | |
| category_8opt | STRING | โ | |
| category_9opt | STRING | โ |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| category_index | INT | โ |