nemr.app

AIEngineering

Shipping LLM Features to Production: Evals, Guardrails and the Boring Parts

· 5 min read · by Elias Nemr

What separates an LLM demo from a production feature: evals, structured outputs, retrieval quality, guardrails, cost and latency budgets, and observability.

Getting a language model to do something impressive in a demo takes an afternoon. Getting it to do something reliably, for real users, at a sustainable cost, without embarrassing anyone — that takes engineering. Almost none of that engineering is about the model itself.

These are the pieces I'd put in place before calling an LLM feature "production-ready". They're deliberately unglamorous.

The demo trap

A demo is a handful of hand-picked inputs where the model happens to do well. Production is the long tail: typos, other languages, adversarial users, empty inputs, 40-page pastes, and the one request that makes the model confidently invent something. The gap between the two is where trust is won or lost, and you can only close it if you can measure quality.

1. Write evals before you tune prompts

An eval is a repeatable test that tells you whether the feature is getting better or worse. Without one, every prompt tweak is a guess, and every model upgrade is a gamble.

  • Build a golden set. Start with 30–100 real (or realistic) inputs with known-good outputs or clear pass/fail criteria. Include the awkward cases on purpose. Grow it every time something breaks in production.
  • Prefer checks you can compute. Does the output parse? Does it include the required fields? Does it cite a source that exists? Is it under the length limit? Cheap, deterministic checks catch a surprising amount.
  • Use model-graded evals carefully. A model judging another model's output scales well for subjective qualities (tone, helpfulness), but judges have biases — they favour longer answers, their own style, and the first option shown. Calibrate against human labels on a sample, and randomise ordering.
  • Run evals in CI. A prompt or model change that drops the score should fail the build just like a failing unit test.
for (const c of goldenSet) {
  const out = await runFeature(c.input);
  results.push({
    id: c.id,
    parsed: schema.safeParse(out).success,
    mustMention: c.mustMention.every((s) => out.text.includes(s)),
    forbidden: !c.forbidden.some((s) => out.text.includes(s)),
  });
}
report(results); // fail the run if the pass-rate drops below the baseline

2. Constrain the output

Free-form text is hard to build software on. Wherever your code consumes the result, ask for structured output (JSON that matches a schema), validate it, and decide up front what happens when validation fails: retry with the error message, fall back to a simpler path, or surface a graceful failure. Never pass raw model text into a SQL query, a shell command or an HTML template.

3. Treat retrieval as its own system

If your feature answers questions from your own documents (retrieval-augmented generation), most "hallucinations" are actually retrieval failures: the right passage never made it into the prompt. Evaluate retrieval separately from generation. Does the correct chunk appear in the top-k results? How often? Improvements to chunking, metadata filtering and query rewriting usually beat prompt wordsmithing. And require the model to say "I don't know" — and test that it does — when the context doesn't contain the answer.

4. Assume the input is hostile

Prompt injection is the defining security problem of LLM apps: any text the model reads — a web page, an email, a PDF, a user message — can contain instructions, and the model can't reliably tell your instructions from theirs. You can't fully solve this at the prompt level, so design around it:

  • Least privilege for tools. If a model can send email, delete records or spend money, assume it can be tricked into doing so. Give it the narrowest possible permissions and require confirmation for anything destructive or irreversible.
  • Separate untrusted content from instructions, and label it clearly in the prompt — it reduces, but doesn't remove, the risk.
  • Treat output as untrusted. Escape it, validate it, and never execute it blindly.
  • Watch for data exfiltration routes, like model-generated links or images that carry private data in a URL.

5. Budget for cost and latency

LLM calls are slow and metered. Decide your latency and cost targets per request before launch, then design to them:

  • Right-size the model. Use a smaller, faster model for easy steps (classification, extraction, routing) and reserve the big one for hard reasoning.
  • Cache. Exact-match caches for repeated requests, and provider-side prompt caching for long, stable prefixes.
  • Stream responses so users see progress immediately. Perceived latency matters more than total latency.
  • Set timeouts, retries with backoff and a fallback (another model, a cached answer, or a non-AI path). Providers have outages; your feature shouldn't go down with them.
  • Cap output length and input size so one pathological request can't burn your budget.

6. Make it observable

When a user says "it gave me a weird answer", you need to be able to find that exact request. Log (with appropriate privacy handling) the full prompt, retrieved context, model and version, parameters, output, latency, token counts and cost. Version your prompts like code, so every output can be traced to the prompt and model that produced it. Add a thumbs-up/down control and feed the bad cases straight into your golden set.

7. Keep a human in the loop where it matters

For high-stakes outputs — medical, legal, financial, anything irreversible — the model should draft and a person should decide. For lower-stakes ones, show confidence appropriately, make it easy to correct the output, and make it obvious it's AI-generated. A feature that's honest about its limits earns more trust than one that sounds sure of everything.

8. Roll out gradually

  • Shadow mode: run the feature on real traffic without showing results, and compare against your baseline.
  • Feature flags and percentage rollouts so you can ramp up — and turn off — without a deploy.
  • Re-run evals on every model upgrade. A "better" model can still regress on your specific task.

The checklist

  • Golden set and automated evals, run in CI.
  • Structured, validated output with a defined failure path.
  • Retrieval measured separately from generation; "I don't know" tested.
  • Least-privilege tools, untrusted-input handling, no blind execution of output.
  • Latency and cost budgets, caching, streaming, timeouts and fallbacks.
  • Full request logging, versioned prompts, user feedback loop.
  • Human review for high-stakes actions; staged rollout behind flags.

None of this makes the model smarter. It makes the system trustworthy, and that's what users actually experience. The teams that ship good AI features are rarely the ones with the cleverest prompts; they're the ones that treat the model as one unreliable component inside a well-tested piece of software.

Elias Nemr is a software engineer who has built and shipped products across Blockchain, Finance, E-Commerce, AI, Energy and Indie Games. More about him →

Found this useful? Buy me a coffee

Keep reading