What it is
Text classification means reading some text and putting it in a bucket. Is this email spam or not? Is this support ticket about billing, a bug or a refund? Is this message safe to show? The labels are decided in advance, and the model's job is to pick the right one, or several.
It is a sorting task, like a mail clerk dropping letters into pigeonholes. The clerk does not write anything new. They choose a slot.
Common uses
- Moderation. Flag harmful or policy-breaking content.
- Routing. Send a request to the right team, or to the right model. See model routing.
- Tagging. Label documents by topic, language or sentiment.
- Safety checks. Screen inputs and outputs, as part of AI guardrails.
- Grading. Score an answer against a rubric, as in LLM-as-a-judge.
How it is done
There are three common approaches:
- Classic machine learning. Train a small model on labeled examples. Fast and cheap, but it needs a good labeled dataset.
- Embeddings plus a simple classifier. Turn text into embeddings, numeric representations of meaning, then train a light model on top. A good middle path.
- Prompting a language model. Describe the labels in a prompt and ask. This needs no training data and works well for new categories, though it costs more per item and can be less consistent.
A fine-tuned model sits between the second and third: more consistent than prompting, with less data than training from scratch.
Getting good results
- Define labels so two people would pick the same one. Vague labels give noisy results.
- Include an "other" or "unsure" label so the system is not forced into a wrong guess.
- Use structured output so the label comes back in a fixed format.
- Look at the confidence score, if there is one, and send low-confidence cases to a person. See model calibration and human-in-the-loop.
- Measure accuracy on a sample you labeled yourself, and look at the mistakes, not only the average.
The catch
Classifiers inherit the biases and blind spots of their training data, and they can be fooled by text written to trick them, including prompt injection. Class imbalance also hides errors: a system that labels everything "not spam" can look 99% accurate when spam is rare.
The short version
Text classification is sorting text into labels. It is the quiet workhorse behind moderation, routing and tagging, and it works best when the labels are clear and the uncertain cases go to a human.