AIForum.

How to Set Up a Local LLM Evaluation Harness with Ollama and Python

On this page

THE SHORT ANSWER

A local LLM evaluation harness runs a fixed set of prompts through a model on your own machine and scores the outputs automatically, so prompt or model changes cannot silently degrade quality. This guide walks through the architecture used by two public references: a pytest-based harness with five scorers targeting Ollama, and a LangChain v1 tutorial that pairs rule-based assertions with an LLM-as-a-judge.
Quick facts

A local LLM evaluation harness is a repeatable test suite that sends a fixed set of prompts through a model running on your own machine, scores each response automatically, and fails when quality drops. The practical reason to build one is regression detection: an agent can behave differently across runs, and small prompt or model changes introduce regressions that are easy to miss without a repeatable way to test multiple inputs and score the outputs. That is the problem the freeCodeCamp tutorial on evaluating AI agents with an LLM-as-a-judge harness sets out to solve, using LangChain v1, Ollama, Qwen, and Python entirely on local hardware so there are no API costs.

The second useful reference is the sbezjak/llm-eval-harness project, a pytest-based harness that runs a fixed golden set through a local model, scores outputs with five different scorers, and encodes each scorer’s known limitations as xfail(strict=True) tests so silent regressions break the build. It targets Ollama at localhost:11434 and is written for Python 3.11+ managed with uv. This article combines both approaches into a step-by-step setup you can adapt.

What a local evaluation harness actually does

An evaluation harness has four moving parts: a dataset of prompts with expected or graded answers (often called a golden set), a runner that sends each prompt to the model, one or more scorers that convert an output into a number or a pass/fail verdict, and a test runner that reports the aggregate result. The freeCodeCamp tutorial describes this as a Python script, a list of test cases, rule-based checks, and an LLM-as-judge, printing a clear pass/fail summary. The llm-eval-harness project implements the same idea on top of pytest, which means ordinary test tooling — markers, fixtures, HTML reports, coverage — comes for free.

Running it locally matters for three reasons. First, you avoid per-call API costs while iterating. Second, prompts and outputs stay on your machine, which simplifies handling of sensitive test data. Third, you control the exact model version, so a score change can be attributed to your change rather than a provider-side update. The tradeoff is that local scoring is limited by the hardware you have and by the quality of the local judge model you choose.

Prerequisites and environment

Before writing any tests, confirm the following:

  • Ollama installed and running. Both references use Ollama as the model backend. The harness project assumes it is reachable at localhost:11434.
  • Python 3.11 or newer. The reference harness specifies Python 3.11+ and manages dependencies with uv.
  • A model pulled locally. The harness quickstart uses llama3.2, described as roughly a 2 GB one-time download. The freeCodeCamp tutorial uses a Qwen model and notes that smaller Qwen variants can run on lower-memory machines.
  • Disk and memory headroom. Model weights are only part of the footprint; the runtime also needs memory for context and key/value cache, so plan for more than the download size.

If you are new to running models locally, verify Ollama works on its own before adding a test framework on top. Debugging a model server and a test suite at the same time is unnecessarily painful.

Step 1 — Install Ollama and pull a model

Install Ollama for your operating system, start the service, and pull a small instruct model. In the reference harness the command is:

ollama pull llama3.2

The comment in that quickstart marks this as a one-time, roughly 2 GB download needed only for live tests. Confirm the server responds before continuing — if localhost:11434 is not answering, every subsequent test will fail with a connection error rather than a scoring error, which is a misleading signal.

Step 2 — Create the Python project and test runner

The harness project uses uv for dependency management. Its quickstart begins with:

uv sync

That installs runtime and development dependencies. If you prefer plain pip and a virtual environment, the same structure applies; the important part is that pytest, your Ollama client, and your scorer libraries are declared as project dependencies rather than installed ad hoc.

The lint and format commands in the reference are uv run ruff check . and uv run ruff format .. Keeping lint separate from evaluation is deliberate: style failures and quality regressions are different signals.

Step 3 — Define a small golden set

The reference harness calibrates its scorers against a 10-item golden set with human-graded labels. Ten items is small, but it is enough to detect gross regressions and to sanity-check that a scorer behaves as expected. Start with cases where you can articulate what a correct answer looks like, then add adversarial or ambiguous cases once the pipeline is stable.

Store each case as structured data — a prompt, an expected answer or reference text, and any metadata such as category or difficulty. Keeping the dataset separate from the test code lets you grow it without rewriting assertions.

Step 4 — Add scorers, from exact match to LLM-as-a-judge

The reference harness implements five scorers, each producing a different signal:

ScorerSignal
ExactMatchScoreroutput == expected
BleuScorersacrebleu n-gram overlap (BLEU-4)
RougeScorerrouge-score ROUGE-L F1
SemanticScorersentence-transformers cosine similarity
LLMJudgeScorerSecond Ollama call with a hybrid correctness/relevance rubric

These are complementary, not redundant. Exact match is unambiguous but brittle: a correct answer phrased differently fails. BLEU and ROUGE measure surface overlap against a reference and are sensitive to wording. Semantic similarity compares meaning via embeddings and tolerates paraphrase. The LLM judge is the most flexible and the most expensive, because it makes a second model call for every item. The freeCodeCamp tutorial pairs rule-based assertions with an LLM-as-a-judge for the same reason: cheap deterministic checks catch the obvious failures, and the judge handles the cases where there is no single right wording.

An illustrative minimal test using pytest looks like this:

# tests/test_eval.py — illustrative structure, not a tested example
import pytest

