Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

A Java team wants to use an LLM to classify 2 million support tickets per day into 30 categories. How would you evaluate whether an LLM is the right tool versus a classic classifier, and how would you build it?

We decide with measurements, not opinions: label a sample of a few thousand tickets, then compare an LLM prompt and a classic classifier (for example logistic regression on embeddings) on accuracy, cost per ticket and latency. LLMs need little training data and adapt to new categories by a prompt change; classic models are far cheaper and faster at 2 million tickets a day once trained. Often the best design is a hybrid: embeddings plus a small classifier for most tickets, and an LLM only for low-confidence cases, built with structured output, batch APIs, idempotent retries and drift monitoring.

Why this question is asked

Classification is one of the most common first LLM projects, and at small volume the choice hardly matters. At 2 million tickets a day it matters a lot: a choice that costs one cent per ticket costs $20,000 a day. Interviewers use this scenario to see whether we can compare approaches with numbers, design for volume and failure, and avoid both extremes, sending everything to the biggest model or dismissing LLMs entirely. In this answer, we will build a labelled baseline, compare the two approaches with example numbers, design a hybrid, build the Java pipeline with structured output and idempotency, and plan monitoring.

1Start With a Labelled Sample

Before choosing anything, we need a way to measure. We take a random sample of recent tickets, around 3,000 to 5,000, and have experienced support agents label each one with one of the 30 categories. Where agents disagree, we note it: if humans agree only 85 percent of the time on a category, no model will reliably reach 98 percent on it, and the category definitions may need fixing first.

We split the sample into a training part and a held-out test part. Every approach we try is scored on the same test set, with accuracy overall and per category, because a model that is 95 percent accurate overall can still be terrible at the rare category that matters most, such as security reports.

2Comparing the Two Approaches With Numbers

The LLM approach is a prompt that lists the 30 categories with one-line definitions and a few examples, asks for one label, and uses a low temperature. It needs no training, and adding a category is a prompt change. The classic approach turns each ticket into an embedding, a vector of numbers from an embedding model, and trains a small classifier such as logistic regression on the labelled examples. It needs labelled data and retraining when categories change, but each prediction is a cheap calculation.

Let us put example numbers on it. Suppose a ticket averages 400 tokens and the prompt with category definitions adds 600, so 1,000 input tokens per ticket, or 2 billion input tokens a day. At an example price of $0.15 per million input tokens for a small model, that is $300 a day; with a large model at $3 per million it is $6,000 a day. The embedding approach embeds only the 400-token ticket, 800 million tokens a day, which at an example $0.02 per million is $16 a day, and the classifier runs on ordinary CPUs. 2 million tickets a day is about 23 per second on average, perhaps 70 per second at peak, which both approaches can handle, but rate limits and latency are much easier with the classic model.

Example comparison on the same test set (illustrative numbers)
ApproachAccuracyCost per dayLatency per ticketNew category
Large LLM prompt93%~$6,0001 to 3 sedit the prompt
Small LLM prompt88%~$3000.5 to 1 sedit the prompt
Embeddings + logistic regression91%~$16 + CPU~50 mslabel examples, retrain
Hybrid (classifier, LLM if unsure)94%~$16 + ~$600mostly ~50 msprompt now, retrain later
Measure your own numbers; prices and accuracy vary by model and data.

3Designing the Hybrid

The numbers usually point to a hybrid. The classifier gives a probability for each category. When its top probability is high, say at least 0.9, we accept its label; in many ticket datasets that covers 80 to 90 percent of traffic. The remaining uncertain tickets go to an LLM prompt, which is good at the unusual cases a small model has not seen. If the LLM's answer is also uncertain or invalid, the ticket goes to a human triage queue. The threshold is tuned on the test set: lower it and we save money but lose accuracy, raise it and the LLM share grows.

The hybrid also handles new categories gracefully. When the business adds category 31, we add it to the LLM prompt on day one, route tickets that look related to the LLM, and use the LLM's labels, spot-checked by humans, to train the next classifier version.

Step throughRouting one ticket
  1. Embed the ticket text
  2. Small classifier predictsprobabilities for 30 categories
  3. Top probability >= 0.9?
    YesUse the classifier labelNoAsk the LLM
  4. LLM returns a label as JSONenum of 30 categories
  5. Valid and confident?
    YesUse the LLM labelNoSend to human triage
  6. Store label with ticket ididempotent write, model versions recorded

6 steps in order. Play them, or step through them one at a time.

4Building It in Java

For the LLM part, we never parse free text. We ask for structured output: Spring AI's entity() can map the response to a Java record or enum, and providers that support JSON schema mode constrain the model to valid output. Low-urgency traffic can go through a provider's batch API, where available, which typically costs much less in exchange for results within hours; check your provider's terms. Every write is keyed by ticket id, so a retry after a timeout cannot create duplicates.

