Generative AI is rapidly reshaping the way customer service teams handle support tickets. By automating ticket summarization and intelligent routing, organizations can speed up response times, reduce manual workload, and improve customer satisfaction. As we covered in our Ultimate Guide to AI Workflow Automation in Customer Service, automating these workflows is a cornerstone of modern support operations. In this deep dive, we’ll walk you through building a practical, testable workflow using generative AI—covering setup, code, integration, and troubleshooting.
Whether you’re just starting with AI-powered automation or looking to refine your existing processes, this playbook will help you use generative AI to summarize and route support tickets automatically. For a broader look at automated triage, see our step-by-step guide to building automated ticket triage with AI.
Prerequisites
- Python 3.9+ installed on your system
- Pip (Python package manager)
- OpenAI API Key (or alternative LLM provider, e.g., Azure OpenAI, Cohere, Anthropic)
- Basic knowledge of Python scripting and REST APIs
- Sample customer support tickets (CSV or JSON format)
- Optional: Access to a ticketing system API (e.g., Zendesk, Freshdesk) for integration
Step 1: Prepare Your Environment and Data
-
Set up a Python virtual environment:
python3 -m venv genai-support-env source genai-support-env/bin/activate
-
Install required Python packages:
pip install openai pandas requests python-dotenv
-
Export your OpenAI (or other LLM) API key as an environment variable:
export OPENAI_API_KEY="sk-..."
Tip: For local development, create a
.envfile with your API key:OPENAI_API_KEY=sk-... -
Prepare a sample dataset of support tickets (CSV or JSON):
Example
tickets.csv:ticket_id,subject,description 101,Login Issue,"I can't log into my account. The password reset link isn't working." 102,Billing Error,"I was charged twice for my last invoice. Please help." 103,Feature Request,"Can you add dark mode to the app?"
Screenshot description: Terminal showing a successful Python virtual environment activation and package installation.
Step 2: Build a Ticket Summarization Script Using Generative AI
-
Create a new Python script,
summarize_tickets.py: -
Write code to load tickets and call the LLM for summarization:
import os import pandas as pd import openai from dotenv import load_dotenv load_dotenv() openai.api_key = os.getenv("OPENAI_API_KEY") def summarize_ticket(description): prompt = ( "Summarize the following customer support ticket in 1-2 sentences, " "highlighting the key issue and any relevant context:\n\n" f"Ticket: {description}\n\nSummary:" ) response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": prompt}], max_tokens=60, temperature=0.3 ) return response.choices[0].message['content'].strip() df = pd.read_csv("tickets.csv") df["summary"] = df["description"].apply(summarize_ticket) df.to_csv("tickets_summarized.csv", index=False) print("Summarization complete. Output saved to tickets_summarized.csv") -
Run the script:
python summarize_tickets.py
-
Check the output:
Open
tickets_summarized.csvto see each ticket with its AI-generated summary.
Screenshot description: The output CSV file with a new "summary" column for each ticket.
For more on prompt design, see our Prompt Engineering Techniques for Customer Service Automation.
Step 3: Automatically Classify and Route Tickets
-
Decide on routing categories (e.g., Billing, Technical, Feature Request):
Define a mapping or list of categories your support team uses.
-
Extend your script to classify each ticket:
def classify_ticket(summary): prompt = ( "Given the following customer support ticket summary, assign it to one of these categories: " "Billing, Technical, Feature Request, Account, Other.\n\n" f"Summary: {summary}\n\nCategory:" ) response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": prompt}], max_tokens=10, temperature=0 ) return response.choices[0].message['content'].strip() df["category"] = df["summary"].apply(classify_ticket) df.to_csv("tickets_routed.csv", index=False) print("Classification and routing complete. Output saved to tickets_routed.csv")Tip: For production, batch API calls or use async for better performance.
-
Run the script again:
python summarize_tickets.py
-
Review the routed tickets:
The output
tickets_routed.csvnow includes both summaries and assigned categories.
Screenshot description: CSV file showing ticket_id, subject, summary, and category columns.
For a more advanced triage workflow, see From Zero to Automated: Building a Customer Support Ticket Routing Workflow with AI.
Step 4: Integrate with Your Ticketing System
-
Get your ticketing system’s API credentials (e.g., Zendesk, Freshdesk):
Follow your platform’s API documentation to obtain an API key or OAuth token.
-
Write Python code to update ticket status/category via API:
import requests ZENDESK_DOMAIN = "yourcompany.zendesk.com" ZENDESK_EMAIL = "your-email@company.com" ZENDESK_TOKEN = "your_zendesk_api_token" def update_ticket_category(ticket_id, category): url = f"https://{ZENDESK_DOMAIN}/api/v2/tickets/{ticket_id}.json" headers = {"Content-Type": "application/json"} data = { "ticket": { "custom_fields": [ {"id": 12345678, "value": category.lower()} ] } } response = requests.put( url, headers=headers, json=data, auth=(f"{ZENDESK_EMAIL}/token", ZENDESK_TOKEN) ) if response.status_code == 200: print(f"Ticket {ticket_id} updated to category '{category}'.") else: print(f"Failed to update ticket {ticket_id}: {response.text}") for _, row in df.iterrows(): update_ticket_category(row["ticket_id"], row["category"])Note: Replace
12345678with your actual custom field ID for category. -
Test the integration:
python summarize_tickets.py
Confirm tickets are updated in your ticketing system dashboard.
Screenshot description: Zendesk dashboard showing tickets auto-categorized by the AI workflow.
For scaling across cloud platforms, see Building AI Workflow Automations Across Multi-Cloud Environments in 2026.
Step 5: Automate the Workflow with Scheduling or Webhooks
-
Schedule the script to run periodically (e.g., every 5 minutes):
crontab -e */5 * * * * /path/to/genai-support-env/bin/python /path/to/summarize_tickets.py -
Alternatively, use webhooks from your ticketing system:
Configure your ticketing system to send new tickets to a webhook endpoint, which triggers your summarization and routing script.
from flask import Flask, request app = Flask(__name__) @app.route('/webhook/ticket', methods=['POST']) def handle_ticket(): data = request.json summary = summarize_ticket(data['description']) category = classify_ticket(summary) update_ticket_category(data['ticket_id'], category) return {"status": "processed"}, 200 if __name__ == "__main__": app.run(port=5000)Tip: Deploy this Flask app with a production-ready WSGI server (e.g., Gunicorn) and use HTTPS.
Screenshot description: Cron job list or webhook request logs showing successful automation runs.
For zero-touch, fully automated workflows, see How to Design Zero-Touch Customer Support Workflows with AI.
Common Issues & Troubleshooting
- API Rate Limits: If you process a large volume of tickets, you may hit LLM or ticketing system API rate limits. Implement batching, exponential backoff, or contact your provider for higher limits.
- Incorrect Classification: If the AI misroutes tickets, improve your prompt, provide category definitions, or fine-tune the model with examples. See our prompt engineering playbook.
-
Authentication Errors: Double-check API keys, tokens, and environment variables. Test API access with
curlorrequestsbefore integrating. -
Data Formatting Issues: Ensure your ticket data is clean (no missing fields, proper encoding). Use
pandasto preprocess as needed. - Timeouts or Slow Responses: Use async API calls or increase timeout settings. For large backlogs, process tickets in batches.
- Security: Never commit API keys to source control. Use environment variables or secrets management.
Next Steps
- Monitor and audit your automated workflows to ensure accuracy and fairness.
- Expand ticket categories and add escalation logic for urgent cases.
- Integrate sentiment analysis or intent detection for more nuanced routing.
- Explore multi-model approaches for specialized domains (e.g., legal, technical).
- Read our comparison of top AI workflow automation tools for customer service teams to choose the right stack for your needs.
- For a complete strategic overview, see The Ultimate Guide to AI Workflow Automation in Customer Service.
By following these steps, you can build a robust, generative AI-powered workflow for summarizing and routing customer support tickets—freeing your team to focus on high-value interactions and strategic improvements.