GOLDEN = [
    {"prompt": "What port does Ollama listen on by default?",
     "expected": "11434"},
]

def test_exact_match(ollama_client):
    for case in GOLDEN:
        output = ollama_client.generate(case["prompt"])
        assert output.strip() == case["expected"]

Note the distinction between this sketch and the reference projects: the harness above is a simplified illustration of the pattern, while the two cited sources are the actual implementations with their own file layouts and configuration.

Step 5 — Separate fast tests from live model tests

One of the most practical details in the reference harness is pytest marker usage. The quickstart lists three modes:

  • uv run pytest -m "not ollama" — fast path, no network, described as about 10 seconds.
  • uv run pytest -m ollama — live model only, described as about 7 minutes.
  • uv run pytest — the full suite.

This split matters. Scorer logic, dataset validation, and parsing can be tested without a model, so they run in seconds and can gate every commit. Anything that calls the model is slower and depends on a running server, so it belongs in a separate, explicitly requested pass. If you wire the live tests into a default CI job, expect intermittent failures whenever the model server is unavailable.

Step 6 — Run the suite and read the reports

The reference harness generates an HTML test report with coverage using:

uv run pytest 
  --html=reports/report.html --self-contained-html 
  --cov=eval_harness --cov-report=html:reports/coverage

An HTML report is more useful than console output for evaluation work because you can scan which cases failed and compare across runs. The freeCodeCamp tutorial likewise emphasizes a clear pass/fail summary as the primary output of the harness.

Encoding known scorer limits as strict xfail tests

The most distinctive design choice in llm-eval-harness is that each scorer’s known limitations are encoded as xfail(strict=True) tests, so silent regressions break the build. In pytest, xfail marks a test as expected to fail; with strict=True, the suite fails if that test unexpectedly passes. Applied to evaluation, this turns documented weaknesses into tripwires: if a scorer starts behaving differently than its documented limitation predicts, you are told immediately rather than discovering it after a model swap. It is a way of writing down what you know is imperfect instead of quietly ignoring it.

Limitations, tradeoffs, and what this cannot tell you

A local harness measures consistency against your own golden set. It does not establish general model quality, and a passing suite is not evidence that the model is correct on inputs you never wrote down. Several concrete tradeoffs deserve attention:

  • Golden set size. Ten items will catch gross regressions but will not characterize behavior across a domain. Expanding the set increases confidence and runtime.
  • Judge cost and bias. An LLM judge requires a second model call per item, which is why the live pass in the reference takes minutes rather than seconds. A local judge is also only as reliable as the model behind it.
  • Reference-based metrics. BLEU and ROUGE compare against a reference string; when multiple correct phrasings exist, they penalize valid answers.
  • Nondeterminism. The same input can produce different outputs across runs, so a single failure is a signal to investigate, not automatically a bug.
  • Version drift. Scores are only comparable when the model, quantization, and sampling settings are held constant. Record them alongside results.

Next steps

Start with the fast path: build a small golden set, implement exact match and one similarity scorer, and get pytest -m "not ollama" passing in seconds. Add the live-model marker and an LLM judge only after the offline layer is stable. Then expand the dataset with cases drawn from real failures you have seen, and record the model name, version, and settings next to every result so future comparisons are meaningful. If you hit a specific error — a connection refused on localhost:11434, a scorer returning unexpected values, or a strict xfail that flips — share your environment, model, and the exact output in the community so others can reproduce it.

FAQ

Do I need a GPU to run a local evaluation harness?

The cited sources do not specify hardware requirements. The harness quickstart uses llama3.2, described as roughly a 2 GB one-time download, and the freeCodeCamp tutorial notes that smaller Qwen variants can run on lower-memory machines. Ollama can run models without a dedicated GPU, but expect slower generation, which directly extends the runtime of live tests.

How many test cases should the golden set contain?

The reference harness uses 10 items with human-graded labels, which is enough to calibrate scorers and catch gross regressions. A larger set gives more confidence across a domain but increases runtime, especially for the LLM judge, which makes one model call per item.

Can the harness run in CI without a model server?

Yes, if you follow the marker split used by the reference harness. Tests marked with the ollama marker are excluded by uv run pytest -m "not ollama", which runs the fast, network-free path in roughly 10 seconds. The live pass is requested explicitly and takes about 7 minutes.

Why use both BLEU/ROUGE and an LLM judge?

Reference-based metrics like BLEU and ROUGE are cheap and deterministic but penalize valid answers that are phrased differently. An LLM judge handles paraphrase and rubric-based correctness but costs a second model call per item. Using both lets cheap checks catch obvious failures while the judge covers cases with no single right wording.

References

  1. https://github.com/sbezjak/llm-eval-harness
  2. https://www.freecodecamp.org/news/how-to-evaluate-ai-agents-with-an-llm-as-a-judge-harness-in-python/

Related terms

Golden set
A fixed collection of prompts paired with expected or human-graded answers, used as the reference for scoring model outputs.
LLM-as-a-judge
Using a second model call to grade an output against a rubric, typically for correctness and relevance, instead of comparing strings.
BLEU-4
An n-gram overlap metric computed with the sacrebleu library, used in the reference harness to compare generated text against a reference.
ROUGE-L F1
A recall-oriented overlap metric based on longest common subsequence, computed with the rouge-score library in the reference harness.
xfail(strict=True)
A pytest marker declaring that a test is expected to fail; with strict=True, the suite reports a failure if the test unexpectedly passes.

Leave a Reply

Your email address will not be published. Required fields are marked *