One read of Claude Developer Platformapi-20261120T223715Z
13 pages moved out of 936 read.
Pages moved
13
significant first
Pages read
936
in this capture
Captured
22:37 UTC
Corpus hash
de09bf58781a
corpus-hash
What this read moved
1-13 of 13about-claude/use-case-guides/ticket-routing Changed · +263 / -221 lines
## Why use Claude for ticket routing ## Define whether to use Claude for ticket routing
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
build-with-claude/prompt-engineering/prompting-claude-haiku-5-5 Changed · +8 / -3 lines
from line 6
66
77This guide covers the prompting patterns specific to Claude Haiku 5.5. For the model’s API changes, see [What’s new in Claude Haiku 5.5](https://platform.claude.com/docs/en/models/haiku-5-5/whats-new-haiku-5-5). For techniques that apply across all current Claude models, see [Prompting best practices](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices).
88
9Existing Claude Haiku 4.5 prompts should perform well without changes. Start with the section that matches what you observe:
9Existing Claude Haiku 4.5 prompts should perform well without changes, unless they ask the model to write its reasoning in the response (see [Safeguard refusals](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-haiku-5-5#safeguard-refusals)). Start with the section that matches what you observe:
1010
1111* Unsure which effort level to run, or your Claude Haiku 4.5 requests set a thinking budget: [Use effort to control thinking](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-haiku-5-5#use-effort-to-control-thinking)
1212* The model searches the web, document sets, or knowledge bases, or skips a search that would find newer facts: [Accurate search results](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-haiku-5-5#accurate-search-results)
from line 130
130130* `cyber`: the request could enable cyber harm, such as malware or exploit development. Finding vulnerabilities in source code is allowed. High-risk dual-use cybersecurity work isn’t allowed. Benign cybersecurity work can also trigger this category. If the `cyber` classifier blocks your organization’s legitimate security work, you can apply to the [Cyber Verification Program](https://support.claude.com/en/articles/14604842).
131131* `frontier_llm`: the request could help with the development of competing AI models.
132132* `bio`: the request could enable biological harm, such as dangerous lab methods. Everyday health and educational questions aren’t affected. If the `bio` classifier blocks your organization’s life sciences work, you can apply to the [Life Sciences Verification Program](https://www.anthropic.com/news/life-sciences-verification-program).
133* `general_harms`: the request falls under a usage-policy area other than the previous three. Benign work can also trigger this category.
133* `reasoning_extraction`: the request asks the model to reproduce its internal reasoning in the response text.
134* `general_harms`: the request falls under another usage-policy area. Benign work can also trigger this category.
134135
135Claude Haiku 4.5 doesn’t return these refusals.
136Code written for Claude Haiku 4.5 might not handle these refusals.
136137
138With or without streaming, a refusal might arrive before any output or after partial output. For what each case returns and whether it’s billed, see [What a refusal looks like](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusal-response) and [How refusals are billed](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#how-refusals-are-billed).
139
137140Claude Haiku 5.5 has no [server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback). If a request is declined, handle `stop_reason: "refusal"` in your client. Sending the same request to Claude Haiku 5.5 again usually returns another refusal.
141
142Prompts, skills, and tool descriptions that ask Claude Haiku 5.5 to write its thinking or reasoning in the response might be declined with the `reasoning_extraction` category. Change the prompt rather than retry the request: remove those instructions, and see [Keep reasoning in thinking blocks](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks) for what to ask for instead. Claude Haiku 5.5 returns empty `thinking` blocks by default, so to read a summary of its reasoning, set `thinking: {"type": "adaptive", "display": "summarized"}`.
138143
build-with-claude/refusals-and-fallback Changed · +8 / -1 lines
from line 220
220220
221221The wording can sit in a system prompt, a skill, or a tool description, so check those too.
222222
223You can still ask Claude to explain its answer. Ask for a short explanation, the evidence behind a result, or a summary of the actions it took. To see how the model reasoned, set `display: "summarized"` and read the [`thinking` blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#summarized-thinking). This category has no recommended fallback model, so change the prompt rather than retry the request. If a reworded request is still declined, [contact support](https://support.claude.com/en/articles/9015913-how-to-get-support) and include the [request ID](https://platform.claude.com/docs/en/api/errors#request-id).
223Models that might return this category include the following:
224
225* Claude Fable 5.2, Claude Fable 5.1, and Claude Fable 5
226* Claude Opus 5.5 and Claude Opus 5
227* Claude Sonnet 5.5
228* Claude Haiku 5.5
229
230You can still ask Claude to explain its answer. Ask for a short explanation, the evidence behind a result, or a summary of the actions it took. To see a summary of the model’s reasoning, set `thinking: {"type": "adaptive", "display": "summarized"}` and read the [`thinking` blocks](https://platform.claude.com/docs/en/build-with-claude/thinking#summarized-thinking). This category has no recommended fallback model, so change the prompt rather than retry the request. If a reworded request is still declined, [contact support](https://support.claude.com/en/articles/9015913-how-to-get-support) and include the [request ID](https://platform.claude.com/docs/en/api/errors#request-id).
224231
225232## How refusals are billed
226233
managed-agents/self-hosted/kubernetes Changed · +17 / -7 lines
## Set up the add-on on GKE
from line 19
1919
2020* **A cluster:** Kubernetes 1.30 or later, with:
2121
22 * The Agent Sandbox controller (on GKE, the [Agent Sandbox add-on](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/how-install-agent-sandbox))
22 * The Agent Sandbox controller (on GKE, the Agent Sandbox add-on; release 0.16.0 needs GKE 1.35, as [Set up the add-on on GKE](https://platform.claude.com/docs/en/managed-agents/self-hosted/kubernetes#set-up-the-add-on-on-gke) says)
2323 * Nodes that run gVisor (on GKE, a [GKE Sandbox node pool](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/sandbox-pods))
2424 * A network plugin that enforces NetworkPolicy (on GKE, Dataplane V2 or Calico)
2525
from line 236
236236| `publicInternet` | Your servers, the dispatcher, a DNS server, and the public internet |
237237| `gateway` | Your servers, the dispatcher, and, through the egress gateway, the hosts that you list. See [Turn on the gateway on Kubernetes](https://platform.claude.com/docs/en/managed-agents/self-hosted/agent-identity#turn-on-the-gateway-on-kubernetes). |
238238
239## Set up the add-on on GKE
240
241Release 0.16.0 needs a cluster on GKE 1.35 and the Agent Sandbox add-on’s `v1alpha1` API. GKE can’t move a cluster back to an earlier minor version. If yours is on 1.36 or later, create a new cluster. A new cluster doesn’t have the `/workspace` volumes of your existing sessions, so copy out any files you need before you delete the old cluster.
242
243Starting in GKE 1.36.3-gke.1767000, the add-on moves to `v1beta1`, and [existing `v1alpha1` workloads can fail](https://docs.cloud.google.com/kubernetes-engine/docs/troubleshooting/known-issues#agentsandbox-v1alpha1-workload-failures) when a cluster upgrades to that version or later.
244
2451. Turn on the add-on with `gcloud beta container clusters update <cluster> --enable-agent-sandbox`.
2462. Check that `kubectl api-versions | grep agents.x-k8s.io` lists `agents.x-k8s.io/v1alpha1`. Later GKE versions can list it too, so also confirm that the cluster is on 1.35.
2473. Add a [maintenance exclusion](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/maintenance-windows-and-exclusions#configuring_a_maintenance_exclusion) with the `no_minor_upgrades` scope, because GKE upgrades clusters automatically.
248
239249## Other clusters
240250
241251Set `platform` in `cma-values.yaml` to `eks` for Amazon EKS, to `aks` for Azure Kubernetes Service (AKS), or to `generic` for any other cluster. All three need the upstream Agent Sandbox controller with its extensions, and a network plugin that enforces NetworkPolicy. They also need:
from line 267
257267
258268The commands in this section are for GKE. On another cluster, use `sandboxclaims` in place of `sandboxes`.
259269
260Deleting a session doesn’t free its volume. Archive the session first. Delete it only after `kubectl -n cma get sandboxes -l anthropic.com/session-id=<session-id>` lists nothing.
270Deleting a session might not free its volume, so archive the session first. Delete it only after `kubectl -n cma get sandboxes -l anthropic.com/session-id=<session-id>` lists nothing. An upgrade can delete the volumes of deleted sessions, as [Kubernetes: the volumes of deleted sessions](https://platform.claude.com/docs/en/managed-agents/self-hosted/upgrade#deleted-sessions-volumes) says.
261271
262If you deleted a session without archiving it, free its volume yourself:
272If you deleted a session without archiving it and its volume stays, free the volume yourself:
263273
2641. Find the session’s ID in the dispatcher’s log. This command prints a line for each session that appears to be deleted and still has a volume, with the ID after `session_id`:
2741. Find the session’s ID in the dispatcher’s log. This command can print a line for each session that appears to be deleted and still has a volume, with the ID after `session_id`:
265275
266276 ```bash
267277 kubectl -n cma logs deployment/cma-dispatcher --since=6m \
from line 278
268278 | grep "could not check the claim's session" | grep "403 Forbidden"
269279 ```
270280
271 The dispatcher writes these lines every 5 minutes. If the session isn’t listed, wait 5 minutes and run the command again.
281 The dispatcher writes these lines every 5 minutes. If the session isn’t listed, wait 5 minutes and run the command again. If it still isn’t listed, run `kubectl -n cma get sandboxes -l anthropic.com/session-id=<session-id>`. If that lists nothing, the volume is gone. If it lists a sandbox, go on to step 2 with that ID.
272282
2732832. Confirm that the session is deleted. With the port forwarded and `ANTHROPIC_API_KEY` set as in [Run a session](https://platform.claude.com/docs/en/managed-agents/self-hosted/kubernetes#run-a-session), run `ant --base-url http://127.0.0.1:8400 beta:sessions retrieve --session-id <session-id>`. Go on only if the answer is `404 Not Found` with `Session not found`. If the command prints a session, stop: that session isn’t deleted.
274284
managed-agents/self-hosted/upgrade Changed · +18 / -0 lines
### Kubernetes: the volumes of deleted sessions
from line 24
2424
2525Then go through [Settings and paths to check](https://platform.claude.com/docs/en/managed-agents/self-hosted/upgrade#settings-and-paths-to-check).
2626
27<Warning>
28 On Kubernetes, an upgrade can delete the files of some sessions, and nothing reports an error. Before you upgrade, see [Kubernetes: the volumes of deleted sessions](https://platform.claude.com/docs/en/managed-agents/self-hosted/upgrade#deleted-sessions-volumes).
29</Warning>
30
2731A minor or major upgrade includes a database backup. The dump holds every conversation in plain text, so the commands on this page encrypt it with the [age encryption tool](https://age-encryption.org). Create a key pair once, and keep the private key, `cma-backup.agekey`, away from the backups:
2832
2933```bash
from line 176
172176| A line that contains `cannot downgrade`, when you deploy the old release again | The old release can’t run on the changed schema. | Restore the backup, as in [Roll back](https://platform.claude.com/docs/en/managed-agents/self-hosted/upgrade#roll-back). |
173177| Another error from the migration | You don’t need to roll back. On Kubernetes, the servers stay as they were until the migration succeeds. | Fix the cause, and run `helm upgrade` or `docker compose up --build -d` again. |
174178
179On Docker Compose, `docker compose up` in the new release’s directory can stop with `required variable CMA_PG_USER is missing a value`. The new release’s `.env` then lacks the names that your stack’s data is kept under: its Compose project, its volumes, and its database role and name. The new stack hasn’t started, the old one might be stopped, and your data is untouched. Don’t add a `CMA_PG_USER` line to `.env` by hand. With that line alone, the stack starts empty under the release’s own names. Your data then stays in the old volumes. Instead, run `docker compose up -d` in the old release’s Compose directory. Then run this line there, in the terminal that has the `$releases` variable. In place of `<archive>`, write the archive’s name from the “Extract the new archive” step:
180
181```bash
182sh "$releases/<archive>/compose/keep-names.sh" && cp .env "$releases/<archive>/compose/"
183```
184
185Make again any change that you made to the new release’s `.env`. Then go on with the “Stop the old stack and start the new one” step.
186
175187The migration can succeed while the new servers don’t become ready. To find the cause, read the servers’ log:
176188
177189* **Kubernetes:** `kubectl -n cma-server logs -l anthropic.com/role=server --prefix --tail=20`
from line 360
348360Check the settings file for `inference.attribution`, and the server’s environment for `CMA_INFERENCE__ATTRIBUTION`. Delete the line if you find one. The release that you’re upgrading to doesn’t have the setting, and its server doesn’t start if either is set.
349361
350362When the Claude API is your inference provider, each model call carries the IDs of its session and of that session’s agent and environment after the upgrade. See [What the server sends to its inference provider](https://platform.claude.com/docs/en/managed-agents/self-hosted-data-and-access#what-the-server-sends-to-its-inference-provider).
363
364### Kubernetes: the volumes of deleted sessions
365
366An upgrade can delete the `/workspace` volume of each session that you deleted, and of each session that isn’t in the server’s database, such as one lost to a restore. You can lose those sessions’ files, and nothing reports an error. The deletion can start as soon as the first server of the new release answers. With the server chart, that’s during its `helm upgrade`.
367
368Find those sessions while the old servers are running, before you stop any of them: run the command in step 1 of [Free a session’s volume](https://platform.claude.com/docs/en/managed-agents/self-hosted/kubernetes#free-a-sessions-volume). If you run more than one environment, run it in each sandbox release’s namespace. Don’t do that section’s other steps for a session whose files you need. To keep the files, copy them out with your own Kubernetes tools. No API call, admin command, or page of the console on your server reaches these volumes.
351369
352370### Kubernetes: the names of your objects
353371
test-and-evaluate/strengthen-guardrails/handle-streaming-refusals Changed · +5 / -3 lines
from line 38
3838* **Messages API**: The stream ends with `stop_reason` `"refusal"`, and `stop_details` (`category` and `explanation`) arrives on the `message_delta` event.
3939* **Managed Agents**: A refused turn ends, and the session goes idle. Treat a turn as refused if `stop_details.type` or `stop_reason.type` is `"refusal"`.
4040
41Starting with Claude 4 models, streaming responses from Claude’s API return **`stop_reason`: `"refusal"`** when streaming classifiers intervene to handle potential policy violations. This safety feature helps maintain content compliance during real-time streaming.
41On Claude 4 and later models, streaming responses from the Claude API return **`stop_reason`: `"refusal"`** when streaming classifiers intervene to handle potential policy violations. This safety feature helps maintain content compliance during real-time streaming.
4242
4343<Tip>
4444 This page covers how refusals appear in streaming responses. For every `stop_reason` value and how to handle it, see [Stop reasons and fallback](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons). To retry refused requests on another Claude model, see [Refusals and fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback).
from line 86
8686 Resetting context is not the only way to recover. You can also retry the refused request on a different Claude model, and the [Refusals and fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback) page shows how to set that up with server-side fallback, the SDK middleware, or a manual retry.
8787</Tip>
8888
89A `reasoning_extraction` refusal is an exception: change the prompt instead of retrying on another model, as [Keep reasoning in thinking blocks](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks) says.
90
8991## Implementation guide
9092
9193Here’s how to detect and handle streaming refusals in your application:
from line 347
345347
346348## Migration notes
347349
348If you built refusal handling when this feature first shipped, or you’re adding it to an existing integration, check the following:
350If you’re adding refusal handling to an existing integration, check the following:
349351
350352* **Refusals are responses, not errors.** A refusal arrives as a successful HTTP 200 response with `stop_reason`: `"refusal"`, so monitoring built only on error rates won’t surface it. Track refusals as their own signal.
351353* **Refusals include structured detail.** On every model, a refusal also includes a `stop_details` object that identifies the policy category behind the decline. See [What a refusal looks like](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusal-response) for the full response shape.
352354* **Retry on a different model.** Re-sending a refused request to the same model usually results in another refusal. Instead of only resetting context, retry on a fallback model with [server-side fallback, the SDK middleware, or a manual retry](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback), and redeem [fallback credit](https://platform.claude.com/docs/en/build-with-claude/fallback-credit) when you build the retry yourself. Claude Haiku 5.5 has no server-side fallback, and its refusals carry no fallback credit, so set up its retry in your client.
353355* **Check batch results for refusals.** A refused request in a [Message Batch](https://platform.claude.com/docs/en/build-with-claude/batch-processing) is returned as a succeeded result with `stop_reason`: `"refusal"`, not as an errored result.
354* **Centralize handling on `stop_reason`.** The API continues to consolidate refusal handling around `stop_reason`: `"refusal"`, so branch on the stop reason rather than on model-specific behavior.
356* **Centralize handling on `stop_reason`.** Branch on `stop_reason`: `"refusal"` rather than on model-specific behavior.
355357
356358## Next steps
357359
build-with-claude/handling-stop-reasons Changed · +2 / -0 lines
from line 1930
19301930
19311931You can usually get a response to a refused request by retrying it on another Claude model. This works for Claude Fable 5.2, Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, Claude Sonnet 5.5, and Claude Haiku 5.5. [Refusals and fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback) shows how to set up that retry, server-side or in your client. Claude Haiku 5.5 has no server-side fallback, so set up its retry with [client-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#client-side-fallback). If you build the retry yourself from any of these models except Claude Haiku 5.5, [Fallback credit](https://platform.claude.com/docs/en/build-with-claude/fallback-credit) covers how to avoid paying the prompt-cache cost twice.
19321932
1933A `reasoning_extraction` refusal is an exception: change the prompt instead of retrying on another model, as [Keep reasoning in thinking blocks](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks) says.
1934
19331935### model\_context\_window\_exceeded
19341936
19351937Claude stopped because it reached the model’s context window limit. This lets you request the maximum possible tokens without knowing the exact input size.
build-with-claude/prompt-engineering/claude-prompting-best-practices Changed · +1 / -1 lines
from line 780
780780
781781* **Prefer general instructions over prescriptive steps.** A prompt such as “think thoroughly” often produces better reasoning than a hand-written step-by-step plan. Claude’s reasoning frequently exceeds what a human would prescribe.
782782* **Multishot examples work with thinking.** Worked examples in your prompt shape how Claude approaches similar problems in its own thinking blocks. Present each example as a problem, the method to apply, and the expected answer.
783* **Manual chain-of-thought (CoT) prompting as a fallback.** When thinking is off, you can still encourage step-by-step reasoning by asking Claude to think through the problem before it answers, and to put the final answer in `<answer>` tags so you can extract it. On Claude Fable 5.2, Claude Fable 5.1, Claude Fable 5, Claude Opus 5.5, Claude Opus 5, and Claude Sonnet 5.5, rely on thinking instead, at a lower [effort](https://platform.claude.com/docs/en/build-with-claude/effort) level if cost or latency matters: a prompt that asks the model to write out its reasoning, for example in `<thinking>` tags, might be declined. See [Keep reasoning in thinking blocks](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks).
783* **Manual chain-of-thought (CoT) prompting as a fallback.** When thinking is off, you can still encourage step-by-step reasoning by asking Claude to think through the problem before it answers. Ask it to put the final answer in `<answer>` tags so you can extract it. Some models might decline a prompt that asks them to write their reasoning, for example in `<thinking>` tags. On those models, rely on thinking instead. If cost or latency matters, use a lower [effort](https://platform.claude.com/docs/en/build-with-claude/effort) level. For examples of these models, see [Keep reasoning in thinking blocks](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks).
784784* **Ask Claude to self-check.** Append something like “Before you finish, verify your answer against \[test criteria].” This catches errors reliably, especially for coding and math. Claude Opus 5 is the exception: it verifies its own work well without explicit instruction, and verification instructions carried over from prompts tuned for earlier models can cause over-verification, adding tokens and latency. On Claude Opus 5, remove these instructions rather than rewriting them. See [Task scope and over-verification](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-opus-5#task-scope-and-over-verification).
785785
786786<Note>
build-with-claude/thinking Changed · +1 / -1 lines
from line 561
561561 In rare cases where you need access to full thinking output, [contact Anthropic sales](mailto:[email protected]).
562562</Note>
563563
564To see the model’s reasoning, read the `thinking` blocks rather than prompting for reasoning in the response text. On Claude Fable 5.2, Claude Fable 5.1, Claude Opus 5.5, Claude Opus 5, Claude Sonnet 5.5, and Claude Fable 5, a request that attempts to elicit the model’s internal reasoning as part of the response text might be refused with `stop_details.category: "reasoning_extraction"`. See [What a refusal looks like](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusal-response) for the field reference and [Keep reasoning in thinking blocks](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks) for what to ask for instead.
564To see the model’s reasoning, read the `thinking` blocks rather than prompting for reasoning in the response text. Some models might refuse a request that asks for their internal reasoning as part of the response text. The refusal has `stop_details.category: "reasoning_extraction"`. For examples of these models and what to ask for instead, see [Keep reasoning in thinking blocks](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#keep-reasoning-in-thinking-blocks). For the field reference, see [What a refusal looks like](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusal-response).
565565
566566### Streaming thinking
567567
managed-agents/self-hosted-data-and-access Changed · +1 / -1 lines
from line 79
7979
8080The server stores everything else, such as agents, sessions, and session history, in your database. If you set up no database, which is the default, the server holds that data in memory, and a restart erases it. If you configure a secret manager, the server keeps the secret of each new [vault credential](https://platform.claude.com/docs/en/managed-agents/vaults) there instead of in the database. Secrets that it stored earlier stay in the database.
8181
82Sessions and their history stay in your database until you delete them. The server doesn’t delete a session because of its age, archived or not. Deleting a session through the API removes the session and its history from your database, though the server keeps the session’s ID. The server can refuse the delete while a session is running. The delete doesn’t reach copies elsewhere, such as database backups, exported logs and traces, or what the agent wrote to a [memory store](https://platform.claude.com/docs/en/managed-agents/memory). On Kubernetes, the delete also leaves the session’s `/workspace` volume in place, as [Free a session’s volume](https://platform.claude.com/docs/en/managed-agents/self-hosted/kubernetes#free-a-sessions-volume) describes.
82Sessions and their history stay in your database until you delete them. The server doesn’t delete a session because of its age, archived or not. Deleting a session through the API removes the session and its history from your database, though the server keeps the session’s ID. The server can refuse the delete while a session is running. The delete doesn’t reach copies elsewhere, such as database backups, exported logs and traces, or what the agent wrote to a [memory store](https://platform.claude.com/docs/en/managed-agents/memory). On Kubernetes, the session’s `/workspace` volume can stay after the delete, as [Free a session’s volume](https://platform.claude.com/docs/en/managed-agents/self-hosted/kubernetes#free-a-sessions-volume) describes.
8383
8484What the server sends to the model, and what the model returns, fall under your organization’s agreement with the provider that serves the model. The agreement’s data retention terms apply. When the Claude API serves the model, the data retention agreement and settings that your organization has with Anthropic apply. If your organization has a [zero data retention (ZDR)](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention#zero-data-retention-zdr-scope) arrangement, it covers these model calls in the same way as other Messages API calls.
8585
managed-agents/self-hosted/quickstart Changed · +2 / -0 lines
from line 215
215215
216216## Troubleshooting
217217
218* **`docker compose up` stops with `required variable CMA_PG_USER is missing a value`:** On a new install, add the line `CMA_PG_USER=cma_server` to `.env`, and run `docker compose up --build -d` again. To upgrade a stack, don’t add the line. See [If the upgrade fails](https://platform.claude.com/docs/en/managed-agents/self-hosted/upgrade#if-the-upgrade-fails).
219
218220* **Your archive has no `compose` directory:** The archive holds an earlier release, and this page’s commands don’t match it. Ask your Anthropic account team for the current release. To move a running deployment to the current release, see [Upgrade self-hosted Claude Managed Agents](https://platform.claude.com/docs/en/managed-agents/self-hosted/upgrade).
219221
220222* **The server never comes up:** Run `docker compose logs migrate`. The one-time `migrate` container creates the database tables. It must exit with status `0` before the server starts.
models/haiku-5-5/migration-guide Changed · +1 / -0 lines
from line 32
32328. If you replay stored conversations through a different account, replay each one through the account that produced it. See [Replay thinking blocks through the account that produced them](https://platform.claude.com/docs/en/models/haiku-5-5/migration-guide#replay-thinking-blocks-through-the-producing-account).
33339. If your code changes `system`, `tools`, or earlier `messages` between requests in a conversation and sends thinking blocks back, keep the conversation append-only. See [Keep earlier turns unchanged](https://platform.claude.com/docs/en/models/haiku-5-5/migration-guide#keep-earlier-turns-unchanged).
343410. Handle `stop_reason: "refusal"`. Claude Haiku 5.5 runs safety classifiers that can decline a request, and it has no server-side fallback. See [Safeguard refusals](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-haiku-5-5#safeguard-refusals).
3511. If your prompts ask the model to write its reasoning in the response, such as in `<thinking>` or `<reasoning>` tags, remove those instructions. Claude Haiku 5.5 might decline a request that includes them and return the `reasoning_extraction` category. See [Safeguard refusals](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-haiku-5-5#safeguard-refusals).
3536
3637If your organization has a [Priority Tier](https://platform.claude.com/docs/en/api/service-tiers#supported-models) commitment on Claude Haiku 4.5, plan capacity separately: Priority Tier is not supported on Claude Haiku 5.5.
3738
models/haiku-5-5/whats-new-haiku-5-5 Changed · +1 / -1 lines
from line 17
1717| [Adaptive thinking and effort](https://platform.claude.com/docs/en/models/haiku-5-5/whats-new-haiku-5-5#adaptive-thinking-and-effort) | New | Optional: set `effort` to trade response quality against speed and cost. |
1818| [Larger context window and output](https://platform.claude.com/docs/en/models/haiku-5-5/whats-new-haiku-5-5#larger-context-window-and-output) | New | None. Existing `max_tokens` values stay valid, but thinking tokens count toward them. Long prompts are billed at higher prices; see [Long context pricing](https://platform.claude.com/docs/en/about-claude/pricing#long-context-pricing). |
1919| [Browser use tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/browser-use-tool) | New | None. |
20| [Safety classifiers can decline a request](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusal-response) | New | Handle `stop_reason: "refusal"` in your client. Server-side fallback isn’t available. |
20| [Safety classifiers can decline a request](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#refusal-response) | New | Handle `stop_reason: "refusal"` in your client. Server-side fallback isn’t available. Remove prompt instructions that ask the model to write its reasoning. |
2121| [Manual extended thinking returns an error](https://platform.claude.com/docs/en/models/haiku-5-5/migration-guide#configure-thinking) | Breaking | Replace `budget_tokens` with adaptive thinking. |
2222| [Sampling parameters can return an error](https://platform.claude.com/docs/en/models/haiku-5-5/migration-guide#remove-sampling-parameters) | Breaking | Omit `temperature`, `top_p`, and `top_k`. |
2323| [Assistant message prefill returns an error](https://platform.claude.com/docs/en/models/haiku-5-5/migration-guide#replace-assistant-prefill) | Breaking | End `messages` with a user turn. |