Java
enum Category { BILLING_REFUND, LOGIN_PROBLEM, BUG_REPORT, SECURITY_REPORT, OTHER /* ... 30 in total */ }
record Classification(Category category, double confidence) {}
Classification llmClassify(Ticket t) {
return chatClient.prompt()
.system(categoryPrompt) // definitions and examples, loaded from a versioned file
.user("<ticket>\n" + t.text() + "\n</ticket>")
.options(ChatOptions.builder().temperature(0.0).maxTokens(50).build())
.call()
.entity(Classification.class); // Classification[category=LOGIN_PROBLEM, confidence=0.82]
}
// Idempotent store: a retried message for the same ticket updates nothing new
jdbc.update("""
INSERT INTO ticket_label (ticket_id, category, source, model_version)
VALUES (?, ?, ?, ?) ON CONFLICT (ticket_id) DO NOTHING""",
t.id(), c.category().name(), "llm", modelVersion); // 1 the first time, 0 on a retry

Notice that the ticket text is wrapped in delimiters, because tickets are written by customers and may contain text that looks like instructions. Retries use exponential backoff on rate-limit errors, and the consumer reading tickets from the queue processes them in parallel up to the provider's limit.

5Monitoring Drift and Sampling for Review

A classifier that is 94 percent accurate on launch day will not stay that way. Products change, a new release creates a new kind of bug, and customers start using new words. This is drift: the inputs move away from the data the model was trained or prompted on. We watch the distribution of predicted categories per day, the share of tickets that fall below the confidence threshold, and how often agents re-label a ticket after it was routed. A sudden rise in any of them is an early warning.

We also sample a few hundred labelled tickets a week for human review, stratified so rare categories are included, and add the corrected ones to the training and evaluation sets. That review keeps the accuracy number honest and provides the data for retraining the classifier every few weeks.

6Follow-up questions

Why not fine-tune a small LLM instead of using logistic regression?

That is a valid middle option, and it can beat logistic regression on accuracy. But it needs more training infrastructure and serving cost than a linear model on embeddings, and at 2 million tickets a day the difference in running cost adds up. I would try it only if the simpler classifier plus LLM fallback does not reach the accuracy target.

How do you get a confidence value from an LLM?

Asking the model for a confidence number is weak but sometimes useful as a signal. Better options are token log probabilities where the provider exposes them, or asking two different prompts or models and treating disagreement as low confidence. In the hybrid, the classifier's calibrated probability is the main confidence signal, and the LLM handles the hard cases.

What if the LLM returns a category that does not exist?

With structured output mapped to a Java enum, parsing fails instead of silently storing a wrong value. We retry once with the validation error in the prompt and otherwise send the ticket to human triage.

7Conclusion

In this answer, we saw how to decide between an LLM and a classic classifier by measuring both on a labelled sample for accuracy, cost per ticket and latency. LLMs need little data and adapt by prompt change, while embeddings plus a small classifier are much cheaper and faster at 2 million tickets a day. A hybrid that sends only low-confidence tickets to an LLM often gives the best balance. We built it with structured output, batch APIs where available, idempotent writes keyed by ticket id and retries, and we keep it healthy by monitoring drift and sampling outputs for human review.

What to say in the interviewAbout 90 seconds aloud

Open with

I would not pick the approach up front; I would measure. First I get three to five thousand recent tickets labelled by experienced agents, check how much humans agree, and hold out a test set.

Then, if they want more

Then I try two candidates on the same test set: an LLM prompt with the 30 category definitions and a few examples at temperature zero, and a classic model, embeddings plus logistic regression. I compare accuracy overall and per category, cost per ticket and latency.

At 2 million tickets a day the cost difference is large: with example prices, a large model could be thousands of dollars a day, while embeddings plus a classifier are tens of dollars. LLMs win on needing little data and on new categories, since that is a prompt change; classic models win on cost and speed once trained.

Very often I end up with a hybrid: the classifier handles tickets where it is confident, maybe 85 percent, and the uncertain ones go to the LLM, then to humans if still unclear.

In Java I would use structured output mapped to an enum so labels always parse, batch APIs for non-urgent volume, retries with backoff, and idempotent writes keyed by ticket id. After launch I monitor category distribution, the low-confidence rate and agent corrections to catch drift, and sample outputs weekly for human review and retraining.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring AI reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A Java team wants to use an LLM to classify 2 million support tickets per day into 30...": https://scrivio-interview-library.netlify.app/spring-boot/llm-fundamentals/89e1ac33ec/