Overview
The Dynamic Text Classifier node classifies input text into user-defined categories using an AI language model. It is useful for scenarios where you want to automatically tag or label text data based on custom categories, such as sorting customer feedback, categorizing support tickets, or organizing content by topic.
Users provide a list of categories and the text to classify. The node sends this information to an AI model with a prompt instructing it to output classification results in a structured JSON format. It supports single-label or multi-label classification and can handle cases where no category clearly matches by either discarding the item or routing it to an "Other" output branch.
Practical examples:
- Automatically tagging product reviews as "Positive," "Neutral," or "Negative."
- Categorizing incoming emails into departments like "Sales," "Support," or "Billing."
- Sorting social media comments into topics such as "Feature Request," "Bug Report," or "General Feedback."
Properties
| Name | Meaning |
|---|---|
| Text to Classify | The text input to be classified. Can be static text or an expression referencing previous node data. |
| Categories | A collection of categories to classify the text into. Each category requires a name and optionally a description to clarify its meaning. |
| Options | Collection of additional options: |
| - Allow Multiple Classes To Be True (multiClass) | Boolean flag indicating if multiple categories can be true simultaneously (multi-label classification). If false, only one category can be selected per input. |
| - When No Clear Match (fallback) | Defines behavior when the text does not clearly match any category: • Discard Item — ignore and drop from output. • Output on Extra, 'Other' Branch — send to a separate "Other" output branch. |
| - System Prompt Template | Custom string template used as the system prompt for the AI model. Supports placeholders for categories and formatting instructions. Defaults to a prompt asking the model to classify text into the given categories. |
| - Enable Auto-Fixing | Boolean flag to enable automatic fixing of broken AI outputs by triggering an additional AI call. Helps ensure valid JSON output from the model. |
Output
The node outputs an array of arrays, each corresponding to one output branch:
- Each inner array contains items classified into the respective category.
- If fallback is set to "other," an additional output branch named "Other" will contain items that do not fit any category.
- Each item includes the original input data plus classification metadata.
- In case of errors during classification, if "Continue On Fail" is enabled, the error message is included in the output JSON for that item.
The classification result for each input is a JSON object with boolean fields for each category indicating whether the input belongs to that category. If multiClass is false, only one category should be true; otherwise, multiple categories can be true.
If binary data were involved, it would represent the classified content, but this node only outputs JSON classification results.
Dependencies
- Requires an AI language model connection configured as an input to the node.
- Uses LangChain libraries for prompt templating, message handling, and output parsing.
- No external API keys are directly referenced here, but the AI model connection must be properly authenticated in n8n.
Troubleshooting
- No categories defined error: The node throws an error if no categories are provided. Ensure at least one category is added.
- Invalid JSON output from AI: If the AI returns malformed JSON, enabling "Enable Auto-Fixing" may help by retrying the output parsing.
- Empty output or discarded items: If many inputs are discarded, check the fallback option and consider switching to the "Other" branch to capture unmatched items.
- Multiple categories true unexpectedly: Verify the "Allow Multiple Classes To Be True" option matches your use case (single vs multi-label).
- AI model connection issues: Ensure the AI language model input is connected and authenticated correctly.
- Errors during classification: If "Continue On Fail" is off, the node will stop on errors. Enable it to continue processing other items and see error details in output.