What is classification — the task where AI barely lies

There's one task where AI almost can't lie to you. Not because it got more honest — because you left it no choice.
That task is classification. It's built so the model is physically unable to invent an answer: you say upfront which answers exist, and the schema simply won't let anything else through.
It sounds duller than "write me some text". But classification is what most working AI features actually run on — and it's the one beginners walk right past.
What classification is
Classification is when the model doesn't compose an answer but picks one of your predefined labels.
A review is "positive", "negative" or "neutral". An email is "invoice", "support" or "spam". A transaction is "food", "transport" or "housing". You invent the labels; the model's job is to stick one on.
It's the oldest task in machine learning, but it used to mean collecting a dataset and training your own model for each one. Now it's one line in a prompt and you have a classifier by the evening. That's what changed.
There are two flavours, and mixing them up is expensive:
- One label out of many. An email is either "invoice" or "spam". Technically the model just picks from a list.
- Several labels at once. A review can be about "delivery" and "price". That needs a list, not a single value — and accuracy has to be scored differently.
How to lock the model into your labels
The usual approach is to ask nicely: "answer with one word from this list". It works 95 times out of 100, and the other five you get "Most likely this is an invoice 😊" — and your code dies on a string comparison.
So you define labels with a schema, not a request. In the Gemini API it looks like this:
from enum import Enum
class Category(Enum):
INVOICE = 'invoice'
SUPPORT = 'support'
SPAM = 'spam'
OTHER = 'other'
response = client.models.generate_content(
model='gemini-2.5-flash',
contents=letter_text,
config={
'response_mime_type': 'text/x.enum',
'response_schema': Category,
},
)
print(response.text) # exactly one of the four words
Notice text/x.enum. That isn't JSON — the output is a raw value, one word with no quotes and no wrapper. There's nothing to parse: the answer is either one of your labels or nothing. More on that mechanism in the piece on structured output.
Why it's the cheapest AI task there is
Three reasons, all of them about the bill at the end of the month.
The answer is one token. Not a paragraph, not JSON — a word. You pay for input and output both, and the output here is microscopic.
A small model is enough. Sorting an email into four boxes is not writing an article. A small language model handles it comfortably — many times cheaper than a flagship, and sometimes able to run locally. The rest of the saving tricks are in how to cut your AI costs.
You can trim the context. For "spam or not" you rarely need the whole email — the subject and first few lines usually do.
Why you can measure it, and can't measure generation
This is the difference that makes classification the right place to start.
Take a generated paragraph and ask: is it correct? There's no answer. There's "I like it", "too long", "wrong tone" — taste, which doesn't add up to a number.
Now take classification. You labelled 50 emails by hand, ran them through the model, compared — 46 matched. That's 92% accuracy. You reword one label, run again — 94%. You can see whether it got better or worse.
That's exactly how AI evals work: without a number you aren't improving, you're stirring. That run is walked through step by step in how to classify text with AI.
And one more effect nobody mentions: 80% of a classifier's mistakes aren't the model being dumb — they're bad labels. If "support" and "complaint" sit side by side, a human would mix them up too. The metric catches this on your second pass.
Where you'll meet it
In practically every useful AI feature — just under other names:
- Triaging inbound. Emails, tickets, form submissions — into folders.
- Moderation. "Fine" / "needs review" / "blocked".
- Routing. Simple questions to a cheap model, hard ones to the flagship.
- Money. A bank statement line into a spending category.
- Tags. A note or a photo gets labels from your fixed list.
Notice the pattern? None of these are "AI writes for me" — they're "AI sorts for me". The second half is duller and works far more reliably.
Isn't classification the same as asking for tags?
Almost, with one difference that changes everything. "Invent some tags" is generation: the list is new every time, so you can't filter by it. Classification picks from a closed list, so the result can go into a database column and be searched.
How many labels should I use?
Start with 4–7 plus "other". Fewer than five and you lose the point; more than ten and the model starts confusing neighbours — so will you. If "other" collects more than 20%, you missed a category: pull it out and give it its own label.
Classification is that rare case where the boring solution is both cheaper and more reliable than the flashy one. In KODiQ we walk through things like this in plain language and on real examples — from your first prompt to a feature you can actually trust.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





