ai newsFr., 4. Dez.
EilmeldungAlibaba Releases Qwen4-35B-A3B: Open-Weight MoE Model With 1M Context

How I Test an LLM Feature So It Doesn't Break in Production - By Gopi Gugan

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 us

dev.toDonnerstag 22:58 · 03.12.3 Min. Lesezeit
Bild: dev.to

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.

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

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

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']}" Enter fullscreen mode Exit fullscreen mode The point isn't a perfect score. It's knowing immediately when a "small" prompt tweak made five answers worse.

"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).

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

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

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.

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.

Quelle: dev.to (dev.to). Original öffnen