Opens in a new tab
Guide

Build a Python ticket router that knows when to ask for help

In brief

Run a small keyword router, then compare a learned classifier by how long it takes for a team that can help to accept the ticket.

4 min read

Is this the right starting point?
Before you read
Basic Python and support-ticket workflow familiarity; prior NLP training experience is unnecessary.
What you will take away
Run a transparent routing baseline and evaluate a learned alternative through capable ownership and correction effort.
Sources
A paper ticket sits on a curved yellow track between two desks, with a branch leading to a third desk.
On this page3 sections

A support ticket can spend an afternoon moving briskly. Imagine someone reporting an intermittent login failure. The router sends it to networking, networking sends it back, and the next attempt makes the same choice. Every reassignment is quick. The customer is still waiting for someone to look at the problem.

Start with a router simple enough to show why it sent a ticket somewhere. You can use it to compare a learned classifier later, including the time from arrival to the moment a team that can investigate accepts the work. The prediction only gets the ticket to a door.

Give the router an answer for “I can't tell”

Save this example as route_ticket.py and run python3 route_ticket.py. It needs Python 3 and no extra packages. The program converts the text to lowercase, extracts runs of letters from a to z, and compares the resulting words with the keywords for each team.

import re

KEYWORDS = {
    "Network Team": {"network", "dns", "vpn"},
    "Security Team": {"phishing", "malware"},
    "Software Team": {"application", "software"},
    "Hardware Team": {"hardware", "battery"},
}

def propose_queue(text):
    words = set(re.findall(r"[a-z]+", text.lower()))
    matches = [team for team, keys in KEYWORDS.items() if words & keys]
    return matches[0] if len(matches) == 1 else "Human triage"

if __name__ == "__main__":
    ticket = "I'm having trouble accessing a specific website."
    print(propose_queue(ticket))

The sample says someone is having trouble accessing a website. None of the category keywords appears, so it prints Human triage. A message with both vpn and phishing gets that result too, because two categories matched. A message with vpn and dns only matches one category, so it goes to networking.

Where the keyword router sends a ticket
Where the keyword router sends a ticket. One matching category gives the router a queue to suggest. An empty match or several matches leaves the ticket for human triage.
One matching category gives the router a queue to suggest. An empty match or several matches leaves the ticket for human triage.
Read diagram description

One matching category gives the router a queue to suggest. An empty match or several matches leaves the ticket for human triage. The program splits the input into words and checks each category's keywords. It proposes the one matching queue when there is exactly one. Otherwise it returns Human triage.

Try “This is not a VPN issue.” Now it suggests networking. You and the program read the same word and took different things from it. The program never considered the negation. That gives you a small, reproducible case a later classifier can try to handle better.

Our login ticket poses a different problem. Even a reader may need to know whether the identity provider rejected the login or a connection failed before the request reached it. Sending the same sparse description through another round of prediction won't uncover that detail. Give the triager enough time and authority to ask for it and find a team that will take the work. If the same gap keeps sending tickets back, look at the categories and the handoff that produced it.

Yesterday's first queue can teach the wrong lesson

A learned classifier uses examples of ticket text paired with reviewed destinations. It can learn that two different phrases often point to the same team. It can also learn an old habit with impressive accuracy. If the login ticket says “Network Team” in its first assignment and the identity team eventually handles it, which label should become the example?

Choose labels that reflect the work a team could actually accept. Protect customer data before using tickets in training, and keep duplicates and closely related copies from crossing the training and evaluation boundary. Hold back a later period to see how the router handles wording and ownership it didn't see while learning.

Suppose you review 100 tickets. Ninety-five belong to a common queue and five to a specialist. A router that sends every ticket to the common queue gets 95% right and finds none of the specialist's work. The missing five are much easier to see in a confusion matrix, a table of intended and predicted destinations. Scikit-learn's evaluation guide explains that table and how to measure what each queue receives and what it misses.

Decide which suggestions can travel alone

A learned router can also decline to send a ticket automatically. Pick the threshold using data outside training and compare what a wrong assignment costs with the workload the fallback creates. A high score may rank one queue ahead of another. Unless you've checked calibration, the score need not tell you how often predictions like it are correct.

Start with suggestions a triager can review. Compare the two routers on the same ticket stream, counting handoffs, correction work, cases still waiting and time until a team with the right capability accepts the investigation. Keep the existing escalation path for severe incidents. Queue selection must leave urgent response intact.

Keep the history and reason for each handoff so the next team can use what the earlier team learned. Revisit the comparison when products, teams or routing rules change. The customer reliability guide connects that operational history with the effect on the person who reported the failure.

Send the login ticket through the comparison again. If the triager can get the missing detail and an identity engineer takes the investigation, you've changed what happens to the ticket. If networking just gets the same message sooner, the customer will still be looking at the same login screen.

Sources & context

Sources linked in this article. Read alongside the author’s analysis; a citation does not independently verify a publisher’s claims.

Report an error or outdated detail

Keep reading

Where to go next