Post

Comparing LLMs in Practice: Designing and Implementing a Benchmark

When we build an application with a large language model (LLM), we have to decide which model will do the work. The model might answer questions about documents, extract information from text, or help a customer find a solution to a problem. Two models can perform the same task differently. One might respond more quickly, while another follows instructions more closely or makes fewer mistakes.

As new models become available, we may want to replace the one our application uses today. A new model might be less expensive or perform better on a public benchmark. Those are good reasons to consider it, but they tell us little about how it will handle the particular inputs and requirements of our application. Trying a few prompts gives us an initial impression. How can we make a comparison that we can repeat and explain?

Suppose your application answers questions about résumés. A new model responds faster than the one you use today. You give it a résumé that lists a Kubernetes workshop and ask which Kubernetes certification the person earned. It replies, confidently, that the person is a Certified Kubernetes Administrator. The source lists no certification. Would you still switch?

A benchmark is a planned set of tasks and checks that we use to measure performance. By giving both models the same work and checking the results against requirements we can explain, we can make a more informed decision. We’ll design a small benchmark for the résumé question-answering feature, score a few answers by hand, and read the kind of report you could use to decide whether to ship a model change.

This article is accompanied by a small C# application in the AI Engineering Training repository. The repository contains source code, sample data, instructions, and tests for the experiment we’ll work through here. You can follow the examples without running the code, then use the companion project to compare two real models yourself. We’ll refer to parts of the project as we introduce the benchmark and return to it in Section 7 to run the experiment.

1 What would block the release

Before measuring a model, think about what happens to its answers after it produces them. A mistake that is acceptable in one application may have serious consequences in another. A model that writes a useful draft for a person to edit has a different responsibility from one whose answer is used directly by another program.

In our example, a person supplies a résumé and asks a question about it. The model must answer from that résumé rather than draw on its general knowledge or fill in missing details. A downstream program reads the answer as JSON, a text format for representing structured data, and a person may use the result to decide whether a candidate meets a requirement. Those two uses give us two distinct obligations. The answer must fit the software contract, and its claims must be supported by the résumé.

What would make you decide against using a new model? Write your decision rule before you see either model’s score. For this exercise, suppose inventing a certification on an explicitly unanswerable case blocks the release. We’ll consider a latency improvement, meaning a reduction in the time it takes to get a reply, once that case passes and the remaining errors have been reviewed. Your own application might put a different requirement first. A support bot that frequently times out has a reliability problem even when every completed answer is accurate.

We also need a point of comparison. The baseline is the model currently in use. The candidate is the model you are considering. Evaluating them on the same task makes the baseline a practical reference. It lets you inspect whether the candidate fails some of the very cases the baseline handles. To do that, we first need to decide what a good answer to each question would look like.

2 Build a test set with known answers

If we ask two models a question and then choose the reply that sounds more convincing, we may end up rewarding a well-written mistake. We need an answer key that is independent of either model. We can prepare it in advance by reading each résumé and deciding which information a reply should contain and which claims would be incorrect.

A golden dataset is a collection of inputs with reviewed expectations. Each example in the dataset is called a test case. For each case, record:

  • The source résumé and the question we will ask.
  • The facts a good answer must include.
  • Likely false claims worth checking.
  • Whether we expect one particular answer or need to check the individual facts.

Include examples that exercise the decisions your application gets wrong in practice. Here are three kinds of cases from our dataset.

Case

What the source says

What a good answer does

Certification lookup

Elin completed the Azure Administrator Associate certification.

Returns the certification named in the source.

Missing certification

Luca completed a Kubernetes workshop. The résumé lists no formal certification.

Reports that the requested information is missing.

Two facts after an outage

Tari wrote a runbook and added a latency alert. A rollback rehearsal happened the following week.

Includes both requested changes and leaves the rehearsal out of the answer.

To compare the replies consistently, we ask the models to follow a common response contract. Each reply should be one JSON object with three fields:

  • answer: A concise answer.
  • facts: A list of relevant facts copied from the résumé.
  • quote: An excerpt intended to support the answer.

Having separate fields lets the application read and check each part.

What should happen when the information is missing? We want the model to abstain, meaning it should report that the source does not support an answer rather than guess. The missing-certification case gives abstention a concrete meaning. For Luca’s question, the expected response is the object below. In JSON, null represents the absence of a value. The empty fact list expresses a deliberate decision about what the source supports.

