Text Classifier Multiple Branches - How to combine all fired outputs into single item?

I have a Text Classifier node with “Allow Multiple Classes To Be True” enabled. When multiple categories fire (e.g. “OpenAI” and “Short Report”), I get separate outputs on different branches.

Problem: I need to collect ALL fired branch names into a single item for further processing, but Merge nodes wait for all inputs even when only some branches fire.

My setup:

  • Text Classifier → 4 different branches
  • Need to know which branches fired (e.g. [“OpenAI”, “Short Report”])
  • Want single output item with all fired branch info

Current issue: Merge node hangs when only 2 out of 4 branches fire.

Any ideas how to reliably collect multiple Text Classifier outputs into one item?

Thanks!

It says 2 items here

Information on your n8n setup

  • n8n version: 1.101
  • Database (default: SQLite): SQLITE
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Windows 11

First Option: I know it sounds complicated and unnecessary but maybe you can turn it into two workflows. Using the Wait node you can wait for some time and then receive whatever data the other workflow returns and continue.

One workflow that has a Webhook Trigger → Wait 2 minutes → Continues with data received

And the other gets triggered to run the classifier. It seems complicated but worth the shot.

Second Option (Not sure): Have you tried using a switch node right after the classifier? E.g, If (Option 1 From classifier) → Exists → Continues with that data. Although it’s blurry when I think about it, it may be an option.

Not sure I understand where you are going with the Switch Node?

What I meant is;

You said that the workflow gets stuck because the Code node is expecting the rest of your options. So I was wandering if it would still get stuck if you attached a Switch node to the classifier before this Code node.

And the rules is something like ‘(option1 → exists )’ This is what I was wandering if it would work. Because in theory this node would use the options that exist and pass them through the data flow.

Edit: The Webhook method seems more reliable.

yes but it can habe multiple outputs which means it will output 2 items from there on… so I would have to create a logic within the switch for every scenario if that even works since it gets 2 items as inputs - so that wont work.

Try Webhooks. It seems more logical to use a time limit at this point. One minute is more than enough for the AI to generate the right output (Even when all options are included).

Thanks but how should this be a solution to something like this. I mean thing this bigger. Think we have 15 classifications and I allow multiple selections this isnt a solution either since its way too complex…

I mean the code:

return [{
  json: {
    ...items[0].json,
    branch_name: $input.params.categories.categories[$prevNode.outputIndex].category,
    output_index: $prevNode.outputIndex
  }
}];

this code works if I set it to allow only one to be true. it outputs the correct branch only… but when multiple are selected it seems to not be able to handle 2 items together in this case.

It gets progressively harder to automate a workflow when dealing with bigger amount of data. And I have to be honest I have never dealt with this much (15 Branches for instance) since it will deplete all my tokens.

I have some problems with credentials these days so I can’t really test myself before telling you to do something so I’m just trying to give you possible solutions.

How about using an external DB to store whatever the output items are, the retrieve them as a list in the next node? Google Sheets for instance, use Append Rows into Sheet (A node for every branch there is) and then attach all to a Get Rows node which you can turn into one single item afterwards.

@Mookie_Lian you see the problem is these cases can be quite large as soon as you checkmark the “allow multiple selections” field cause then even with 4 selections you already have 15 possible combinations… so I just wonder how that can be done via code…

I`m trying to solve the exact same problem, get the name of the match branch on a parameter. If you find a way to do it pls let me know.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.