Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

Name four common LLM use cases in enterprise Java applications and, for each, one way it can fail in production.

Four common use cases are summarisation of tickets or documents, which can omit key facts or invent details; question answering over documents with RAG, which can retrieve the wrong chunks and answer confidently from them; extraction of structured data from text, which can return invalid formats or wrong fields; and classification and routing, which can drift as inputs change and misroute work. A fifth, code or SQL generation, can produce insecure or wrong queries, so generated SQL must never run without restrictions.

Why this question is asked

Most enterprise LLM features fall into a handful of patterns, and each pattern has its own typical way of going wrong in production. Knowing them helps a developer design the safeguards before the first incident rather than after. Interviewers ask this to check that a candidate has a realistic picture of LLMs: useful, but with failure modes that are different from ordinary code, because they produce plausible output rather than errors. In this answer, we will go through summarisation, RAG question answering, extraction, classification and routing, and code or SQL generation, looking at what each one does, the failure it is prone to, and how we guard against it, with Java code where it helps.

1Why LLM Failures Are Different

When ordinary Java code fails, it usually fails loudly: an exception, a 500 status, a failed test. LLM features usually fail quietly. The summary reads well but leaves out the one fact that mattered; the answer cites a document, but the wrong one; the extracted total is a valid number, just not the right one. Because the output always looks plausible, nobody notices until a customer or an auditor does.

So for every use case, the question is not only does it work, but how will we notice when it does not. The safeguards below all aim to turn quiet failures into visible ones.

Four use cases and how they fail
Use caseTypical failureMain safeguard
SummarisationOmits key facts, invents detailsSource-grounded prompts, fact checks on samples
RAG question answeringWrong chunks, confident wrong answerRetrieval evaluation, citations, say not found
Structured extractionInvalid format, wrong field valuesSchema output, validation, review queue
Classification and routingDrift as inputs change, misroutingConfidence thresholds, drift monitoring
Code or SQL generationInsecure or wrong queriesRead-only, validated, limited execution

2Summarisation of Tickets and Documents

Summarising long support tickets, incident reports or contracts saves people a lot of reading. A Java service sends the text with instructions such as summarise in five lines for a support agent, and stores or displays the result. The failure is that a summary is a selection: the model may leave out a key fact, the customer's threat to cancel, the deadline in clause 7, or worse, add a detail that is not in the source, such as a refund that was never promised.

The first defence is in the prompt. If we tell the model to use only facts from the text and to always cover the same elements, the customer, the problem, what was promised and the next step, an omission becomes visible because an expected part is empty. The second defence is in the interface: the summary always sits next to a link to the full source, so a reader who doubts it can check in one click. But neither tells us how often summaries are wrong, so we also check a sample every week against the original text, by people or with an automated fact check, and track the error rate over time.

3Question Answering Over Documents With RAG

RAG assistants answer employees' or customers' questions from internal documents by retrieving relevant chunks and putting them in the prompt. The typical failure is retrieval, not generation: the search returns chunks from the wrong product, an outdated version of a policy, or a section that looks similar but says something different, and the model answers confidently from them. The user sees a fluent answer with a citation and has no reason to doubt it.

Since the failure starts in retrieval, that is where we measure first. We keep a set of real questions together with the document that correctly answers each one, and check how often that document appears in the top results; if it is missing, no prompt can save the answer. Metadata filters for product, version and permissions then stop the search from even considering chunks that cannot be right for this user. Finally, we make the answer checkable and give the model a way out: every answer carries clickable citations, and the prompt tells the model to say the documents do not answer the question rather than stretch an unrelated chunk into an answer.

4Extraction of Structured Data

Extraction turns free text into fields: invoice number and total from an invoice, names and dates from a contract, order details from an email. It replaces a lot of manual data entry. It fails in two ways: the format is wrong (a date as 03/04/2025, JSON wrapped in prose) which breaks parsing, or the format is fine but the value is wrong (the subtotal taken as the total, a missing field filled with a guess), which is worse because it is silent.

Java
record OrderRequest(@NotBlank String customerEmail, @Positive int quantity, @NotBlank String sku) {}
OrderRequest req = chatClient.prompt()
.system("Extract the order. Use null for anything not stated. Never guess.")
.user("<email>\n" + emailText + "\n</email>")
.call().entity(OrderRequest.class); // schema-shaped output mapped to a record
if (!validator.validate(req).isEmpty() || !catalog.exists(req.sku())) {
reviewQueue.add(emailText); // a person checks; nothing is ordered on a guess
}