{
  "answer": null,
  "facts": [],
  "quote": null
}

The outage case tests a different skill. We ask what two things Tari added after the outage. An answer that mentions only the runbook captures one of two required facts. A model may also confuse the later rollback rehearsal with the two things Tari added. Keeping these cases separate makes it easier to see whether a model struggles with missing information, incomplete answers, or distracting details.

Imagine asking Elin which certification she completed. We know the name of the certification, so we can compare the model’s answer with that name. We call this a closed-form question. Luca’s question works the same way, except that we expect no answer because his résumé names no certification. Tari’s question is different. There are two facts we want to see, but the model can express the answer in more than one way. We can check those facts without requiring the whole answer to have one particular wording.

The companion dataset records this distinction. Each case has an id, resumeText, and question. Its answer key contains expectedFacts, forbiddenFacts, closedForm, and expectedAnswer. Think of closedForm as a switch that tells the scorer whether to check for one exact answer:

  • true: Compare the answer with expectedAnswer. For Elin, this is the certification name. For Luca, it is null, because the information is missing.
  • false: Do not compare the answer with one exact value. For Tari, expectedAnswer is also null, but the two required facts still need to be checked.

The same null value therefore has two different meanings in the answer key. The closedForm field tells us which one applies.

An answer key can contain mistakes too. If we list a fact as required when it does not appear in the résumé, we could penalize a model for doing exactly what we asked. Before making any model requests, the application checks that:

  • The dataset contains between one and twenty cases.
  • Every case has a unique, nonblank ID, a résumé, and a question.
  • Both fact lists are present, contain no blank or duplicate entries, and all expected facts appear in the source.
  • None of the forbidden phrases appears in the source.
  • For a question with one exact expected answer, that answer appears in the expected fact list. If the expected answer is null, the expected fact list must be empty.

These checks catch some mistakes in the dataset before we make any model requests. You still need to read the source and decide whether the answer key is appropriate.

3 Give both models the same work

Now that we have questions and reviewed expectations, we can give the models some work. Suppose we give the baseline a short question and the candidate a more detailed instruction explaining how to handle missing information. If the candidate performs better, how would we know whether the improvement came from the model or the instruction?

For each case, give both models the same conditions:

  • Use the same source résumé, question, and instructions.
  • Use the same temperature, a generation setting that influences how much variation we may see in the model’s choices.
  • Use the same output limit, which caps the number of tokens, or units of text, the model can generate.
  • Present the cases in the same order.
  • Start a fresh conversation for every answer so that an earlier question cannot help with a later one.

In this comparison, the model is the variable we change.

The companion project prepares all the selected prompts before either model runs. The shared instructions ask the model to answer only from the résumé, copy the relevant facts and one supporting quotation, and use null and an empty fact list when the information is missing. Each prepared prompt contains the résumé and question. The answer key stays with the scorer; giving it to the model would defeat the purpose of the test.

To send the requests, the project uses Microsoft Agent Framework, a .NET framework for working with AI agents. In BenchmarkRequest.cs, a ChatClientAgent uses the same ChatOptions for both models: a temperature of 0.2 and a limit of 768 output tokens. The application reuses a client and agent for each model, but calls RunAsync without a session so each answer starts a fresh conversation.

If the candidate requires a rewritten prompt, the combined change can still be worth evaluating. Describe the comparison as one between two configurations, because the results now reflect a model change and a prompt change together. Keep the inputs and settings with the results so you can tell exactly what you compared when you revisit a surprising case. With the requests prepared, we can turn our attention to the replies.

4 Check format facts and evidence separately

When a model returns an answer, we could read it and mark it as right or wrong. That would be a useful judgment, but it would not tell us much about what went wrong. A reply can contain the correct information and still be unusable by our program. Another can arrive in exactly the requested format and contain an invented certification. We want to see those failures separately.

Read a response the way the application will use it. There are several questions we can ask:

  • Can a JSON parser read it?
  • Does the result contain the required fields with the expected types?
  • Does it capture the required facts and give the expected answer when there is one?
  • Does it avoid the false claims listed in the answer key?
  • Can you find the quoted text in the original résumé, or did the model correctly report that the information was missing?

Each question describes a different check we can perform on the reply.

