Mehmet Ali Demirci
TR
← All posts

Adding an AI feature is easy, keeping it reliable is hard: evaluation infrastructure for LLM integrations

Adding an AI feature to a product now takes an afternoon. Get an API key, write a prompt, and the demo works. The hard part starts later: does the feature still work on day thirty, on a thousand different inputs, after the model version changes?

The gap I see most often in software companies is this: an LLM integration is tested like an ordinary function, which means it is not tested at all. This post describes five practical pieces I use to close that gap.

1. Why classic tests are not enough

A classic unit test expects the same output for the same input. LLM output is probabilistic. Three problems follow:

2. A golden set

The first step is a list of real inputs for which you know the correct answer. You do not need hundreds; start with 50-100 well-chosen examples.

The evaluation script gives each example to the model, compares the answer with the expected one, and produces one accuracy number. When the prompt or model changes, you compare this number with the previous one. If it dropped, you roll the change back.

3. Force a structure and validate the output

Wiring free-text answers into code is fragile. Ask the model for a predefined JSON schema and validate the answer with your own code. The model follows the schema "usually", not "always".

$answer = json_decode($model->reply($input), true);

$valid = is_array($answer)
    && in_array($answer['category'] ?? null, $allowedCategories, true)
    && is_numeric($answer['confidence'] ?? null);

if (! $valid) {
    return $this->ruleBasedFallback($input); // do not trust the model answer
}

The key point is the allowed-values list. If the model invents a category that is not on the list, the system must reject it.

4. A fallback path: if the AI fails, the product must not

External APIs slow down, quotas run out, providers have outages. The feature needs three states:

  1. Model answered and the answer passed validation: use it.
  2. Answer invalid or confidence low: fall back to rules, or ask the user.
  3. Model unreachable: turn the feature off quietly and keep the main flow working.

Showing a low-confidence answer as a "suggestion" instead of applying it automatically sharply reduces the cost of a mistake. The user confirms with one click; if it is wrong they correct it, and that correction goes into the golden set.

5. Measure cost and latency from the start

Takeaway for a software company

Treat an AI feature not as "an API call" but as a measurable component. In practice that means: a golden set, a validation layer, a fallback path and a cost log. Without these four, the feature works in the demo and cannot be trusted in production.

If you want to build this infrastructure in your team, or review an existing LLM integration, you can write to me through the contact form.