← Back to library

Build a support-ticket classifier and measure its accuracy

An Anthropic cookbook notebook that builds a support-ticket classifier step by step. It starts with a plain prompt, then adds similar past tickets retrieved as examples and a reasoning step, measuring accuracy on a held-out test set after each change. The worked example sorts insurance tickets into ten categories.

  • OutcomeA ticket classifier that uses your category definitions and past labeled tickets, tested against held-out tickets before you rely on it.
  • SetupAn afternoon+
  • LevelAdvanced
  • CreditAnthropic
View original
Works with
Claude

Published Oct 20, 2026Updated Oct 20, 2026AI dry run on sample input: passed Oct 20, 2026Source verified Oct 23, 2026

When should you use it?

  • Ticket routing rules keep misfiling tickets
  • You have a year of tickets already labeled by category
  • You want an accuracy number before switching on automation

Not for: Teams without labeled history or a developer to run Python

What do you need, and what do you get?

You need

  • Labeled historical tickets
  • Category definitions
  • An Anthropic API key and Python

You get

  • Classifier prompt
  • Accuracy and confusion matrix on your test tickets

How does it work, step by step?

  1. Open the notebookOpen it on GitHub, or clone the repository and run it in Jupyter or Colab.
  2. Add an API keyThe notebook calls the model API; set the key as an environment variable, never in the notebook.
  3. Swap in your dataReplace the example data with a small, anonymized sample of your own.
  4. Check the resultsCompare outputs against what a person would have produced before using it on real work.

The prompt

The original prompt by Anthropic (claude-cookbooks), word for word, with a link to where it was published. Below it is our adapted version with fill-in blanks, if you want it. Works in Claude. Values in lime are placeholders.

Original prompt by Anthropic (claude-cookbooks)

Word for wordby Anthropic (claude-cookbooks)
You will classify a customer support ticket into one of the following categories:
<categories>
    {{categories}}
</categories>

Here is the customer support ticket:
<ticket>
    {{ticket}}
</ticket>

Use the following examples to help you classify the query:
<examples>
    {{examples}}
</examples>

First you will think step-by-step about the problem in scratchpad tags.
You should consider all the information provided and create a concrete argument for your classification.

Respond using this format:
<response>
    <scratchpad>Your thoughts and analysis go here</scratchpad>
    <category>The category label you chose goes here</category>
</response>

Exactly as published by Anthropic (claude-cookbooks) in Classification guide · anthropics/claude-cookbooks.

Our adapted version (optional)

Fill in the blanks (optional; the copied prompt uses your values)

Adapted prompt3 variables
Classify this support ticket into exactly one category.
Categories with definitions:
{category_definitions}

Similar past tickets with their correct labels:
{labelled_examples}

Ticket:
{ticket}

Reason briefly about which definition fits, then give the category label on its own line. If two categories fit equally, say so instead of guessing.

What can go wrong?

  • Accuracy on the notebook's insurance data says nothing about yours; measure on your own tickets.
  • Keep categories mutually exclusive or accuracy will suffer whatever the prompt.

Our take

Most no-code ticket routing goes live without anyone knowing how often it's right. This notebook's main lesson is the method: hold back labeled tickets, measure accuracy after every prompt change, and only automate once the number is good enough for your risk. The techniques it layers (clear category definitions, retrieved similar examples, reasoning before the answer) are the same ones that help in any classification prompt. In our dry run we ran the published prompt by hand on twelve sample MSP tickets across five categories, with three retrieved examples each: eleven matched the label we expected, and the miss was a billing question about a security product, which is a category-definition problem rather than a prompt problem. We'd tell any team doing this to fix overlapping categories first. Re-measure accuracy every few months on fresh tickets, because new products and issues shift what customers write about. A classifier that was 90% right last spring can drift without anyone noticing unless the measurement is repeated.

Where the time goes back: Routing gets automated only once you have measured how often it is right.

FAQ

Can I use this without coding?
Not as published; it is a Python notebook. Our prompt below works in a chat assistant for small batches, but you lose the accuracy measurement that makes the notebook valuable.
How many labeled tickets do I need?
A few hundred across your categories is a reasonable start: most for examples, with a set held back for testing.

Source and credit

The original prompt on this page is by Anthropic (claude-cookbooks), shown word for word with a link to where it was published. The summary, notes and adapted version are ours.

Original
Classification guide · anthropics/claude-cookbooks
Creator
Anthropic
Published on
GitHub (anthropics/claude-cookbooks)
Original date
May 19, 2024
License
MIT
Originally for
Claude
AI dry run
Oct 20, 2026: passed. Dry-run tested by our AI test agent on sample input. Format followed (scratchpad + category); 70%→95% accuracy claim not repeated on our page.
AI dry run on sample data; not run with live connected accounts. The playbooks.bot test agent filled the prompt with synthetic inputs, produced the output and checked it against the page's stated outputs and guardrails.
Verified
Oct 23, 2026: source link resolves to the original, the credited creator published it, our excerpt or prompt matches it, and the license allows our use.

The original is licensed under the MIT License (Copyright (c) 2023 Anthropic). The original prompt above is reproduced under that license with its copyright notice; our adapted prompt and summary are our own wording.

Are you the creator? Claim or correct this page.

More in Customer Support

All 28 Customer Support playbooks →

Related playbooks

Customer SupportWorkflow✓ AI dry run

Work technical support cases from one agent session

Answer technical support cases faster by tracing product behavior in the codebase and pulling customer data, logs and past threads into one agent session.

Credit: Kody Fisher & Zach Hudson

An afternoon+
Customer SupportWorkflow✓ AI dry run

Hand callers from a phone bot without repeats

Design an AI phone line so callers can reach a person quickly and the staff member sees everything the caller already said.

Credit: u/Philodendron60 on r/VetTech

Under an hour