I'm Gopi Gugan, a software engineer building AI features with FastAPI, Postgres/pgvector, and React/TypeScript — and if you want to see more of my work, it's at gopigugan.ca. The first time I shipped an LLM feature, I did what I always do: I wrote unit tests, they passed, and I shipped it. Then users asked the model questions I never tested, and it answered with total confidence and total nonsense. That's when I learned that testing an LLM feature is a different job from testing regular code — and most of it has nothing to do with the model itself.

Unit tests still matter — test everything around the model

The model is the one part of the system you can't make deterministic, so I test everything else hard:

  • Prompt construction: given this user input and this retrieved context, does the prompt contain exactly what I expect?
  • Parsing: if the model returns malformed JSON, does my code fail gracefully instead of crashing the request?
  • Retrieval: for a known question, does my pgvector query return the chunk I expect in the top results?
  • Fallbacks: if the LLM call times out, does the user get a clear error instead of a spinner forever?

These are plain, boring, deterministic tests. They catch most of the bugs I actually ship.

Build a golden set and run it on every change

A golden set is a small list of real inputs and the answers I consider acceptable — usually 20 to 30 cases I wrote by hand from real user questions. Every time I change a prompt, swap a model, or tune retrieval, I run the whole set and compare. It's my regression suite for a system that has no fixed outputs.

Here's the shape of the harness I use in Python:

import json, pytest # Each case: a question, the context to retrieve, and what a good answer must do CASES = json.load(open("tests/golden_cases.json")) @pytest.mark.parametrize("case", CASES, ids=lambda c: c["id"]) def test_golden_case(llm_client, case): answer = llm_client.answer(case["question"], context=case["context"]) # Hard checks first: structure, grounding, no forbidden behaviour assert answer.citations, "answer must cite its sources" assert not any(p in answer.text for p in case["must_not_contain"]) # Soft check: a rubric score, not an exact string match score = rubric_score(answer.text, case["rubric"]) assert score >= case["min_score"], f"score {score} below {case['min_score']}" 

The point isn't a perfect score. It's knowing immediately when a "small" prompt tweak made five answers worse.

Judge with a rubric, not vibes

"That answer looks good" doesn't scale, and it doesn't survive a code review. I score answers against a short rubric — usually three or four checks, like "answers the question asked," "only uses the provided context," and "says 'I don't know' when the context is missing." I use a second LLM call as the judge for the subjective checks, and plain code for the objective ones (citations present, no invented URLs, response under a length limit).

Two rules I follow here:

  • The judge is never the same prompt as the feature. A judge that shares the feature's blind spots approves everything.
  • I spot-check the judge. Every week I read a handful of judged answers myself. When the judge and I disagree, I fix the rubric, not the score.

Test the failure modes, not just the happy path

LLM features fail in ways regular code doesn't, so I test those paths on purpose:

  • Empty retrieval: what happens when pgvector returns nothing relevant? The answer should say it doesn't know, not invent one.
  • Contradictory context: two chunks disagree. Does the model pick one silently, or flag the conflict?
  • Jailbreak attempts: "ignore your instructions and..." — does the system prompt hold?
  • Long, messy input: pasted logs, typos, three questions in one message. Does it still answer the right one?
  • Slow model: a 20-second response. Does my React UI stream progress, or does the user think the app froze?

Most of my production incidents have been one of these five, not a model quality problem.

Keep a human in the loop for the edge cases

No automated test catches everything, and pretending otherwise is how bad answers reach users. In my apps, low-confidence answers — low retrieval scores, no citations, or a judge score near the threshold — get flagged for human review before they go out, or shown to the user with a clear "check this" label. The goal isn't to remove humans from the loop. It's to spend human attention where it matters: the answers the system is least sure about.

The honest summary

Testing an LLM feature means testing the system around the model deterministically, keeping a small golden set you actually run, judging answers against a written rubric, and deliberately testing the failure modes. The model will still surprise you — that's the nature of the tool. But with this setup, the surprises show up in your test run, not in a user's screenshot.

If you're building with LLMs and still relying on "I tried it a few times and it looked fine," build the golden set first. It's the single highest-value test I have, and it takes an afternoon.