Start with the format. In this experiment, AnswerParser.cs first checks whether the reply is valid JSON and then checks its structure. A usable response must meet these requirements:

  • The JSON object contains exactly the three named properties: answer, facts, and quote.
  • answer and quote are either null or nonblank strings.
  • facts is an array of nonblank strings. An empty array is allowed.

The instructions request JSON; the application checks the returned text rather than relying on a provider-enforced schema. A reply with an extra confidence field, for example, can pass the JSON check and fail the shape check.

Once we have a usable object, we can look at its contents. Consider an answer that names the wrong certification and quotes the sentence where Elin completed her actual certification. A literal source-quote check can pass because the quotation exists. Read the quote beside the claim. The source names a different certification, so the quote fails to support the answer. Likewise, a forbidden-phrase check detects the claims you listed. A reviewer can recognize an equivalent claim phrased in a way the list misses.

Exact matching is useful when the expected answer is a known database name, date, or certification. For questions such as the outage example, scoring each required fact gives you partial credit you can interpret. A reply that lists “runbook” but not “latency alert” has matched one of two required facts. This tells us more than simply marking the answer as incorrect.

We need to decide what counts as a match. The experiment compares the expected facts with the individual strings in the fact list, ignoring letter case. “Latency Alert” matches “latency alert,” but “an alert for latency” does not. Exact answers are also compared without regard to letter case. The forbidden-phrase check looks for listed phrases anywhere in the answer and fact list, ignoring letter case.

For questions other than those where we expect a missing answer, the evidence check requires a non-null answer and a quotation that appears exactly in the source, including letter case. For Luca’s case, the evidence check instead requires the null answer, empty fact list, and null quote shown earlier.

What if the reply contains the information we asked for and some incorrect information as well? Suppose a reply to Tari’s question lists both required facts and also says that Tari added a rollback rehearsal. The source mentions the rehearsal, but it happened the following week. The fact recall can be perfect, and the listed forbidden phrase for this case is “automated failover,” not “rollback rehearsal.” Even a reply that passes the local checks can contain an incorrect claim. Fact recall tells you which required facts the reply included, not whether everything it included was correct.

The instructions ask for distinct facts copied from the source, but the parser does not check for duplicate facts, and the scorer does not check whether every returned fact appears in the source. What we ask a model to do and what we check it actually did are not always the same.

For some tasks, it can be useful to ask another language model to judge a reply. For example, deciding whether a summary is clear or whether it conveys the meaning of a long document can be difficult to express as a set of programming rules. In our experiment, however, we already know the expected facts, the listed false claims, and the response structure. We can perform these checks locally without making another model request.

BenchmarkScorer.cs uses Microsoft Agent Framework’s FunctionEvaluator to define rules and LocalEvaluator to apply them for the forbidden-phrase, evidence, and applicable exact-answer checks. The parser and required-fact matching run locally too. The scorer pairs each reply with its case ID, so a failed request cannot shift the answers for the cases that follow. Given the same reply and answer key, the checks produce the same result. This is called deterministic evaluation.

5 Read the denominators and the timing

After checking each reply, we have a collection of individual results. We could inspect every answer, but we also want a way to compare how the models performed across the whole test set. A metric summarizes one aspect of that performance. To interpret a rate, we need to know both what we counted and what we divided by.

Suppose four of five responses have the right object shape and the fifth times out. The shape success rate is four out of five attempts. If one of the four usable objects contains a listed false claim, the false-claim rate among those objects is one out of four. Report the timeout in the error rate as well. The denominators answer different questions about what the application received. We cannot tell whether an unusable reply contains a listed false claim using the same structured check.

Required-fact recall measures how much of the expected information the replies contain. Add up the number of matching facts and divide by the number expected across the attempted cases. A timeout earns zero facts for its case. If the selected cases contain no expected facts, the recall denominator is zero and the measure is unavailable. Missing-answer cases still contribute to the checks that apply to them.

Other success rates use different groups of replies or cases:

  • JSON and shape success rates use all attempts.
  • Exact-match rate uses all attempted cases for which closedForm is true, including questions where the expected answer is null.
  • Evidence pass rate uses all attempts, including those that cannot be scored.

A measure without applicable observations is reported as N/A. These are separate measures rather than parts of one overall quality score.

