Home Blog Reviews Best Picks Guides Tools Glossary Advertise Subscribe Free
Tech Frontline May 20, 2026 5 min read

From Zero to Automated: Building a Customer Support Ticket Routing Workflow with AI

Tired of manual ticket sorting? Here’s how to build an AI-powered support routing workflow from scratch.

T
Tech Daily Shot Team
Published May 20, 2026
From Zero to Automated: Building a Customer Support Ticket Routing Workflow with AI

Customer support teams are inundated with tickets, and manual triage is slow, error-prone, and expensive. In 2026, AI-powered workflow automation is transforming ticketing systems by routing tickets instantly and accurately—freeing up human agents for higher-value work. In this hands-on tutorial, you’ll build a practical, testable AI-driven support ticket routing workflow from scratch. You’ll learn to classify incoming support requests by topic, urgency, or customer type, and automatically assign them to the right agent or queue.

For a broader look at how AI is revolutionizing IT ticketing, see our parent pillar article on AI workflow automation in IT support.

Prerequisites

1. Define Your Ticket Routing Criteria

  1. Identify routing goals: Decide what categories or criteria matter for your workflow. Common examples:
    • Department (e.g., Billing, Technical Support, Sales)
    • Urgency (e.g., Critical, High, Normal)
    • Customer tier (e.g., Enterprise, SMB, Free)
  2. Document your categories: For this tutorial, we’ll use:
    • Department: Billing, Technical, Sales
    • Urgency: Critical, High, Normal, Low
  3. Prepare example tickets: Gather 10-20 anonymized support tickets for each category to use as test data.

2. Set Up Your Development Environment

  1. Create a new project folder:
    mkdir ai-ticket-routing && cd ai-ticket-routing
  2. Initialize a virtual environment:
    python3 -m venv venv
    source venv/bin/activate
  3. Install required Python packages:
    pip install openai pandas python-dotenv requests
  4. Create a .env file for your API key:
    touch .env
    echo "OPENAI_API_KEY=sk-..." >> .env
          
  5. Prepare sample ticket data: Save a CSV file named tickets.csv with columns: id,subject,description.
    id,subject,description
    1,Unable to login,I'm locked out of my account and need access urgently.
    2,Invoice issue,My last invoice has an incorrect amount.
    3,Interested in upgrade,Can you tell me more about the enterprise plan?
    ...
          

3. Build the AI Ticket Classification Script

  1. Create classify_ticket.py

    This script will use OpenAI’s GPT-3.5/4 API to classify each ticket by department and urgency.

    
    import os
    import pandas as pd
    import openai
    from dotenv import load_dotenv
    
    load_dotenv()
    openai.api_key = os.getenv("OPENAI_API_KEY")
    
    DEPARTMENTS = ["Billing", "Technical", "Sales"]
    URGENCY_LEVELS = ["Critical", "High", "Normal", "Low"]
    
    def classify_ticket(ticket_text):
        prompt = f"""You are an AI support assistant. 
    Given this ticket, assign:
    - Department: Billing, Technical, or Sales
    - Urgency: Critical, High, Normal, or Low
    
    Ticket:
    \"\"\"
    {ticket_text}
    \"\"\"
    
    Respond in JSON: {{"department": "...", "urgency": "..."}}"""
    
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[{"role": "user", "content": prompt}],
            max_tokens=50,
            temperature=0
        )
        import json
        try:
            result = json.loads(response['choices'][0]['message']['content'])
            return result['department'], result['urgency']
        except Exception as e:
            print("Error parsing AI response:", e)
            return None, None
    
    def main():
        df = pd.read_csv("tickets.csv")
        departments = []
        urgencies = []
    
        for idx, row in df.iterrows():
            ticket_text = f"Subject: {row['subject']}\nDescription: {row['description']}"
            dept, urg = classify_ticket(ticket_text)
            print(f"Ticket {row['id']} → {dept}, {urg}")
            departments.append(dept)
            urgencies.append(urg)
    
        df['department'] = departments
        df['urgency'] = urgencies
        df.to_csv("tickets_classified.csv", index=False)
    
    if __name__ == "__main__":
        main()
          
  2. Run the script:
    python classify_ticket.py

    Expected output: Each ticket is classified, and a new tickets_classified.csv file is created with department and urgency columns.

    Screenshot description: Terminal output showing ticket IDs and their assigned department and urgency.

