ticket-routing changedabout-claude/use-case-guides/ticket-routing
Nearest release: v2.1.330, published 3 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+263added
Lines−221removed
From line
1
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits18to this page, all time
## Why use Claude for ticket routing ## Define whether to use Claude for ticket routing
The whole hunk
from line 1, old and new numbered
/
The two sides of this change are more than 400 edits apart, too far apart to line up, so this is the differ's own diff of it and the words inside a line are not marked.
from line 1
11---
22title: Ticket routing
33url: https://platform.claude.com/docs/en/about-claude/use-case-guides/ticket-routing
4description: This guide walks through how to use Claude's advanced natural language understanding capabilities to classify customer support tickets at scale based on customer intent, urgency, prioritization, customer profile, and more.
4description: Classify customer support tickets by intent, urgency, and other criteria with Claude, then evaluate and improve the routing.
55---
66
7This guide shows how to route customer support tickets with Claude. It covers why Claude suits the task, how to write and deploy a classification prompt, and how to evaluate and improve it.
8
79## Prerequisites
810
9* A Claude API key and the Anthropic SDK installed
11* The Anthropic SDK installed
12* A credential for the Claude API, such as [Workload Identity Federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation) for a service or [CLI sign-in](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication) on your own machine
1013* Access to, and familiarity with, your existing support ticketing system
1114* A sample set of historical support tickets for testing
1215
13## Define whether to use Claude for ticket routing
16## Why use Claude for ticket routing
1417
1518Here are some key indicators that you should use an LLM such as Claude instead of traditional ML approaches for your classification task:
1619
from line 34
3134 Traditional ML approaches often rely on bag-of-words models or simple pattern matching. Claude excels at applying underlying rules when classes are defined by conditions rather than examples.
3235 </Accordion>
3336
34 <Accordion title="You need interpretable reasoning for classification decisions">
35 Many traditional ML models provide little insight into their decision-making process. Claude can provide human-readable explanations for its classification decisions, building trust in the automation system and facilitating easy adaptation if needed.
37 <Accordion title="You need explanations for classification decisions">
38 Many traditional ML models provide little insight into their decision-making process. Claude can give a short explanation of each classification, which helps your team trust the automation and adjust it when needed.
3639 </Accordion>
3740
3841 <Accordion title="You want to handle edge cases and ambiguous tickets more effectively">
from line 244
241244
242245Ticket routing is a type of classification task. Claude analyzes the content of a support ticket and classifies it into predefined categories based on the issue type, urgency, required expertise, or other relevant factors.
243246
244Write a ticket classification prompt. The initial prompt should contain the contents of the user request and return both the reasoning and the intent.
247Write a ticket classification prompt. It contains the text of the support request and asks Claude for two things: a one-sentence summary of the request and its intent.
245248
246249<Tip>
247250 Try the [metaprompt recipe from the Claude Cookbook](https://colab.research.google.com/github/anthropics/claude-cookbooks/blob/main/misc/metaprompt.ipynb) to have Claude write a first draft for you.
from line 264
261264 ```python Python
262265 def classify_support_request(ticket_contents):
263266 # Define the prompt for the classification task
264 classification_prompt = f"""You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with your reasoning.
267 classification_prompt = f"""You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with a one-sentence summary of the request.
265268
266269 Here is the customer support request you need to classify:
267270
268271 <request>{ticket_contents}</request>
269272
270 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for has concerns about.
271
272 First, write out your reasoning and analysis of how to classify this request inside <reasoning> tags.
273
274 Then, output the appropriate classification label for the request inside a <intent> tag. The valid intents are:
273 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for or has concerns about.
274
275 First, write a one-sentence summary of the request inside <summary> tags.
276
277 Then, output the appropriate classification label for the request inside an <intent> tag. The valid intents are:
275278 <intents>
276279 <intent>Support, Feedback, Complaint</intent>
277280 <intent>Order Tracking</intent>
from line 287
284287 <request>Hello! I had high-speed fiber internet installed on Saturday and my installer, Kevin, was absolutely fantastic! Where can I send my positive review? Thanks for your help!</request>
285288
286289 Here is an example of how your output should be formatted (for the above example request):
287 <reasoning>The user seeks information in order to leave positive feedback.</reasoning>
290 <summary>The user seeks information in order to leave positive feedback.</summary>
288291 <intent>Support, Feedback, Complaint</intent>
289292
290293 Here are a few more examples:
from line 297
294297 <request>I wanted to write and personally thank you for the compassion you showed towards my family during my father's funeral this past weekend. Your staff was so considerate and helpful throughout this whole process; it really took a load off our shoulders. The visitation brochures were beautiful. We'll never forget the kindness you showed us and we are so appreciative of how smoothly the proceedings went. Thank you, again, Amarantha Hill on behalf of the Hill Family.</request>
295298
296299 Example 2 Output:
297 <reasoning>User leaves a positive review of their experience.</reasoning>
300 <summary>User leaves a positive review of their experience.</summary>
298301 <intent>Support, Feedback, Complaint</intent>
299302 </example 2>
300303 <example 3>
from line 310
307310 <request>Your website keeps sending ad-popups that block the entire screen. It took me twenty minutes just to finally find the phone number to call and complain. How can I possibly access my account information with all of these popups? Can you access my account for me, since your website is broken? I need to know what the address is on file.</request>
308311
309312 Example 9 Output:
310 <reasoning>The user requests help accessing their web account information.</reasoning>
313 <summary>The user requests help accessing their web account information.</summary>
311314 <intent>Support, Feedback, Complaint</intent>
312315 </example 9>
313316
314 Remember to always include your classification reasoning before your actual intent output. The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
317 Remember to always include your one-sentence summary before your intent output. The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
315318 """
316319 ```
317320
318321 ```typescript TypeScript
319322 function classifySupportRequest(ticketContents: string) {
320323 // Define the prompt for the classification task
321 const classificationPrompt = `You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with your reasoning.
324 const classificationPrompt = `You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with a one-sentence summary of the request.
322325
323326 Here is the customer support request you need to classify:
324327
325328 <request>${ticketContents}</request>
326329
327 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for has concerns about.
328
329 First, write out your reasoning and analysis of how to classify this request inside <reasoning> tags.
330
331 Then, output the appropriate classification label for the request inside a <intent> tag. The valid intents are:
330 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for or has concerns about.
331
332 First, write a one-sentence summary of the request inside <summary> tags.
333
334 Then, output the appropriate classification label for the request inside an <intent> tag. The valid intents are:
332335 <intents>
333336 <intent>Support, Feedback, Complaint</intent>
334337 <intent>Order Tracking</intent>
from line 344
341344 <request>Hello! I had high-speed fiber internet installed on Saturday and my installer, Kevin, was absolutely fantastic! Where can I send my positive review? Thanks for your help!</request>
342345
343346 Here is an example of how your output should be formatted (for the above example request):
344 <reasoning>The user seeks information in order to leave positive feedback.</reasoning>
347 <summary>The user seeks information in order to leave positive feedback.</summary>
345348 <intent>Support, Feedback, Complaint</intent>
346349
347350 Here are a few more examples:
from line 354
351354 <request>I wanted to write and personally thank you for the compassion you showed towards my family during my father's funeral this past weekend. Your staff was so considerate and helpful throughout this whole process; it really took a load off our shoulders. The visitation brochures were beautiful. We'll never forget the kindness you showed us and we are so appreciative of how smoothly the proceedings went. Thank you, again, Amarantha Hill on behalf of the Hill Family.</request>
352355
353356 Example 2 Output:
354 <reasoning>User leaves a positive review of their experience.</reasoning>
357 <summary>User leaves a positive review of their experience.</summary>
355358 <intent>Support, Feedback, Complaint</intent>
356359 </example 2>
357360 <example 3>
from line 367
364367 <request>Your website keeps sending ad-popups that block the entire screen. It took me twenty minutes just to finally find the phone number to call and complain. How can I possibly access my account information with all of these popups? Can you access my account for me, since your website is broken? I need to know what the address is on file.</request>
365368
366369 Example 9 Output:
367 <reasoning>The user requests help accessing their web account information.</reasoning>
370 <summary>The user requests help accessing their web account information.</summary>
368371 <intent>Support, Feedback, Complaint</intent>
369372 </example 9>
370373
371 Remember to always include your classification reasoning before your actual intent output. The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
374 Remember to always include your one-sentence summary before your intent output. The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
372375 `;
373376 }
374377 ```
from line 381
378381 {
379382 // Define the prompt for the classification task
380383 var classificationPrompt = $"""
381 You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with your reasoning.
384 You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with a one-sentence summary of the request.
382385
383386 Here is the customer support request you need to classify:
384387
385388 <request>{ticketContents}</request>
386389
387 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for has concerns about.
388
389 First, write out your reasoning and analysis of how to classify this request inside <reasoning> tags.
390
391 Then, output the appropriate classification label for the request inside a <intent> tag. The valid intents are:
390 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for or has concerns about.
391
392 First, write a one-sentence summary of the request inside <summary> tags.
393
394 Then, output the appropriate classification label for the request inside an <intent> tag. The valid intents are:
392395 <intents>
393396 <intent>Support, Feedback, Complaint</intent>
394397 <intent>Order Tracking</intent>
from line 404
401404 <request>Hello! I had high-speed fiber internet installed on Saturday and my installer, Kevin, was absolutely fantastic! Where can I send my positive review? Thanks for your help!</request>
402405
403406 Here is an example of how your output should be formatted (for the above example request):
404 <reasoning>The user seeks information in order to leave positive feedback.</reasoning>
407 <summary>The user seeks information in order to leave positive feedback.</summary>
405408 <intent>Support, Feedback, Complaint</intent>
406409
407410 Here are a few more examples:
from line 414
411414 <request>I wanted to write and personally thank you for the compassion you showed towards my family during my father's funeral this past weekend. Your staff was so considerate and helpful throughout this whole process; it really took a load off our shoulders. The visitation brochures were beautiful. We'll never forget the kindness you showed us and we are so appreciative of how smoothly the proceedings went. Thank you, again, Amarantha Hill on behalf of the Hill Family.</request>
412415
413416 Example 2 Output:
414 <reasoning>User leaves a positive review of their experience.</reasoning>
417 <summary>User leaves a positive review of their experience.</summary>
415418 <intent>Support, Feedback, Complaint</intent>
416419 </example 2>
417420 <example 3>
from line 427
424427 <request>Your website keeps sending ad-popups that block the entire screen. It took me twenty minutes just to finally find the phone number to call and complain. How can I possibly access my account information with all of these popups? Can you access my account for me, since your website is broken? I need to know what the address is on file.</request>
425428
426429 Example 9 Output:
427 <reasoning>The user requests help accessing their web account information.</reasoning>
430 <summary>The user requests help accessing their web account information.</summary>
428431 <intent>Support, Feedback, Complaint</intent>
429432 </example 9>
430433
431 Remember to always include your classification reasoning before your actual intent output. The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
434 Remember to always include your one-sentence summary before your intent output. The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
432435 """;
433436 }
434437 ```
from line 439
436439 ```go Go
437440 func classifySupportRequest(ticketContents string) {
438441 // Define the prompt for the classification task
439 classificationPrompt := `You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with your reasoning.
442 classificationPrompt := `You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with a one-sentence summary of the request.
440443
441444 Here is the customer support request you need to classify:
442445
443446 <request>` + ticketContents + `</request>
444447
445 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for has concerns about.
446
447 First, write out your reasoning and analysis of how to classify this request inside <reasoning> tags.
448
449 Then, output the appropriate classification label for the request inside a <intent> tag. The valid intents are:
448 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for or has concerns about.
449
450 First, write a one-sentence summary of the request inside <summary> tags.
451
452 Then, output the appropriate classification label for the request inside an <intent> tag. The valid intents are:
450453 <intents>
451454 <intent>Support, Feedback, Complaint</intent>
452455 <intent>Order Tracking</intent>
from line 462
459462 <request>Hello! I had high-speed fiber internet installed on Saturday and my installer, Kevin, was absolutely fantastic! Where can I send my positive review? Thanks for your help!</request>
460463
461464 Here is an example of how your output should be formatted (for the above example request):
462 <reasoning>The user seeks information in order to leave positive feedback.</reasoning>
465 <summary>The user seeks information in order to leave positive feedback.</summary>
463466 <intent>Support, Feedback, Complaint</intent>
464467
465468 Here are a few more examples:
from line 472
469472 <request>I wanted to write and personally thank you for the compassion you showed towards my family during my father's funeral this past weekend. Your staff was so considerate and helpful throughout this whole process; it really took a load off our shoulders. The visitation brochures were beautiful. We'll never forget the kindness you showed us and we are so appreciative of how smoothly the proceedings went. Thank you, again, Amarantha Hill on behalf of the Hill Family.</request>
470473
471474 Example 2 Output:
472 <reasoning>User leaves a positive review of their experience.</reasoning>
475 <summary>User leaves a positive review of their experience.</summary>
473476 <intent>Support, Feedback, Complaint</intent>
474477 </example 2>
475478 <example 3>
from line 485
482485 <request>Your website keeps sending ad-popups that block the entire screen. It took me twenty minutes just to finally find the phone number to call and complain. How can I possibly access my account information with all of these popups? Can you access my account for me, since your website is broken? I need to know what the address is on file.</request>
483486
484487 Example 9 Output:
485 <reasoning>The user requests help accessing their web account information.</reasoning>
488 <summary>The user requests help accessing their web account information.</summary>
486489 <intent>Support, Feedback, Complaint</intent>
487490 </example 9>
488491
489 Remember to always include your classification reasoning before your actual intent output. The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
492 Remember to always include your one-sentence summary before your intent output. The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
490493 `
491494 // ...
492495 }
from line 499
496499 void classifySupportRequest(String ticketContents) {
497500 // Define the prompt for the classification task
498501 String classificationPrompt = """
499 You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with your reasoning.
502 You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with a one-sentence summary of the request.
500503
501504 Here is the customer support request you need to classify:
502505
503506 <request>%s</request>
504507
505 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for has concerns about.
506
507 First, write out your reasoning and analysis of how to classify this request inside <reasoning> tags.
508
509 Then, output the appropriate classification label for the request inside a <intent> tag. The valid intents are:
508 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for or has concerns about.
509
510 First, write a one-sentence summary of the request inside <summary> tags.
511
512 Then, output the appropriate classification label for the request inside an <intent> tag. The valid intents are:
510513 <intents>
511514 <intent>Support, Feedback, Complaint</intent>
512515 <intent>Order Tracking</intent>
from line 522
519522 <request>Hello! I had high-speed fiber internet installed on Saturday and my installer, Kevin, was absolutely fantastic! Where can I send my positive review? Thanks for your help!</request>
520523
521524 Here is an example of how your output should be formatted (for the above example request):
522 <reasoning>The user seeks information in order to leave positive feedback.</reasoning>
525 <summary>The user seeks information in order to leave positive feedback.</summary>
523526 <intent>Support, Feedback, Complaint</intent>
524527
525528 Here are a few more examples:
from line 532
529532 <request>I wanted to write and personally thank you for the compassion you showed towards my family during my father's funeral this past weekend. Your staff was so considerate and helpful throughout this whole process; it really took a load off our shoulders. The visitation brochures were beautiful. We'll never forget the kindness you showed us and we are so appreciative of how smoothly the proceedings went. Thank you, again, Amarantha Hill on behalf of the Hill Family.</request>
530533
531534 Example 2 Output:
532 <reasoning>User leaves a positive review of their experience.</reasoning>
535 <summary>User leaves a positive review of their experience.</summary>
533536 <intent>Support, Feedback, Complaint</intent>
534537 </example 2>
535538 <example 3>
from line 545
542545 <request>Your website keeps sending ad-popups that block the entire screen. It took me twenty minutes just to finally find the phone number to call and complain. How can I possibly access my account information with all of these popups? Can you access my account for me, since your website is broken? I need to know what the address is on file.</request>
543546
544547 Example 9 Output:
545 <reasoning>The user requests help accessing their web account information.</reasoning>
548 <summary>The user requests help accessing their web account information.</summary>
546549 <intent>Support, Feedback, Complaint</intent>
547550 </example 9>
548551
549 Remember to always include your classification reasoning before your actual intent output. The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
552 Remember to always include your one-sentence summary before your intent output. The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
550553 """.formatted(ticketContents);
551554 }
552555 ```
from line 559
556559 {
557560 // Define the prompt for the classification task
558561 $classificationPrompt = <<<PROMPT
559 You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with your reasoning.
562 You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with a one-sentence summary of the request.
560563
561564 Here is the customer support request you need to classify:
562565
563566 <request>{$ticketContents}</request>
564567
565 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for has concerns about.
566
567 First, write out your reasoning and analysis of how to classify this request inside <reasoning> tags.
568
569 Then, output the appropriate classification label for the request inside a <intent> tag. The valid intents are:
568 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for or has concerns about.
569
570 First, write a one-sentence summary of the request inside <summary> tags.
571
572 Then, output the appropriate classification label for the request inside an <intent> tag. The valid intents are:
570573 <intents>
571574 <intent>Support, Feedback, Complaint</intent>
572575 <intent>Order Tracking</intent>
from line 582
579582 <request>Hello! I had high-speed fiber internet installed on Saturday and my installer, Kevin, was absolutely fantastic! Where can I send my positive review? Thanks for your help!</request>
580583
581584 Here is an example of how your output should be formatted (for the above example request):
582 <reasoning>The user seeks information in order to leave positive feedback.</reasoning>
585 <summary>The user seeks information in order to leave positive feedback.</summary>
583586 <intent>Support, Feedback, Complaint</intent>
584587
585588 Here are a few more examples:
from line 592
589592 <request>I wanted to write and personally thank you for the compassion you showed towards my family during my father's funeral this past weekend. Your staff was so considerate and helpful throughout this whole process; it really took a load off our shoulders. The visitation brochures were beautiful. We'll never forget the kindness you showed us and we are so appreciative of how smoothly the proceedings went. Thank you, again, Amarantha Hill on behalf of the Hill Family.</request>
590593
591594 Example 2 Output:
592 <reasoning>User leaves a positive review of their experience.</reasoning>
595 <summary>User leaves a positive review of their experience.</summary>
593596 <intent>Support, Feedback, Complaint</intent>
594597 </example 2>
595598 <example 3>
from line 605
602605 <request>Your website keeps sending ad-popups that block the entire screen. It took me twenty minutes just to finally find the phone number to call and complain. How can I possibly access my account information with all of these popups? Can you access my account for me, since your website is broken? I need to know what the address is on file.</request>
603606
604607 Example 9 Output:
605 <reasoning>The user requests help accessing their web account information.</reasoning>
608 <summary>The user requests help accessing their web account information.</summary>
606609 <intent>Support, Feedback, Complaint</intent>
607610 </example 9>
608611
609 Remember to always include your classification reasoning before your actual intent output. The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
612 Remember to always include your one-sentence summary before your intent output. The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
610613 PROMPT;
611614 }
612615 ```
from line 618
615618 def classify_support_request(ticket_contents)
616619 # Define the prompt for the classification task
617620 classification_prompt = <<~PROMPT
618 You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with your reasoning.
621 You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with a one-sentence summary of the request.
619622
620623 Here is the customer support request you need to classify:
621624
622625 <request>#{ticket_contents}</request>
623626
624 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for has concerns about.
625
626 First, write out your reasoning and analysis of how to classify this request inside <reasoning> tags.
627
628 Then, output the appropriate classification label for the request inside a <intent> tag. The valid intents are:
627 Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for or has concerns about.
628
629 First, write a one-sentence summary of the request inside <summary> tags.
630
631 Then, output the appropriate classification label for the request inside an <intent> tag. The valid intents are:
629632 <intents>
630633 <intent>Support, Feedback, Complaint</intent>
631634 <intent>Order Tracking</intent>
from line 641
638641 <request>Hello! I had high-speed fiber internet installed on Saturday and my installer, Kevin, was absolutely fantastic! Where can I send my positive review? Thanks for your help!</request>
639642
640643 Here is an example of how your output should be formatted (for the above example request):
641 <reasoning>The user seeks information in order to leave positive feedback.</reasoning>
644 <summary>The user seeks information in order to leave positive feedback.</summary>
642645 <intent>Support, Feedback, Complaint</intent>
643646
644647 Here are a few more examples:
from line 651
648651 <request>I wanted to write and personally thank you for the compassion you showed towards my family during my father's funeral this past weekend. Your staff was so considerate and helpful throughout this whole process; it really took a load off our shoulders. The visitation brochures were beautiful. We'll never forget the kindness you showed us and we are so appreciative of how smoothly the proceedings went. Thank you, again, Amarantha Hill on behalf of the Hill Family.</request>
649652
650653 Example 2 Output:
651 <reasoning>User leaves a positive review of their experience.</reasoning>
654 <summary>User leaves a positive review of their experience.</summary>
652655 <intent>Support, Feedback, Complaint</intent>
653656 </example 2>
654657 <example 3>
from line 664
661664 <request>Your website keeps sending ad-popups that block the entire screen. It took me twenty minutes just to finally find the phone number to call and complain. How can I possibly access my account information with all of these popups? Can you access my account for me, since your website is broken? I need to know what the address is on file.</request>
662665
663666 Example 9 Output:
664 <reasoning>The user requests help accessing their web account information.</reasoning>
667 <summary>The user requests help accessing their web account information.</summary>
665668 <intent>Support, Feedback, Complaint</intent>
666669 </example 9>
667670
668 Remember to always include your classification reasoning before your actual intent output. The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
671 Remember to always include your one-sentence summary before your intent output. The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
669672 PROMPT
670673 end
671674 ```
672675</CodeGroup>
673676
674<Note>
675 This prompt is written for Claude Haiku 5.5, which runs here at `low` effort. On Claude Fable 5.2, Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, and Claude Sonnet 5.5, ask for the intent and a one-sentence summary of the request instead. See [Keep reasoning in thinking blocks](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks).
676</Note>
677
678677Here are the key components of this prompt:
679678
680679* The prompt template inserts `ticket_contents` (typescript, csharp, go, java: `ticketContents`; php: `$ticketContents`) into the `<request>` tags.
681680* The prompt gives Claude a clearly defined role as a classification system that carefully analyzes the ticket content to determine the customer’s core intent and needs.
682* The prompt instructs Claude on proper output formatting, in this case to provide its reasoning and analysis inside `<reasoning>` tags, followed by the appropriate classification label inside `<intent>` tags.
681* The prompt tells Claude how to format its output: a one-sentence summary of the request inside `<summary>` tags, followed by the classification label inside `<intent>` tags.
683682* The prompt specifies the valid intent categories: `Support, Feedback, Complaint`, `Order Tracking`, and `Refund/Exchange`.
684683* The prompt includes a few examples (a.k.a. few-shot prompting) to illustrate how the output should be formatted, which improves accuracy and consistency.
685684
686Having Claude split its response into separate XML tag sections lets you use regular expressions to extract the reasoning and intent from the output independently. This lets you create targeted next steps in the ticket routing workflow, such as using only the intent to decide which person to route the ticket to.
685Because each part of the response sits in its own XML tags, you can use regular expressions to extract the summary and the intent separately. Then, you can act on each part on its own, such as using only the intent to decide who gets the ticket.
686
687The prompt asks for a summary of the request rather than Claude’s reasoning. [Some Claude models](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks) might decline a prompt that asks them to write their reasoning. You can still ask for a short explanation of a classification. To see a summary of how Claude reached it, set `thinking: {"type": "adaptive", "display": "summarized"}` and read the response’s [`thinking` blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#summarized-thinking). Claude can skip thinking on a simple ticket, so some responses have no `thinking` block.
687688
688689### Deploy your prompt
689690
690691It’s hard to know how well your prompt works without deploying it in a test production setting and [running evaluations](https://platform.claude.com/docs/en/test-and-evaluate/develop-tests).
691692
692Build the deployment structure. Start by defining the function signature for wrapping the call to Claude. Extend the function you started writing earlier, which takes `ticket_contents` (typescript, csharp, go, java: `ticketContents`; php: `$ticketContents`) as input, so that it now returns the reasoning and the intent as output. If you have an existing automation using traditional ML, you’ll want to follow that signature instead.
693Build the deployment structure. Start by defining the function signature for wrapping the call to Claude. Extend the function you started writing earlier, which takes `ticket_contents` (typescript, csharp, go, java: `ticketContents`; php: `$ticketContents`) as input, so that it now returns the summary and the intent. If you have an existing automation that uses traditional ML, follow its signature instead.
693694
694695<CodeGroup exclude="shell">
695696 <CodeGroupItem language="cURL">
from line 715
714715 # Define the prompt for the classification task
715716 classification_prompt = f"""You will be acting as a customer support ticket classification system.
716717 […]
717 ... The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
718 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
718719 """
719720 # Send the prompt to the API to classify the support request.
720721 message = client.messages.create(
from line 725
724725 messages=[{"role": "user", "content": classification_prompt}],
725726 stream=False,
726727 )
727 reasoning_and_intent = next(
728 if message.stop_reason == "refusal":
729 raise RuntimeError("Claude declined to classify this ticket.")
730 summary_and_intent = next(
728731 (block.text for block in message.content if block.type == "text"), ""
729732 )
730733
731 # Use Python's regular expressions library to extract `reasoning`.
732 reasoning_match = re.search(
733 r"<reasoning>(.*?)</reasoning>", reasoning_and_intent, re.DOTALL
734 # Use Python's regular expressions library to extract `summary`.
735 summary_match = re.search(
736 r"<summary>(.*?)</summary>", summary_and_intent, re.DOTALL
734737 )
735 reasoning = reasoning_match.group(1).strip() if reasoning_match else ""
738 summary = summary_match.group(1).strip() if summary_match else ""
736739
737740 # Similarly, also extract the `intent`.
738 intent_match = re.search(r"<intent>(.*?)</intent>", reasoning_and_intent, re.DOTALL)
741 intent_match = re.search(r"<intent>(.*?)</intent>", summary_and_intent, re.DOTALL)
739742 intent = intent_match.group(1).strip() if intent_match else ""
740743
741 return reasoning, intent
744 return summary, intent
742745 ```
743746
744747 ```typescript TypeScript
from line 753
750753
751754 async function classifySupportRequest(
752755 ticketContents: string
753 ): Promise<{ reasoning: string; intent: string }> {
756 ): Promise<{ summary: string; intent: string }> {
754757 // Define the prompt for the classification task
755758 const classificationPrompt = `You will be acting as a customer support ticket classification system.
756759 […]
757 ... The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
760 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
758761 `;
759762 // Send the prompt to the API to classify the support request.
760763 const message = await client.messages.create({
from line 766
763766 output_config: { effort: "low" },
764767 messages: [{ role: "user", content: classificationPrompt }]
765768 });
769 if (message.stop_reason === "refusal") {
770 throw new Error("Claude declined to classify this ticket.");
771 }
766772 const textBlock = message.content.find((block) => block.type === "text");
767 const reasoningAndIntent = textBlock?.text ?? "";
768
769 // Use a regular expression to extract `reasoning`.
770 const reasoningMatch = /<reasoning>(.*?)<\/reasoning>/s.exec(reasoningAndIntent);
771 const reasoning = reasoningMatch?.[1].trim() ?? "";
773 const summaryAndIntent = textBlock?.text ?? "";
774
775 // Use a regular expression to extract `summary`.
776 const summaryMatch = /<summary>(.*?)<\/summary>/s.exec(summaryAndIntent);
777 const summary = summaryMatch?.[1].trim() ?? "";
772778
773779 // Similarly, also extract the `intent`.
774 const intentMatch = /<intent>(.*?)<\/intent>/s.exec(reasoningAndIntent);
780 const intentMatch = /<intent>(.*?)<\/intent>/s.exec(summaryAndIntent);
775781 const intent = intentMatch?.[1].trim() ?? "";
776782
777 return { reasoning, intent };
783 return { summary, intent };
778784 }
779785 ```
780786
from line 794
788794 // Set the default model
789795 const Model DefaultModel = Model.ClaudeHaiku5_5;
790796
791 async Task<(string Reasoning, string Intent)> ClassifySupportRequest(string ticketContents)
797 async Task<(string Summary, string Intent)> ClassifySupportRequest(string ticketContents)
792798 {
793799 // Define the prompt for the classification task
794800 var classificationPrompt = """
795801 You will be acting as a customer support ticket classification system.
796802 […]
797 ... The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
803 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
798804 """;
799805 // Send the prompt to the API to classify the support request.
800806 var message = await client.Messages.Create(new MessageCreateParams
from line 810
804810 OutputConfig = new OutputConfig { Effort = Effort.Low },
805811 Messages = [new UserMessageParam { Content = classificationPrompt }],
806812 });
807 var reasoningAndIntent = "";
813 if (message.StopReason?.Value() == StopReason.Refusal)
814 {
815 throw new InvalidOperationException("Claude declined to classify this ticket.");
816 }
817 var summaryAndIntent = "";
808818 foreach (var block in message.Content)
809819 {
810820 if (block.TryPickText(out var textBlock))
811821 {
812 reasoningAndIntent = textBlock.Text;
822 summaryAndIntent = textBlock.Text;
813823 break;
814824 }
815825 }
816826
817 // Use a regular expression to extract `reasoning`.
818 var reasoningMatch = Regex.Match(reasoningAndIntent, "<reasoning>(.*?)</reasoning>", RegexOptions.Singleline);
819 var reasoning = reasoningMatch.Success ? reasoningMatch.Groups[1].Value.Trim() : "";
827 // Use a regular expression to extract `summary`.
828 var summaryMatch = Regex.Match(summaryAndIntent, "<summary>(.*?)</summary>", RegexOptions.Singleline);
829 var summary = summaryMatch.Success ? summaryMatch.Groups[1].Value.Trim() : "";
820830
821831 // Similarly, also extract the `intent`.
822 var intentMatch = Regex.Match(reasoningAndIntent, "<intent>(.*?)</intent>", RegexOptions.Singleline);
832 var intentMatch = Regex.Match(summaryAndIntent, "<intent>(.*?)</intent>", RegexOptions.Singleline);
823833 var intent = intentMatch.Success ? intentMatch.Groups[1].Value.Trim() : "";
824834
825 return (reasoning, intent);
835 return (summary, intent);
826836 }
827837 ```
828838
829839 ```go Go
830840 import (
831841 "context"
842 "errors"
832843 "regexp"
833844 "strings"
834845 // ...
from line 851
840851 // Set the default model
841852 const defaultModel = anthropic.ModelClaudeHaiku5_5
842853
843 func classifySupportRequest(ctx context.Context, ticketContents string) (reasoning, intent string, err error) {
854 func classifySupportRequest(ctx context.Context, ticketContents string) (summary, intent string, err error) {
844855 // Define the prompt for the classification task
845856 classificationPrompt := `You will be acting as a customer support ticket classification system.
846857 […]
847 ... The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
858 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
848859 `
849860 // Send the prompt to the API to classify the support request.
850861 message, err := client.Messages.New(ctx, anthropic.MessageNewParams{
from line 869
858869 if err != nil {
859870 return "", "", err
860871 }
861 var reasoningAndIntent string
872 if message.StopReason == anthropic.StopReasonRefusal {
873 return "", "", errors.New("Claude declined to classify this ticket")
874 }
875 var summaryAndIntent string
862876 for _, block := range message.Content {
863877 if textBlock, ok := block.AsAny().(anthropic.TextBlock); ok {
864 reasoningAndIntent = textBlock.Text
878 summaryAndIntent = textBlock.Text
865879 break
866880 }
867881 }
868882
869 // Use a regular expression to extract `reasoning`.
870 reasoningMatch := regexp.MustCompile(`(?s)<reasoning>(.*?)</reasoning>`).FindStringSubmatch(reasoningAndIntent)
871 if reasoningMatch != nil {
872 reasoning = strings.TrimSpace(reasoningMatch[1])
883 // Use a regular expression to extract `summary`.
884 summaryMatch := regexp.MustCompile(`(?s)<summary>(.*?)</summary>`).FindStringSubmatch(summaryAndIntent)
885 if summaryMatch != nil {
886 summary = strings.TrimSpace(summaryMatch[1])
873887 }
874888
875889 // Similarly, also extract the `intent`.
876 intentMatch := regexp.MustCompile(`(?s)<intent>(.*?)</intent>`).FindStringSubmatch(reasoningAndIntent)
890 intentMatch := regexp.MustCompile(`(?s)<intent>(.*?)</intent>`).FindStringSubmatch(summaryAndIntent)
877891 if intentMatch != nil {
878892 intent = strings.TrimSpace(intentMatch[1])
879893 }
880894
881 return reasoning, intent, nil
895 return summary, intent, nil
882896 }
883897 ```
884898
from line 906
892906 // Set the default model
893907 static final Model DEFAULT_MODEL = Model.CLAUDE_HAIKU_5_5;
894908
895 record Classification(String reasoning, String intent) {}
909 record Classification(String summary, String intent) {}
896910
897911 Classification classifySupportRequest(String ticketContents) {
898912 // Define the prompt for the classification task
899913 String classificationPrompt = """
900914 You will be acting as a customer support ticket classification system.
901915 […]
902 ... The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
916 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
903917 """;
904918 // Send the prompt to the API to classify the support request.
905919 Message message = client.messages().create(MessageCreateParams.builder()
from line 924
910924 .build())
911925 .addUserMessage(classificationPrompt)
912926 .build());
913 String reasoningAndIntent = message.content().stream()
927 if (message.stopReason().filter(StopReason.REFUSAL::equals).isPresent()) {
928 throw new IllegalStateException("Claude declined to classify this ticket.");
929 }
930 String summaryAndIntent = message.content().stream()
914931 .flatMap(block -> block.text().stream())
915932 .map(textBlock -> textBlock.text())
916933 .findFirst()
917934 .orElse("");
918935
919 // Use a regular expression to extract `reasoning`.
920 Matcher reasoningMatch = Pattern.compile("<reasoning>(.*?)</reasoning>", Pattern.DOTALL)
921 .matcher(reasoningAndIntent);
922 String reasoning = reasoningMatch.find() ? reasoningMatch.group(1).strip() : "";
936 // Use a regular expression to extract `summary`.
937 Matcher summaryMatch = Pattern.compile("<summary>(.*?)</summary>", Pattern.DOTALL)
938 .matcher(summaryAndIntent);
939 String summary = summaryMatch.find() ? summaryMatch.group(1).strip() : "";
923940
924941 // Similarly, also extract the `intent`.
925942 Matcher intentMatch = Pattern.compile("<intent>(.*?)</intent>", Pattern.DOTALL)
926 .matcher(reasoningAndIntent);
943 .matcher(summaryAndIntent);
927944 String intent = intentMatch.find() ? intentMatch.group(1).strip() : "";
928945
929 return new Classification(reasoning, intent);
946 return new Classification(summary, intent);
930947 }
931948 ```
932949
from line 955
938955 const DEFAULT_MODEL = Model::CLAUDE_HAIKU_5_5;
939956
940957 /**
941 * @return array{string, string} the reasoning and the intent
958 * @return array{string, string} the summary and the intent
942959 */
943960 function classifySupportRequest(Client $client, string $ticketContents): array
944961 {
from line 963
946963 $classificationPrompt = <<<PROMPT
947964 You will be acting as a customer support ticket classification system.
948965 […]
949 ... The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
966 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
950967 PROMPT;
951968 // Send the prompt to the API to classify the support request.
952969 $message = $client->messages->create(
from line 972
955972 outputConfig: ['effort' => 'low'],
956973 messages: [['role' => 'user', 'content' => $classificationPrompt]],
957974 );
958 $reasoningAndIntent = '';
975 if ($message->stopReason === 'refusal') {
976 throw new \RuntimeException('Claude declined to classify this ticket.');
977 }
978 $summaryAndIntent = '';
959979 foreach ($message->content as $block) {
960980 if ($block instanceof \Anthropic\Messages\TextBlock) {
961 $reasoningAndIntent = $block->text;
981 $summaryAndIntent = $block->text;
962982 break;
963983 }
964984 }
965985
966 // Use a regular expression to extract `reasoning`.
967 $reasoning = preg_match('/<reasoning>(.*?)<\/reasoning>/s', $reasoningAndIntent, $reasoningMatch)
968 ? trim($reasoningMatch[1])
986 // Use a regular expression to extract `summary`.
987 $summary = preg_match('/<summary>(.*?)<\/summary>/s', $summaryAndIntent, $summaryMatch)
988 ? trim($summaryMatch[1])
969989 : '';
970990
971991 // Similarly, also extract the `intent`.
972 $intent = preg_match('/<intent>(.*?)<\/intent>/s', $reasoningAndIntent, $intentMatch)
992 $intent = preg_match('/<intent>(.*?)<\/intent>/s', $summaryAndIntent, $intentMatch)
973993 ? trim($intentMatch[1])
974994 : '';
975995
976 return [$reasoning, $intent];
996 return [$summary, $intent];
977997 }
978998 ```
979999
from line 1009
9891009 classification_prompt = <<~PROMPT
9901010 You will be acting as a customer support ticket classification system.
9911011 […]
992 ... The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
1012 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
9931013 PROMPT
9941014 # Send the prompt to the API to classify the support request.
9951015 message = client.messages.create(
from line 1018
9981018 output_config: { effort: "low" },
9991019 messages: [{ role: "user", content: classification_prompt }]
10001020 )
1001 reasoning_and_intent = message.content.grep(Anthropic::Models::TextBlock).first&.text || ""
1002
1003 # Use a regular expression to extract `reasoning`.
1004 reasoning = reasoning_and_intent[%r{<reasoning>(.*?)</reasoning>}m, 1]&.strip || ""
1021 raise "Claude declined to classify this ticket." if message.stop_reason == :refusal
1022 summary_and_intent = message.content.grep(Anthropic::Models::TextBlock).first&.text || ""
1023
1024 # Use a regular expression to extract `summary`.
1025 summary = summary_and_intent[%r{<summary>(.*?)</summary>}m, 1]&.strip || ""
10051026
10061027 # Similarly, also extract the `intent`.
1007 intent = reasoning_and_intent[%r{<intent>(.*?)</intent>}m, 1]&.strip || ""
1008
1009 [reasoning, intent]
1028 intent = summary_and_intent[%r{<intent>(.*?)</intent>}m, 1]&.strip || ""
1029
1030 [summary, intent]
10101031 end
10111032 ```
10121033</CodeGroup>
10131034
10141035This code:
10151036
1016* Creates a client instance using your API key.
1037* Creates a client instance.
10171038* Defines a `classify_support_request()` (typescript, go, java, php: `classifySupportRequest()`; csharp: `ClassifySupportRequest()`) function that takes a `ticket_contents` (typescript, csharp, go, java: `ticketContents`; php: `$ticketContents`) string.
10181039* Sends the `ticket_contents` (typescript, csharp, go, java: `ticketContents`; php: `$ticketContents`) to Claude for classification using the `classification_prompt` (typescript, csharp, go, java: `classificationPrompt`; php: `$classificationPrompt`).
1019* Returns the model’s reasoning and intent extracted from the response.
1020
1021Because the entire reasoning and intent text must be generated before parsing, the example does not stream the response.
1040* Stops with an error if Claude [declines the request](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback), because a declined response has no complete text to parse.
1041* Returns the summary and the intent extracted from the response.
1042
1043The code parses the whole response at once, so the example doesn’t stream the response.
10221044
10231045***
10241046
from line 1084
10621084 # Define the prompt for the classification task
10631085 classification_prompt = f"""You will be acting as a customer support ticket classification system.
10641086 […]
1065 ...The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
1087 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
10661088 """
10671089
10681090 message = client.messages.create(
from line 1094
10721094 messages=[{"role": "user", "content": classification_prompt}],
10731095 )
10741096 usage = message.usage # Get the usage statistics for the API call for how many input and output tokens were used.
1075 reasoning_and_intent = next(
1097 if message.stop_reason == "refusal":
1098 return "", "", False, usage
1099 summary_and_intent = next(
10761100 (block.text for block in message.content if block.type == "text"), ""
10771101 )
10781102
1079 # Use Python's regular expressions library to extract `reasoning`.
1080 reasoning_match = re.search(
1081 r"<reasoning>(.*?)</reasoning>", reasoning_and_intent, re.DOTALL
1103 # Use Python's regular expressions library to extract `summary`.
1104 summary_match = re.search(
1105 r"<summary>(.*?)</summary>", summary_and_intent, re.DOTALL
10821106 )
1083 reasoning = reasoning_match.group(1).strip() if reasoning_match else ""
1107 summary = summary_match.group(1).strip() if summary_match else ""
10841108
10851109 # Similarly, also extract the `intent`.
1086 intent_match = re.search(r"<intent>(.*?)</intent>", reasoning_and_intent, re.DOTALL)
1110 intent_match = re.search(r"<intent>(.*?)</intent>", summary_and_intent, re.DOTALL)
10871111 intent = intent_match.group(1).strip() if intent_match else ""
10881112
10891113 # Check if the model's prediction is correct.
10901114 correct = actual_intent.strip() == intent.strip()
10911115
1092 # Return the reasoning, intent, correct, and usage.
1093 return reasoning, intent, correct, usage
1116 # Return the summary, intent, correct, and usage.
1117 return summary, intent, correct, usage
10941118 ```
10951119
10961120 ```typescript TypeScript
from line 1127
11031127 async function classifySupportRequest(
11041128 ticketContents: string,
11051129 actualIntent: string
1106 ): Promise<{ reasoning: string; intent: string; correct: boolean; usage: Anthropic.Usage }> {
1130 ): Promise<{ summary: string; intent: string; correct: boolean; usage: Anthropic.Usage }> {
11071131 // Define the prompt for the classification task
11081132 const classificationPrompt = `You will be acting as a customer support ticket classification system.
11091133 […]
1110 ...The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
1134 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
11111135 `;
11121136
11131137 const message = await client.messages.create({
from line 1142
11181142 });
11191143 // Get the usage statistics for the API call for how many input and output tokens were used.
11201144 const usage = message.usage;
1145 if (message.stop_reason === "refusal") {
1146 return { summary: "", intent: "", correct: false, usage };
1147 }
11211148 const textBlock = message.content.find((block) => block.type === "text");
1122 const reasoningAndIntent = textBlock?.text ?? "";
1123
1124 // Use a regular expression to extract `reasoning`.
1125 const reasoningMatch = /<reasoning>(.*?)<\/reasoning>/s.exec(reasoningAndIntent);
1126 const reasoning = reasoningMatch?.[1].trim() ?? "";
1149 const summaryAndIntent = textBlock?.text ?? "";
1150
1151 // Use a regular expression to extract `summary`.
1152 const summaryMatch = /<summary>(.*?)<\/summary>/s.exec(summaryAndIntent);
1153 const summary = summaryMatch?.[1].trim() ?? "";
11271154
11281155 // Similarly, also extract the `intent`.
1129 const intentMatch = /<intent>(.*?)<\/intent>/s.exec(reasoningAndIntent);
1156 const intentMatch = /<intent>(.*?)<\/intent>/s.exec(summaryAndIntent);
11301157 const intent = intentMatch?.[1].trim() ?? "";
11311158
11321159 // Check if the model's prediction is correct.
11331160 const correct = actualIntent.trim() === intent.trim();
11341161
1135 // Return the reasoning, intent, correct, and usage.
1136 return { reasoning, intent, correct, usage };
1162 // Return the summary, intent, correct, and usage.
1163 return { summary, intent, correct, usage };
11371164 }
11381165 ```
11391166
from line 1174
11471174 // Set the default model
11481175 const Model DefaultModel = Model.ClaudeHaiku5_5;
11491176
1150 async Task<(string Reasoning, string Intent, bool Correct, Usage Usage)> ClassifySupportRequest(string ticketContents, string actualIntent)
1177 async Task<(string Summary, string Intent, bool Correct, Usage Usage)> ClassifySupportRequest(string ticketContents, string actualIntent)
11511178 {
11521179 // Define the prompt for the classification task
11531180 var classificationPrompt = """
11541181 You will be acting as a customer support ticket classification system.
11551182 […]
1156 ...The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
1183 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
11571184 """;
11581185
11591186 var message = await client.Messages.Create(new MessageCreateParams
from line 1192
11651192 });
11661193 // Get the usage statistics for the API call for how many input and output tokens were used.
11671194 var usage = message.Usage;
1168 var reasoningAndIntent = "";
1195 if (message.StopReason?.Value() == StopReason.Refusal)
1196 {
1197 return ("", "", false, usage);
1198 }
1199 var summaryAndIntent = "";
11691200 foreach (var block in message.Content)
11701201 {
11711202 if (block.TryPickText(out var textBlock))
11721203 {
1173 reasoningAndIntent = textBlock.Text;
1204 summaryAndIntent = textBlock.Text;
11741205 break;
11751206 }
11761207 }
11771208
1178 // Use a regular expression to extract `reasoning`.
1179 var reasoningMatch = Regex.Match(reasoningAndIntent, "<reasoning>(.*?)</reasoning>", RegexOptions.Singleline);
1180 var reasoning = reasoningMatch.Success ? reasoningMatch.Groups[1].Value.Trim() : "";
1209 // Use a regular expression to extract `summary`.
1210 var summaryMatch = Regex.Match(summaryAndIntent, "<summary>(.*?)</summary>", RegexOptions.Singleline);
1211 var summary = summaryMatch.Success ? summaryMatch.Groups[1].Value.Trim() : "";
11811212
11821213 // Similarly, also extract the `intent`.
1183 var intentMatch = Regex.Match(reasoningAndIntent, "<intent>(.*?)</intent>", RegexOptions.Singleline);
1214 var intentMatch = Regex.Match(summaryAndIntent, "<intent>(.*?)</intent>", RegexOptions.Singleline);
11841215 var intent = intentMatch.Success ? intentMatch.Groups[1].Value.Trim() : "";
11851216
11861217 // Check if the model's prediction is correct.
11871218 var correct = actualIntent.Trim() == intent.Trim();
11881219
1189 // Return the reasoning, intent, correct, and usage.
1190 return (reasoning, intent, correct, usage);
1220 // Return the summary, intent, correct, and usage.
1221 return (summary, intent, correct, usage);
11911222 }
11921223 ```
11931224
from line 1236
12051236 // Set the default model
12061237 const defaultModel = anthropic.ModelClaudeHaiku5_5
12071238
1208 func classifySupportRequest(ctx context.Context, ticketContents, actualIntent string) (reasoning, intent string, correct bool, usage anthropic.Usage, err error) {
1239 func classifySupportRequest(ctx context.Context, ticketContents, actualIntent string) (summary, intent string, correct bool, usage anthropic.Usage, err error) {
12091240 // Define the prompt for the classification task
12101241 classificationPrompt := `You will be acting as a customer support ticket classification system.
12111242 […]
1212 ...The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
1243 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
12131244 `
12141245 message, err := client.Messages.New(ctx, anthropic.MessageNewParams{
12151246 Model: defaultModel,
from line 1255
12241255 }
12251256 // Get the usage statistics for the API call for how many input and output tokens were used.
12261257 usage = message.Usage
1227 var reasoningAndIntent string
1258 if message.StopReason == anthropic.StopReasonRefusal {
1259 return "", "", false, usage, nil
1260 }
1261 var summaryAndIntent string
12281262 for _, block := range message.Content {
12291263 if textBlock, ok := block.AsAny().(anthropic.TextBlock); ok {
1230 reasoningAndIntent = textBlock.Text
1264 summaryAndIntent = textBlock.Text
12311265 break
12321266 }
12331267 }
12341268
1235 // Use a regular expression to extract `reasoning`.
1236 reasoningMatch := regexp.MustCompile(`(?s)<reasoning>(.*?)</reasoning>`).FindStringSubmatch(reasoningAndIntent)
1237 if reasoningMatch != nil {
1238 reasoning = strings.TrimSpace(reasoningMatch[1])
1269 // Use a regular expression to extract `summary`.
1270 summaryMatch := regexp.MustCompile(`(?s)<summary>(.*?)</summary>`).FindStringSubmatch(summaryAndIntent)
1271 if summaryMatch != nil {
1272 summary = strings.TrimSpace(summaryMatch[1])
12391273 }
12401274
12411275 // Similarly, also extract the `intent`.
1242 intentMatch := regexp.MustCompile(`(?s)<intent>(.*?)</intent>`).FindStringSubmatch(reasoningAndIntent)
1276 intentMatch := regexp.MustCompile(`(?s)<intent>(.*?)</intent>`).FindStringSubmatch(summaryAndIntent)
12431277 if intentMatch != nil {
12441278 intent = strings.TrimSpace(intentMatch[1])
12451279 }
from line 1281
12471281 // Check if the model's prediction is correct.
12481282 correct = strings.TrimSpace(actualIntent) == strings.TrimSpace(intent)
12491283
1250 // Return the reasoning, intent, correct, and usage.
1251 return reasoning, intent, correct, usage, nil
1284 // Return the summary, intent, correct, and usage.
1285 return summary, intent, correct, usage, nil
12521286 }
12531287 ```
12541288
from line 1296
12621296 // Set the default model
12631297 static final Model DEFAULT_MODEL = Model.CLAUDE_HAIKU_5_5;
12641298
1265 record Classification(String reasoning, String intent, boolean correct, Usage usage) {}
1299 record Classification(String summary, String intent, boolean correct, Usage usage) {}
12661300
12671301 Classification classifySupportRequest(String ticketContents, String actualIntent) {
12681302 // Define the prompt for the classification task
12691303 String classificationPrompt = """
12701304 You will be acting as a customer support ticket classification system.
12711305 […]
1272 ...The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
1306 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
12731307 """;
12741308
12751309 Message message = client.messages().create(MessageCreateParams.builder()
from line 1316
12821316 .build());
12831317 // Get the usage statistics for the API call for how many input and output tokens were used.
12841318 Usage usage = message.usage();
1285 String reasoningAndIntent = message.content().stream()
1319 if (message.stopReason().filter(StopReason.REFUSAL::equals).isPresent()) {
1320 return new Classification("", "", false, usage);
1321 }
1322 String summaryAndIntent = message.content().stream()
12861323 .flatMap(block -> block.text().stream())
12871324 .map(textBlock -> textBlock.text())
12881325 .findFirst()
12891326 .orElse("");
12901327
1291 // Use a regular expression to extract `reasoning`.
1292 Matcher reasoningMatch = Pattern.compile("<reasoning>(.*?)</reasoning>", Pattern.DOTALL)
1293 .matcher(reasoningAndIntent);
1294 String reasoning = reasoningMatch.find() ? reasoningMatch.group(1).strip() : "";
1328 // Use a regular expression to extract `summary`.
1329 Matcher summaryMatch = Pattern.compile("<summary>(.*?)</summary>", Pattern.DOTALL)
1330 .matcher(summaryAndIntent);
1331 String summary = summaryMatch.find() ? summaryMatch.group(1).strip() : "";
12951332
12961333 // Similarly, also extract the `intent`.
12971334 Matcher intentMatch = Pattern.compile("<intent>(.*?)</intent>", Pattern.DOTALL)
1298 .matcher(reasoningAndIntent);
1335 .matcher(summaryAndIntent);
12991336 String intent = intentMatch.find() ? intentMatch.group(1).strip() : "";
13001337
13011338 // Check if the model's prediction is correct.
13021339 boolean correct = actualIntent.strip().equals(intent.strip());
13031340
1304 // Return the reasoning, intent, correct, and usage.
1305 return new Classification(reasoning, intent, correct, usage);
1341 // Return the summary, intent, correct, and usage.
1342 return new Classification(summary, intent, correct, usage);
13061343 }
13071344 ```
13081345
from line 1351
13141351 const DEFAULT_MODEL = Model::CLAUDE_HAIKU_5_5;
13151352
13161353 /**
1317 * @return array{string, string, bool, Usage} the reasoning, the intent, whether the intent is correct, and the usage
1354 * @return array{string, string, bool, Usage} the summary, the intent, whether the intent is correct, and the usage
13181355 */
13191356 function classifySupportRequest(Client $client, string $ticketContents, string $actualIntent): array
13201357 {
from line 1359
13221359 $classificationPrompt = <<<PROMPT
13231360 You will be acting as a customer support ticket classification system.
13241361 […]
1325 ...The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
1362 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
13261363 PROMPT;
13271364
13281365 $message = $client->messages->create(
from line 1370
13331370 );
13341371 // Get the usage statistics for the API call for how many input and output tokens were used.
13351372 $usage = $message->usage;
1336 $reasoningAndIntent = '';
1373 if ($message->stopReason === 'refusal') {
1374 return ['', '', false, $usage];
1375 }
1376 $summaryAndIntent = '';
13371377 foreach ($message->content as $block) {
13381378 if ($block instanceof \Anthropic\Messages\TextBlock) {
1339 $reasoningAndIntent = $block->text;
1379 $summaryAndIntent = $block->text;
13401380 break;
13411381 }
13421382 }
13431383
1344 // Use a regular expression to extract `reasoning`.
1345 $reasoning = preg_match('/<reasoning>(.*?)<\/reasoning>/s', $reasoningAndIntent, $reasoningMatch)
1346 ? trim($reasoningMatch[1])
1384 // Use a regular expression to extract `summary`.
1385 $summary = preg_match('/<summary>(.*?)<\/summary>/s', $summaryAndIntent, $summaryMatch)
1386 ? trim($summaryMatch[1])
13471387 : '';
13481388
13491389 // Similarly, also extract the `intent`.
1350 $intent = preg_match('/<intent>(.*?)<\/intent>/s', $reasoningAndIntent, $intentMatch)
1390 $intent = preg_match('/<intent>(.*?)<\/intent>/s', $summaryAndIntent, $intentMatch)
13511391 ? trim($intentMatch[1])
13521392 : '';
13531393
13541394 // Check if the model's prediction is correct.
13551395 $correct = trim($actualIntent) === trim($intent);
13561396
1357 // Return the reasoning, intent, correct, and usage.
1358 return [$reasoning, $intent, $correct, $usage];
1397 // Return the summary, intent, correct, and usage.
1398 return [$summary, $intent, $correct, $usage];
13591399 }
13601400 ```
13611401
from line 1411
13711411 classification_prompt = <<~PROMPT
13721412 You will be acting as a customer support ticket classification system.
13731413 […]
1374 ...The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
1414 ... The summary should be enclosed in <summary> tags and the intent in <intent> tags. Return only the summary and the intent.
13751415 PROMPT
13761416
13771417 message = client.messages.create(
from line 1422
13821422 )
13831423 # Get the usage statistics for the API call for how many input and output tokens were used.
13841424 usage = message.usage
1385 reasoning_and_intent = message.content.grep(Anthropic::Models::TextBlock).first&.text || ""
1386
1387 # Use a regular expression to extract `reasoning`.
1388 reasoning = reasoning_and_intent[%r{<reasoning>(.*?)</reasoning>}m, 1]&.strip || ""
1425 return ["", "", false, usage] if message.stop_reason == :refusal
1426 summary_and_intent = message.content.grep(Anthropic::Models::TextBlock).first&.text || ""
1427
1428 # Use a regular expression to extract `summary`.
1429 summary = summary_and_intent[%r{<summary>(.*?)</summary>}m, 1]&.strip || ""
13891430
13901431 # Similarly, also extract the `intent`.
1391 intent = reasoning_and_intent[%r{<intent>(.*?)</intent>}m, 1]&.strip || ""
1432 intent = summary_and_intent[%r{<intent>(.*?)</intent>}m, 1]&.strip || ""
13921433
13931434 # Check if the model's prediction is correct.
13941435 correct = actual_intent.strip == intent.strip
13951436
1396 # Return the reasoning, intent, correct, and usage.
1397 [reasoning, intent, correct, usage]
1437 # Return the summary, intent, correct, and usage.
1438 [summary, intent, correct, usage]
13981439 end
13991440 ```
14001441</CodeGroup>
from line 1444
14031444
14041445* The `classify_support_request()` (typescript, go, java, php: `classifySupportRequest()`; csharp: `ClassifySupportRequest()`) function now takes the `actual_intent` (typescript, csharp, go, java: `actualIntent`; php: `$actualIntent`) from the test cases and compares it against Claude’s intent classification to assess whether they match.
14051446* The function extracts usage statistics for the API call to calculate cost based on input and output tokens used.
1447* A declined request counts as a wrong classification, so one refusal doesn’t stop the evaluation. The function still returns its usage, because [some refusals are billed](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#how-refusals-are-billed).
14061448
14071449### Run your evaluation
14081450
14091451A proper evaluation requires clear thresholds and benchmarks to determine what is a good result. The preceding script returns the values you need to measure accuracy and cost per classification, but you still need clearly established thresholds. For example:
14101452
1411* **Accuracy:** 95% (out of 100 tests)
1412* **Cost per classification:** 50% reduction on average (across 100 tests) from current routing method
1453* **Accuracy:** 95 percent (out of 100 tests)
1454* **Cost per classification:** 50 percent reduction on average (across 100 tests) from current routing method
14131455
14141456Having these thresholds allows you to tell at scale, and with impartial empiricism, what method is best for you and what changes you might need to make to better fit your requirements.
14151457
from line 1504
14621504
14631505### Use vector databases and similarity search retrieval to handle highly variable tickets
14641506
1465Despite providing examples being the most effective way to improve performance, if support requests are highly variable, it can be hard to include enough examples in a single prompt.
1507Examples are the most effective way to improve performance, but if support requests are highly variable, it can be hard to include enough of them in a single prompt.
14661508
14671509In this scenario, you could employ a vector database to do similarity searches from a dataset of examples and retrieve the most relevant examples for a given query.
14681510
from line 1518
14761518 <Accordion title="Customers make implicit requests">
14771519 Customers often express needs indirectly. For example, “I’ve been waiting for my package for over two weeks now” might be an indirect request for order status.
14781520
1479 * **Solution:** Provide Claude with some real customer examples of these kinds of requests, along with what the underlying intent is. You can get even better results if you include a classification rationale for particularly nuanced ticket intents, so that Claude can better generalize the logic to other tickets.
1521 * **Solution:** Provide Claude with some real customer examples of these kinds of requests, along with what the underlying intent is. For particularly nuanced intents, also say in the prompt what sets each one apart, so that Claude can apply the same distinction to other tickets.
14801522 </Accordion>
14811523
14821524 <Accordion title="Claude prioritizes emotion over intent">
14831525
No line in this hunk matches that.