Accuracy is only one part of the comparison. If a person is waiting for an answer, the time the model takes to respond matters too. An average can hide the occasional slow reply, so the experiment reports two percentiles of the measured elapsed times. A percentile describes a position in the ordered measurements. P50 is the median elapsed time, and P95 describes the slow end of the measured responses.

With five completed samples, the slowest reply can strongly influence P95. For example, the sorted times 0.70, 0.80, 0.85, 1.05, and 1.55 seconds have a P50 of 0.85 seconds. The experiment uses linear interpolation, which places P95 four fifths of the way from 1.05 to 1.55, at 1.45 seconds. Read latency together with errors, because the experiment calculates percentiles only from replies without a request error. A model that times out on the difficult questions could otherwise appear faster than it really is on the full workload.

The experiment counts the following as request errors:

  • A timeout or provider exception.
  • An empty final assistant reply.
  • A reply that ends at the output token limit.

A completed reply with malformed JSON fails the format checks without counting as a request error, and its elapsed time still contributes to the latency measurements. The stopwatch covers the request, including retries, but not the local scoring.

We may also want to know how much text the models process and generate. When the provider supplies input and output token counts, the application records them with each reply. This can help us investigate differences in usage, although the experiment does not convert those counts into a monetary cost.

6 Inspect the case behind the score

We now have several measurements for comparing two models. Before choosing one, it helps to see how those measurements relate to the behavior we wanted in the first place. A summary can make two models look similar while concealing an important difference in how they handle a particular question.

Imagine the following results from the first five résumé questions. Both models return usable objects on all five cases, and the candidate invents one of the listed certifications on the missing-answer case. These are illustrative results, not measurements from a live run.

Measure

Baseline

Candidate

Objects with the required shape

5 of 5

5 of 5

Required facts found

5 of 5

5 of 5

Exact answers matched

4 of 4

3 of 4

Replies with a listed false claim

0 of 5

1 of 5

Median response time

1.40 seconds

0.85 seconds

The candidate looks equal on fact recall because the missing-certification case contributes zero expected facts. Its faster median is useful, but the invented certification triggers the release rule we wrote at the start. Open that raw reply and read it beside the résumé. You can now name the problem to investigate and add variations that test whether it recurs when the résumé implies an absence less explicitly.

Notice that the missing-answer case can fail both exact matching and the evidence check, even though no required facts are missing. The experiment leaves the release decision to you. A comparison with no request errors can finish with exit code 0, the conventional signal of successful program execution, even if a model gives incorrect answers. If you later use the benchmark in a deployment pipeline, you will need to turn your release rule into an explicit quality check. Running the benchmark successfully is not the same as meeting the requirements for release.

Five cases are enough to learn to read this report. To make a release decision for a real application, use cases from the work it actually performs, cover rare failures with high consequences, and repeat timing measurements under comparable conditions. A saved result can tell you what happened on that run. Repeated runs give you evidence about how often it happens.

There are other reasons to be careful when reading the timing results. The companion experiment runs the baseline’s cases before the candidate’s. Provider load and network conditions may change between those runs, so one difference in response time does not establish that a model is consistently faster. The seed, a setting some model APIs use to control randomness, is unset. Even with the same prompts and generation settings, the replies can vary.

7 Compare two models in the companion project

So far, we have worked through the steps of a benchmark using a few examples. We prepared an answer key, decided what to check, and read the results in light of a release requirement. We can now use a small application to perform the same steps without sending each prompt and checking every reply by hand.

The companion C# experiment lives in 08-llm-benchmarking/llm-benchmarking in the AI Engineering Training repository. The test data in SampleData/GoldenCases.json has twenty fictional examples. The application validates the entire dataset and prepares the first five prompts for the default run. It uses Microsoft Agent Framework to collect answers and applies local checks to the raw replies, so the scoring stage needs no judge model. Microsoft Agent Framework local evaluators

Follow a question through the source files. Program.cs loads the dataset, calls DatasetValidator.cs to check it, and uses PromptPreparer.cs to prepare the common prompts. BenchmarkRequest.cs collects the replies for one model, AnswerParser.cs and BenchmarkScorer.cs check those replies, and MetricsCalculator.cs calculates the measurements we have discussed. The process repeats for the other model. Program.cs saves the report, and OutputPrinter.cs presents the two summaries and individual cases.