4. Implement Automated Ticket Routing Logic

  1. Define routing rules:
    • Billing → assign to billing@company.com
    • Technical (Critical/High) → assign to oncall-tech@company.com
    • Technical (Normal/Low) → assign to tech-support@company.com
    • Sales → assign to sales@company.com
  2. Create route_ticket.py:
    
    import pandas as pd
    
    def assign_agent(department, urgency):
        if department == "Billing":
            return "billing@company.com"
        elif department == "Technical":
            if urgency in ["Critical", "High"]:
                return "oncall-tech@company.com"
            else:
                return "tech-support@company.com"
        elif department == "Sales":
            return "sales@company.com"
        else:
            return "support@company.com"
    
    def main():
        df = pd.read_csv("tickets_classified.csv")
        agents = []
        for idx, row in df.iterrows():
            agent = assign_agent(row['department'], row['urgency'])
            agents.append(agent)
            print(f"Ticket {row['id']} routed to {agent}")
        df['assigned_agent'] = agents
        df.to_csv("tickets_routed.csv", index=False)
    
    if __name__ == "__main__":
        main()
          
  3. Run the routing script:
    python route_ticket.py

    Expected output: tickets_routed.csv now contains an assigned_agent column.

    Screenshot description: Table view of tickets with their assigned agents.

5. Integrate with Your Ticketing System (Optional)

  1. Choose your integration method: Use the ticketing system’s REST API (e.g., Zendesk, Freshdesk, Jira).
  2. Example: Assigning tickets in Zendesk via API
    • Install requests (already done)
    • Update route_ticket.py to call the Zendesk API
    
    import os
    import requests
    
    ZENDESK_DOMAIN = "yourcompany.zendesk.com"
    ZENDESK_EMAIL = "youruser@company.com"
    ZENDESK_TOKEN = os.getenv("ZENDESK_API_TOKEN")
    
    def assign_ticket(ticket_id, agent_email):
        url = f"https://{ZENDESK_DOMAIN}/api/v2/tickets/{ticket_id}.json"
        data = {
            "ticket": {
                "assignee_email": agent_email
            }
        }
        resp = requests.put(
            url,
            json=data,
            auth=(f"{ZENDESK_EMAIL}/token", ZENDESK_TOKEN)
        )
        if resp.status_code == 200:
            print(f"Ticket {ticket_id} assigned to {agent_email}")
        else:
            print(f"Failed to assign ticket {ticket_id}: {resp.text}")
          

    Call assign_ticket for each ticket after routing. See your ticketing platform’s API docs for details.

6. Test the Full Workflow

  1. Use sample tickets: Start with your tickets.csv file.
  2. Run classification:
    python classify_ticket.py
  3. Run routing:
    python route_ticket.py
  4. Verify results: Open tickets_routed.csv and check that each ticket is assigned as expected.
  5. Optional: Use the API integration to assign tickets in your live system.
  6. Screenshot description: Side-by-side comparison of input ticket and routed result.

Common Issues & Troubleshooting

Next Steps

Conclusion

You’ve built a fully functional, testable AI-powered support ticket routing workflow from scratch. This foundation can be extended, productionized, and customized for your organization’s needs. As AI workflow automation becomes the standard in customer support, hands-on skills like these will be essential. For more advanced automations and industry insights, explore our related resources on AI workflow automation tools and the future of IT ticketing.

customer support ticket routing workflow automation AI

Related Articles

Tech Frontline
LLM Prompt Debugging: How to Fix and Optimize Broken Workflow Automations
May 20, 2026
Tech Frontline
API Rate Limits and Quotas: Avoiding Bottlenecks in AI Workflow Automation
May 20, 2026
Tech Frontline
Best Practices for Securing API-Driven AI Workflows in 2026
May 20, 2026
Tech Frontline
API Integration Patterns for Low-Code AI Workflow Automation in 2026
May 20, 2026
Free & Interactive

Tools & Software

100+ hand-picked tools personally tested by our team — for developers, designers, and power users.

🛠 Dev Tools 🎨 Design 🔒 Security ☁️ Cloud
Explore Tools →
Step by Step

Guides & Playbooks

Complete, actionable guides for every stage — from setup to mastery. No fluff, just results.

📚 Homelab 🔒 Privacy 🐧 Linux ⚙️ DevOps
Browse Guides →
Advertise with Us

Put your brand in front of 10,000+ tech professionals

Native placements that feel like recommendations. Newsletter, articles, banners, and directory features.

✉️
Newsletter
10K+ reach
📰
Articles
SEO evergreen
🖼️
Banners
Site-wide
🎯
Directory
Priority

Stay ahead of the tech curve

Join 10,000+ professionals who start their morning smarter. No spam, no fluff — just the most important tech developments, explained.