पाठ 11 / 25
Question Classifier Node
Let a model choose the branch, then measure it.
Model-based routing
The question classifier node uses an LLM to put the input into one of several classes you describe (billing, technical, other), each with its own branch. It handles varied wording better than keyword rules but can misroute ambiguous messages. Write clear class descriptions with examples, use a capable but cheap model, and test routing accuracy on a labelled set of real messages before relying on it. Send uncertain or unknown cases to a safe default branch. Dify's node names, menus and options change between versions; check the current Dify documentation.
Measuring routing accuracy, run
I ran this with plain Python 3 (scikit-learn 1.9.1 where imported). It models or tests one piece of a Dify app locally; Dify itself was not running. On eight labelled test messages, a classifier's choices are 75% correct: billing recall is 1.00, technical 0.67, other 0.50. "How do I export my data" went to other and "Is there a student discount" went to billing. These are example results to show how to score the node.
cases = [ # (user message, expected class, class chosen by the question-classifier node in a test run)
("I was charged twice", "billing", "billing"), ("App crashes when I upload", "technical", "technical"),
("Can I get a refund for order 77", "billing", "billing"), ("How do I export my data", "technical", "other"),
("Do you have an office in Pune", "other", "other"), ("Payment failed but money deducted", "billing", "billing"),
("Login code never arrives", "technical", "technical"), ("Is there a student discount", "other", "billing"),
]
acc = sum(e == g for _, e, g in cases) / len(cases)
print(f"routing accuracy {acc:.2f} on {len(cases)} test messages")
for cls in ["billing", "technical", "other"]:
rel = [g for _, e, g in cases if e == cls]
print(f" {cls:<9} recall {sum(g == cls for g in rel) / len(rel):.2f}")
print("misrouted:", [m for m, e, g in cases if e != g])
Output:
routing accuracy 0.75 on 8 test messages billing recall 1.00 technical recall 0.67 other recall 0.50 misrouted: ['How do I export my data', 'Is there a student discount']
Improve class descriptions from errors
Add misrouted examples to the class descriptions (for example, "data export questions are technical") and re-test.
त्वरित जाँच: How should you check a question classifier node?
- Check only one example
- Trust it without testing
- Count the number of classes
- Measure routing accuracy on labelled real messages
Answer
Measure routing accuracy on labelled real messages — Routing errors cascade downstream.