Keeping the request and scoring stages separate means you can test the scoring rules without making a model request. It also makes it easier to locate the source of a problem when a particular result looks surprising.

To run the experiment, we need access to two models through a model provider, the service that receives our prompts and returns the replies. Use the .NET 10 SDK and the project README’s shared settings instructions to configure a baseline and a different candidate from the same provider.

Run dotnet run from the application folder. The console shows both models and the request plan before asking you to type RUN. Five cases for two models make ten model calls, with up to thirty HTTP attempts if every call uses both retries. A retry is another attempt to send a request after certain failures. The remote provider receives the fictional résumé and question for each call. Check the plan before confirming, since model requests may incur charges.

The shared settings use OPENROUTER_MODEL and OPENROUTER_COMPARISON_MODEL for OpenRouter, or GEMINI_MODEL and GEMINI_COMPARISON_MODEL for Gemini. Choose models that accept the common generation settings. Each model call has a 120-second deadline, including retry waits, as described in the README. To change the number of cases, edit caseCountInt in Program.cs. Selecting all twenty gives forty model calls, with up to 120 HTTP attempts.

Start with the two summary rows, then find certification-missing and incident-facts in the per-case output. Look at the individual checks and the raw replies together. The saved JSON report includes the raw replies, case results, model IDs, generation settings, and fingerprints of the dataset and ordered prompts. The summary leaves cost unavailable, so compare pricing separately if your decision depends on it.

Suppose you run the experiment next week and notice that the scores have changed. Did the models behave differently, or did someone change the test data or instructions? The report is saved beside the executable as benchmark-results-*.json and includes two fingerprints. Each is a SHA-256 hash, a value calculated from the contents so that we can check whether those contents have changed.

The two fingerprints answer different questions:

  • Dataset fingerprint: Changing the answer key changes this fingerprint even if the prompts stay the same.
  • Prompt fingerprint: Changing the instructions or the order of the prepared prompts changes this fingerprint.

The report does not include the full source texts, answer keys, or prompts, so keep the corresponding dataset and source code with it. Identical fingerprints do not guarantee identical replies. OpenRouter can route requests to different upstream deployments, so the results describe the configured models as the provider serves them.

Before relying on the scorer to evaluate a model, how do we know that the scorer itself works? We can give it examples whose results we already know and check whether it calculates the expected scores. The companion xUnit tests exercise the dataset validator, parser, local scoring rules, and metric calculations.

A request test uses the OpenRouter client to capture the outgoing HTTP bodies for two models and checks that they are identical once the model identifier is removed. It also checks that each question has only two messages and contains its own question. Another test checks that a failed request earns no fact credit. The tests use simulated HTTP responses and need no live model calls. The README gives the command to run them from the repository root.

8 Make the release decision yourself

A benchmark is most useful when we use its results to improve the way we test and build the application. Finding a failure tells us something about the model, but it may also tell us that our test cases or scoring rules need more work. Let’s use the companion project to make a small release decision and then investigate one of its limitations.

Use the following steps to make your first release decision:

  • Before running the experiment, write down one failure that would block your model change.
  • Pick an example where that failure could occur and write the expected answer using the source.
  • After the run, compare both replies to your expectation, then see which of the program’s checks found the problem.
  • Save the report with a one-sentence decision that names the case and your reason.

For a second run, keep the models and settings fixed. In SampleData/GoldenCases.json, make these changes to the missing-certification case:

  • Change the résumé so that becoming a Certified Kubernetes Administrator is a future goal rather than a certification Luca has earned.
  • Remove “Certified Kubernetes Administrator” from the case’s forbiddenFacts list, since the validator requires forbidden phrases to be absent from the source.
  • Keep the question unchanged, closedForm set to true, expectedFacts empty, and expectedAnswer set to null.

Would your release rule catch a response that turns the goal into an earned certification? Check the exact-match and evidence results even if the forbidden-phrase check passes. The literal phrase can now appear in the source without supporting the claim that Luca earned the certification. The answer tells you where to improve the benchmark before you rely on it for the next model change.

When another model becomes available, you will have more than a few impressions from trying prompts. You will have a set of reviewed examples, a record of how the models performed, and a reason you can explain for your decision.

0 Comments
Leave a Reply

Your e-mail address will not be published. Required fields are marked *