Dify → Problem Classification | Conditional Branching

Written by
Clara Bennett
Updated on:June-29th-2025
Recommendation

Improve customer service efficiency by classifying questions, and use conditional branches to refine workflows.

Core content:
1. The principle of question classifiers and their application in customer service conversations
2. Workflow template examples and their classification logic
3. Definition, function, and conditional types of conditional branches

Yang Fangxian
Founder of 53AI/Most Valuable Expert of Tencent Cloud (TVP)


Problem Classification

By defining the classification description, the question classifier can use LLM to infer the matching classification based on the user input and output the classification result, providing more accurate information to the downstream nodes.

Common usage scenarios include :

  • Customer Service Conversation Intent Classification
  • Product review categories
  • Batch mail classification

In a typical product customer service question-and-answer scenario, the question classifier can serve as a prerequisite for knowledge base retrieval, classifying the user's input question intent and, after classification, directing different downstream knowledge bases to query related content in order to accurately answer the user's questions.

Sample workflow template The following figure shows a sample workflow template for a product customer service scenario:

  • Category 1 : After-sales related issues
  • Category 2 : Issues related to product operation and use
  • Category 3 : Other issues

Application Example When users enter different questions, the classifier will automatically complete the classification according to the set classification labels/descriptions:

  • “How to set up address book contacts on iPhone 14?” →  “Questions related to product operation and use”
  • “How long is the warranty period?” →  “Questions related to after-sales service”
  • “What’s the weather like today?” →  “Other questions”

How to configure

  1. Select input variables : refers to the input content used for classification, and supports input file variables. In customer service Q&A scenarios, it is usually questions entered by users. sys.query.
  2. Select an inference model : Based on the natural language classification and inference capabilities of the large language model, select an appropriate model to improve the classification effect.
  3. Write category labels/descriptions : Manually add multiple categories and write keywords or descriptions to help the large language model understand the classification basis.
  4. Select downstream nodes : Select the subsequent process path based on the relationship between the classification results and the downstream nodes.

Advanced Settings

  • Instructions : Add additional instructions (such as richer classification criteria) in advanced settings to enhance classification capabilities.
  • Memory : When enabled, input will include chat history to improve question understanding during conversational interactions.
  • Image analysis : only applicable to LLMs with image recognition capabilities, allowing the input of image variables.
  • Memory Window : When off, the system dynamically filters the chat history based on the model context window; when on, the number of transfers (logarithmic) can be precisely controlled.

Output variables

  • class_name: Stores the prediction results of the classification model. After classification is completed, this variable contains the specific category label and can be referenced in subsequent processing nodes to execute the corresponding logic.

Conditional Branching

definition

Split the Chatflow / Workflow process into multiple branches based on If/else/elif conditions.

Node Function

The operating mechanism of conditional branches includes the following six paths:

  • IF condition: select the variable, set the condition and the value that satisfies the condition;
  • IF condition is True, execute the IF path;
  • IF condition is False, execute the ELSE path;
  • ELIF conditional judgment is True, execute the ELIF pathway;
  • ELIF conditional judgment is False, continue to judge the next ELIF path or execute the last ELSE path;

Condition Type

The following condition types are supported:

  • Contains
  • Not contains
  • Start with
  • End with
  • Is
  • Is not
  • Is empty
  • Is not empty

Scenario

The following text summary workflow is used as an example to illustrate each condition:

  • IF condition: Select the summarystyle Variable, condition is includedtechnology;
  • IF condition is True, execute the IF path, query the technology-related knowledge through the knowledge retrieval node and then reply to the LLM node (the upper part of the figure);
  • IF condition is False, but added ELIF conditions, that is summarystyle Variable input does not containtechnology,but ELIF The condition contains science and technology, will check ELIF Is the condition in True, and then execute the steps defined in the path;
  • ELIF The conditions within are False, that is, the input variable does not contain technology, nor does it include science and technology, continue to judge the next ELIF path or execute the last ELSE path;
  • IF condition is False,Right now summarystyle Variable input does not containtechnology, execute the ELSE path and reply through the LLM2 node (the lower part of the figure);

Multiple condition judgment

When it comes to complex conditional judgments, you can set multiple conditional judgments and set  AND  or  OR between the conditions, that is, take the intersection or union between the conditions .