Ticket Routing and Escalation Logic
Classifying intent, routing to specialist agents, and escalation triggers.
The Routing Problem
A customer service agent receives thousands of diverse messages daily: billing disputes, password resets, product defects, shipping delays, feature requests. Sending every message to the same handler produces slow, low-quality responses.
Ticket routing classifies each message and sends it to the team best equipped to resolve it.
Intent Classification with an LLM
The routing layer calls an LLM with a classification prompt. The model returns a structured response with an intent label and a confidence score.
import openai, json
client = openai.OpenAI(api_key='YOUR_OPENAI_KEY')
INTENTS = ['billing', 'technical_support', 'returns_refunds',
'account_access', 'shipping', 'general_inquiry']
def classify_intent(message: str) -> dict:
prompt = (
f'Classify this customer message into exactly one intent.\n'
f'Intents: {INTENTS}\n'
f'Message: "{message}"\n'
f'Respond with JSON: {{"intent": "...", "confidence": 0.0-1.0}}'
)
resp = client.chat.completions.create(
model='gpt-4o-mini',
messages=[{'role': 'user', 'content': prompt}],
response_format={'type': 'json_object'}
)
return json.loads(resp.choices[0].message.content)All lessons in this course
- Ticket Routing and Escalation Logic
- CRM Integration: Salesforce and HubSpot
- Human Handoff Protocols
- Customer Context and History Management