> For the complete documentation index, see [llms.txt](https://lamatic.ai/llms.txt).

# Classifier Node

<NodeOverview slug="classifier-node" type="ai" />

## Overview

The Classifier Node is a powerful AI component that enables users to automatically categorize and classify data based on predefined criteria or machine learning models. This node is essential for applications requiring intelligent data sorting, sentiment analysis, content moderation, and automated decision-making processes.

![classifier.png](../img/classifier/classifier.png)

<NodeTypeInfo 
  batchTrigger={false}
  eventTrigger={false}
  action={true}
  description="This node is an Action node that processes input data and classifies it into predefined categories using AI models."
/>

## Features

<details>
  <summary>**Key Functionalities**</summary>
  1. **Multi-Input Classification:** Supports both text and structured data inputs
  for classification. 2. **Customizable Categories:** Allows defining specific categories
  for classification based on application needs. 3. **Intent Recognition:** Identifies
  user intent from textual input and maps it to predefined intents. 4. **Automated
  Routing:** Routes data or user queries to the appropriate workflow based on classification
  results. 5. **LLM Integration:** Uses large language models to enhance classification
  accuracy and contextual understanding. 6. **Enhanced Classifier Editor:** Two-field editor (Name + Description) for better clarity, with inline editing enabled for both fields, making quick updates seamless.
</details>

<details>
  <summary>**Benefits**</summary>
  1. **Improved Automation:** Reduces manual intervention by automatically categorizing
  input data. 2. **Enhanced User Experience:** Directs queries or data to the appropriate
  processing module efficiently. 3. **Scalability:** Supports multiple classification
  tasks across different domains. 4. **Efficiency:** Streamlines flow by integrating
  classification and routing into a single node. 5. **AI-Powered Accuracy:** Leverages
  advanced AI models for context-aware classification.
</details>

## What Can I Build?

1. Automate customer support by categorizing and routing user queries to the correct department.

1. Enhance chatbot interactions with intent-based responses.

1. Implement dynamic content recommendations based on user input classification.

1. Build intelligent document categorization systems for large-scale data management.

## Prompt Examples

### Support Ticket Router

The LLM reads the input and routes the flow down the matching branch.

**System Prompt**
```
You are a support ticket classifier. 
Analyze the user's message and route it to the correct department.
Use the description of each classifier to make your decision.
Only pick one classifier. Do not explain your choice.
```

**User Prompt**
```
Classify this support message and route it to the right department:
{{triggerNode_1.message}}
```

**Classifiers**

| Name | Description |
|---|---|
| `Billing` | Payment issues, invoices, failed charges |
| `Technical` | Bugs, errors, integration problems |

Each classifier becomes a **branch in your flow**. Add the next nodes
(e.g. send to Slack, trigger an email) inside each branch.

> The Description field helps the LLM decide which branch to pick on ambiguous inputs.

## Setup

### Select the Classifier Node

1. Fill in the required parameters.
1. Build the desired flow
1. Select Classifier Node.
1. Deploy the Project

## Configuration Reference

![agentc.png](../img/classifier/classifier-config.webp)

| **Parameter**             | **Description**                                                                                                | **Example Value**            |
| ------------------------- | -------------------------------------------------------------------------------------------------------------- | ---------------------------- |
| **Generative Model Name** | Select the model to generate text based on the prompt.                                                         | Gemini Model                 |
| **Prompt Template**       | Define the instructions for generating the text output.Define the instructions for generating the text output. | Tell me something about Bali |
| **Classifier**            | Add Classifier with optional description. The two-field editor (Name + Description) supports inline editing for both fields, enabling quick and seamless updates. | `Classifier 1`               |
| **System Prompt**         | System prompt to guide the LLM                                                                                 | You are Travel Planner       |

### Classifier Editor

Classifier nodes now support optional descriptions alongside names. The enhanced two-field editor provides:

- **Name Field:** The classifier label used for identification and routing
- **Description Field (Optional):** Additional context or details about the classifier
- **Inline Editing:** Both fields support inline editing, allowing you to make quick updates directly in the editor without opening additional dialogs

## Low-Code Example

```yaml
nodes:
  - nodeId: agentClassifierNode_885
    nodeType: agentClassifierNode
    nodeName: Agent Classifier
    values:
      promptTemplate: ""
      systemPrompt: ""
      classifier:
        - label: Classifier 1
          value: agentClassifierNode_885-addNode_248
        - label: Classifier 2
          value: agentClassifierNode_885-addNode_671
    needs:
      - triggerNode_1
    classifier:
      - label: Classifier 1
        value: plus-node-addNode_248884
      - label: Classifier 2
        value: plus-node-addNode_671526
  - nodeId: plus-node-addNode_248884
    nodeType: addNode
    nodeName: ""
    values: {}
    needs:
      - agentClassifierNode_885
  - nodeId: plus-node-addNode_671526
    nodeType: addNode
    nodeName: ""
    values: {}
    needs:
      - agentClassifierNode_885
  - nodeId: plus-node-addNode_605143
```

## Output

### `_meta`

- A nested object containing metadata about the request processing.

  - **`prompt_tokens`**: The number of tokens in the input prompt provided to the model.
  - **`completion_tokens`**: The number of tokens generated in the model's output.
  - **`total_tokens`**: The total sum of `prompt_tokens` and `completion_tokens`.
  - **`model_name`**: The identifier of the AI model utilized for processing the request.
  - **`model_provider`**: The organization or entity supplying the AI model.

### `class`

- The classification label or result determined by the classifier.

### `condition`

- A secondary attribute indicating the condition or context of the classification.

### Example Output

```json
{
  "_meta": {
    "prompt_tokens": 56,
    "completion_tokens": 4,
    "total_tokens": 60,
    "model_name": "gemini-1.5-pro-latest",
    "model_provider": "google"
  },
  "class": "Classifier 1",
  "condition": "Classifier 1"
}
```

## Troubleshooting

### Common Issues

| **Problem**                     | **Solution**                                                    |
| ------------------------------- | --------------------------------------------------------------- |
| **Invalid API Key**             | Adjust the confidence threshold or refine system prompts.       |
| **Low Classification Accuracy** | Increase the `Wait for Page Load` time in the configuration.    |
| **Incorrect Routing**           | Review and update routing rules based on classification output. |

### Debugging

1. Check Lamatic Flow logs for error details.
1. Verify API Key.
1. Verify classification model settings.
1. Test different system prompts for improved accuracy.
