Building an impressive demo with a large language model takes an afternoon. A prompt, a few documents and an API key, and the room is convinced. Then the feature meets real users, real data and real edge cases, and the problems start: wrong answers stated with confidence, slow responses, a bill that grows faster than usage, and no clear way to tell whether last week's change made things better or worse.
The gap between demo and product is mostly engineering, not model choice. These are the pieces that close it.
1. Define what "good" means
Before changing prompts or models, write down what the feature must do and how you will judge it. For a support assistant, that might be: answers only from the help centre, cites its source, says "I don't know" when the answer isn't there, and never shares another customer's data.
Turn this into an evaluation set: 50 to 200 real or realistic inputs with the expected behaviour for each. Include the easy cases, the awkward ones and the ones that should be refused. This set is the most valuable asset in the project. Every change is measured against it.
2. Ground the model in your data
Most business features should answer from your data, not from what the model learned during training. The common pattern is retrieval-augmented generation (RAG):
- Split your documents into passages and index them, using embeddings for meaning and often keyword search as well.
- For each question, retrieve the most relevant passages.
- Give the model those passages and instruct it to answer only from them, citing which one it used.
Retrieval quality decides answer quality. Most "the AI is wrong" problems turn out to be "the right passage wasn't retrieved". Measure retrieval separately: for each question in your evaluation set, did the correct passage appear in the top results?
Practical details matter here: sensible chunk sizes, keeping titles and section headings with each passage, filtering by permissions before retrieval, and re-indexing when documents change.
3. Evaluate on every change
Run the evaluation set automatically whenever the prompt, model, retrieval or code changes, just like unit tests.
- Deterministic checks for anything you can check with code: valid JSON, required fields present, a citation included, no banned phrases.
- Reference comparisons where there is a known correct answer, such as an extracted invoice number or a classification label.
- Model-graded checks for open-ended answers, where a second model scores faithfulness to the sources. These are useful but imperfect, so review a sample by hand and check the grader agrees with people.
Track scores over time. A model upgrade that improves average quality but breaks five important cases is a regression, and you will only see it if you measure.
4. Add guardrails and fallbacks
Assume the model will sometimes be wrong, and design for it:
- Structured output. Ask for JSON that matches a schema and validate it. Retry or fall back if it doesn't parse.
- Confidence and refusal. Let the model say it can't answer, and treat that as a correct outcome, not a failure.
- Human review for high-stakes actions. The model drafts; a person approves before anything is sent, filed or paid.
- Prompt injection defences. Treat user input and retrieved documents as untrusted. Don't let text inside a document grant the model new permissions, and limit which tools or actions it can trigger.
- Data boundaries. Enforce access control in your code, not in the prompt. The model should never see data the user isn't allowed to see.
5. Control latency and cost
Production traffic changes the economics quickly. The levers that matter most:
- Right-size the model. Use a smaller, faster model for classification, routing and extraction, and reserve the largest model for the hardest steps.
- Cache repeated work: embeddings, retrieved passages, and full answers to common questions.
- Trim the context. Sending fewer, better passages is cheaper and often more accurate than sending everything.
- Stream responses so users see output immediately, even when the full answer takes a few seconds.
- Set budgets. Limit tokens per request and per user, and alert when spend per day moves outside the expected range.
6. Monitor in production
Log every request with its inputs, retrieved passages, model, prompt version, output, latency and cost, with sensitive data masked where needed. Then watch:
- user feedback such as thumbs up or down, edits and abandoned sessions
- refusal and error rates
- latency and cost per request
- a weekly sample of conversations reviewed by someone who knows the domain
Feed failures back into the evaluation set. Over a few months it becomes a precise description of what your users actually need.
7. Plan for privacy
For sensitive data, check how your model provider handles it: data retention, whether inputs are used for training, and where processing happens. Enterprise agreements and regional deployments cover most needs. For stricter requirements, open models can run inside your own cloud account.
A realistic path
- Week 1–2: define success, build the evaluation set, prototype on real data.
- Week 3–6: build retrieval, guardrails and the evaluation pipeline, and release to internal users.
- Then: release gradually to customers with monitoring in place, and improve against the evaluation set every cycle.
The model is one component. The evaluation set, retrieval, guardrails and monitoring around it are what make the feature trustworthy, and they are what let you switch to a better model later with confidence.
We build LLM features, document extraction and automation as part of our data and AI work, including for compliance teams where every answer must trace back to its source. If you have a prototype that needs to grow up, get in touch.