Sub topic 2
Designing Labels: Definitions, Overlap, and an "Other" Fallback
This chapter covers the label schema, which is the set of categories the model can choose from. It assumes you can read basic Python, have called a chat or text-completion API from code, understand JSON, and know what accuracy means. The prompt, output parsing, and routing code come in later chapters. Here the goal is a label set that a model, and a human reviewer, can apply consistently.
Why the label set comes first
A classifier can only be as clear as the categories it is given. If two labels overlap, the model will split similar messages between them at random. Your accuracy numbers will then look bad, and you will not be able to tell whether the model, the prompt, or the labels are at fault.
Most "the model keeps getting it wrong" problems in classification pipelines trace back to labels that a careful human could not apply consistently either. A useful test: give 30 messages to two colleagues, without discussion. If they disagree on many of them, the model will too.
Three properties make a label set work:
- Mutually exclusive. Each item fits exactly one label, or there is a written rule for choosing.
- Collectively covering. Every item has somewhere to go, which is the job of the fallback label.
- Tied to an action. Each label maps to a handler, a queue, or a decision. A label that nobody acts on differently from another label is a candidate for merging.
Start from the routing decision
Work backwards from what happens after classification. If the support team has three queues, the labels should mirror those queues. Do not create a label such as frustrated just because it seems interesting. If no handler behaves differently for frustrated customers, the label adds error without adding value.
The label set used in this tutorial is:
LABELS = {
"billing": "Charges, invoices, refunds, and payment failures",
"technical": "Bugs, errors, outages, and how-to questions about the product",
"account": "Login, password, profile, and permission changes",
"other": "Anything that does not clearly fit the labels above",
}Each label is a short name plus a one-line definition. The name is what the model returns and what your code compares against. The definition is what the model reads to decide. Both matter.
Writing definitions
A definition should say what belongs in the label, in terms the model can match against text. Compare these two entries for the same label.
| Weak definition | Stronger definition |
|---|---|
| `billing`: Money stuff | `billing`: Charges, invoices, refunds, and payment failures |
| `technical`: Product problems | `technical`: Bugs, errors, outages, and how-to questions about the product |
| `account`: Account issues | `account`: Login, password, profile, and permission changes |
The stronger versions list concrete things that appear in real messages. Some guidelines:
- Use nouns and events that show up in the text, such as "refunds" or "password", instead of abstract words such as "issues".
- Keep each definition to one line. If you need a paragraph, the label is probably two labels.
- Define by content, not by the writer's mood or the item's importance, unless the action really depends on that.
- Use label names that are short, lowercase, and free of spaces, so they are easy to compare in code and to read in JSON.
- Avoid names that mean something else on their own. A label called
generalinvites the model to use it for anything.otherat least signals a leftover bucket.
Handling overlap
Real messages often touch two categories. Consider:
- "I was charged twice and now I can't log in to see my invoice."
This message is both billing and account. There are four common ways to deal with overlap.
| Strategy | How it works | Use when |
|---|---|---|
| Priority rule | Write a tie-break rule: "If a message mentions a charge, choose billing." | One category always wins in practice. |
| Primary issue | Ask for the main problem the sender wants solved. | Items usually have one real request. |
| Multi-label | Allow a list of labels per item. | Handlers can work in parallel, or one item truly needs several teams. |
| Compound label | Add a label such as `billing_and_account`. | A specific combination has its own handler. |
For single-label routing, the first two are the usual choice. A priority rule is simple to state in the prompt and easy to test. A tie-break could look like this in the definitions:
LABEL_RULES = (
"If a message fits more than one label, choose the one for the problem "
"the sender most wants solved. If a charge or refund is involved, prefer billing."
)Multi-label output changes everything downstream. Parsing must accept a list, validation must check each entry, and routing must decide what to do when the labels point to different queues. Choose it only when your handlers need it. The single-label code in this tutorial does not support it.
Compound labels grow quickly. Three base labels give three pairs, and four give six. If you find yourself adding them, a priority rule is usually cheaper.
Finding overlap with data
You do not have to guess where labels overlap. Take 50 to 100 real messages, label them yourself, and note every one where you hesitated. The hesitations cluster around specific label pairs. Those pairs are where to add a priority rule, a clearer definition, or a few-shot example (covered in a later chapter).
Later, the confusion matrix from the evaluation chapter will show the same thing in numbers. If many billing items are predicted as account, those two definitions overlap.
The "other" fallback
Every label set needs a place for items that fit nowhere. Without one, the model must pick a wrong label, and your pipeline will confidently send the item to the wrong team.
The fallback label does three jobs:
- It gives the model a legitimate answer for off-topic input, such as spam, a greeting with no request, or a message in a language your team does not handle.
- It gives the code a safe default when parsing or validation fails.
- It gives you a measurable bucket. The share of traffic landing in
othertells you whether your labels still match reality.
In the routing code, other has no entry in the queue mapping, so it falls through to human triage:
QUEUES = {
"billing": "billing-team",
"technical": "support-engineering",
"account": "account-services",
}
def queue_for(label):
return QUEUES.get(label, "human-triage")
print(queue_for("billing"))
print(queue_for("other"))
print(queue_for("unknown-label"))This prints billing-team, human-triage, and human-triage. The default is built into the lookup, so any unmapped label is handled safely.
Common mistakes with the fallback
- Defining
otheras a topic. "Miscellaneous questions" sounds like a real category and the model may use it for things that belong elsewhere. Define it as the absence of a clear fit, as in the example above. - Leaving it out. The model will force a fit, and you will see wrong-but-confident answers.
- Letting it grow unnoticed. If 25 percent of traffic lands in
other, you either have a missing label or definitions that are too narrow. Review a sample ofotheritems regularly. - Routing it nowhere.
othershould lead to a human or a defined catch-all handler, never to a dropped message.
Granularity: how many labels
More labels give finer routing but more confusion. A rough guide for LLM classification with a plain prompt:
- Up to about 5 to 8 labels is easy to manage with short definitions.
- Beyond 10 to 15, definitions begin to overlap and the prompt grows. Consider a two-step approach: classify into a coarse group first, then into a subtype within the group. This is a cascade, and a later chapter discusses it.
- Very rare labels are hard to evaluate. If a label occurs in 1 percent of traffic, a labeled set of 200 examples contains about two cases, which tells you little. Fold such labels into
other, or route them with a rule instead.
Granularity should follow the routing structure. If two labels go to the same team with the same handling, merge them.
Keeping labels stable
Once you have a labeled evaluation set and production data, the schema is a contract. Changing it has costs:
- Old labeled examples may need relabeling.
- Metrics before and after the change are not comparable.
- Downstream code that matches label strings can break.
Treat label changes like schema changes. Version the label set, rerun your evaluation on the labeled data, and update the routing table in the same change. Never rename a label in the prompt without renaming it in the validation and routing code. Validation will reject the model's output, and every item will fall back to other.
Putting the schema into the prompt
The prompt builder renders the label dictionary directly, so the definitions in the prompt and the labels in the validation code come from a single source:
LABELS = {
"billing": "Charges, invoices, refunds, and payment failures",
"technical": "Bugs, errors, outages, and how-to questions about the product",
"account": "Login, password, profile, and permission changes",
"other": "Anything that does not clearly fit the labels above",
}
label_lines = "\n".join(f"- {name}: {desc}" for name, desc in LABELS.items())
print(label_lines)This prints one - name: definition line per label. Because validation later checks label in LABELS, adding or removing a label in this one dictionary updates both the prompt and the check. Keep it that way. Duplicating the label list in several places is a common source of drift.
A short checklist
- Does each label map to a distinct action?
- Does each definition list concrete content, in one line?
- Is there a written rule for overlapping cases?
- Is there an
otherlabel, defined as "does not clearly fit"? - Do two people agree on a sample of real messages?
- Is the label set kept in one place in the code?
Exercise
A team's label set is billing, technical, account, and general, where general is defined as "Miscellaneous questions". After a week, 40 percent of messages are labeled general, including several about refunds. Name two problems with this design and one change for each.
Show answer
First, general is defined as a topic ("miscellaneous questions") instead of as the absence of a clear fit, so the model uses it as an easy answer for anything vague. Change the definition to "Anything that does not clearly fit the labels above" and name it other. Second, the other definitions are probably too thin, or overlap with each other, so refund messages are not matching billing. Rewrite billing to list concrete content such as charges, invoices, refunds, and payment failures, and add a priority rule such as "If a charge or refund is involved, prefer billing". Then review a sample of the other items and check that the share drops.
Exercise
A message says "I was charged twice and now I can't log in to see my invoice." Your system routes each item to one queue. Describe two ways to handle this message and say when you would pick each.
Show answer
One way is a priority rule: state in the prompt that messages involving a charge or refund go to billing. Pick this when billing problems should always be handled first, because it is simple and easy to test. The other way is a primary-issue rule: ask the model to choose the problem the sender most wants solved. Pick this when messages usually have one main request and the order of concern varies. Multi-label output is a third option, but it is only worth the extra parsing and routing work if both teams need to act on the same item.