Notice the second check: the SKU must exist in our catalog. Schema validation catches format errors, but checks against our own data catch many wrong values too.

5Classification and Routing

Classification assigns a label, a ticket category, an urgency level, a department, and routing sends the work to the right team based on it. It works well at launch and then slowly degrades as inputs change: a new product brings new kinds of problems, customers use new words, a reorganisation changes which team handles what. This is drift, and its symptom is misrouted work that bounces between teams.

Because drift is gradual, a check at launch is not enough; we need signals that keep working afterwards. A confidence threshold sends items the classifier is unsure about to a human triage queue, so the new kinds of input that cause drift tend to land in front of people first. We also watch the share of each label per day and how often people re-route an item after the system routed it, because a rise in either is usually the first sign. And every few weeks we label a fresh sample, measure accuracy again, and update the prompt or retrain when it has dropped.

6Code and SQL Generation

A fifth common use case is generating code or SQL, for example letting business users ask questions in natural language that become database queries. The failure here can be severe: a query that is subtly wrong (a join that double-counts revenue) gives a confident wrong number, and a query that is unsafe (a DELETE, or a SELECT over customer data the user should not see) causes real damage if executed. Generated SQL must never run with ordinary application permissions.

Java
// Generated SQL runs only under strict limits
try (Connection c = readOnlyReplica.getConnection()) { // read-only role, replica database
c.setReadOnly(true);
try (Statement s = c.createStatement()) {
s.execute("SET statement_timeout = '5s'"); // PostgreSQL: stop long queries
s.setMaxRows(1_000); // cap the result size
ResultSet rs = s.executeQuery(validatedSql); // only after parsing allowed SELECT on known tables
}
}

Notice the layers: a role that cannot write, a replica that cannot hurt production, a timeout, a row cap, and validation before execution. Each limits the damage of a wrong or malicious query.

7Follow-up questions

Which of these use cases is safest to start with?

Summarisation and classification with a human in the loop are usually the safest first steps, because a person sees the output before it has consequences, and the cost of a mistake is small. Extraction into systems of record and SQL execution need stronger safeguards before they go live.

How do you detect hallucinated details in summaries automatically?

One approach is a second check that compares each statement in the summary with the source text, using a model prompted as a fact checker or rules for specific facts such as amounts and dates. It is not perfect, so it is used to flag summaries for human review rather than to certify them.

Do these failures go away with better models?

They become less frequent, but not zero, and they become harder to notice because outputs are even more fluent. The safeguards stay necessary, and evaluation sets tell us how much a better model actually helps.

8Conclusion

In this answer, we went through common LLM use cases in enterprise Java applications and how each fails. Summarisation can omit key facts or invent details; RAG question answering can retrieve the wrong chunks and answer confidently; extraction can return invalid formats or wrong values; classification and routing can drift as inputs change; and code or SQL generation can produce insecure or wrong queries. Because LLM failures are quiet, each use case needs safeguards that make failures visible: grounding, evaluation, validation, thresholds, monitoring and restricted execution.

What to say in the interviewAbout 100 seconds aloud

Open with

Four common ones I would name are summarisation, RAG question answering, extraction and classification, and I would add SQL generation. Summarisation of tickets or documents saves reading time, but a summary is a selection, so it can omit the key fact, like a cancellation threat, or invent a detail that is not in the source; I guard with prompts that require specific elements from the text only, a visible link to the source, and sampled fact checks.

Then, if they want more

Question answering over documents with RAG usually fails in retrieval: it pulls a chunk from the wrong product or an old version and the model answers confidently from it, so I evaluate retrieval separately, filter by metadata and require citations.

Extraction of structured data can return invalid formats or, worse, valid-looking wrong values, so I use schema output mapped to a Java record, Bean Validation, checks against our own data, and a review queue.

Classification and routing work at launch and then drift as products and wording change, misrouting work, so I use confidence thresholds with human triage and monitor label distributions and re-routing.

And for SQL generation, a wrong or malicious query can do real damage, so generated SQL never runs without restrictions: a read-only role on a replica, validation that it is a SELECT on known tables, timeouts and row limits. The common thread is that LLM failures are quiet, so each feature needs a way to notice them.

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 "Name four common LLM use cases in enterprise Java applications and, for each, one way it...": https://scrivio-interview-library.netlify.app/spring-boot/llm-fundamentals/e40db77fd6/