MachineLearningMastery shows a lightweight LLM eval harness
MachineLearningMastery's Python tutorial builds a reusable LLM eval harness with exact-match scoring, rubric judging and regression tracking. See how.
Source: MachineLearningMasteryMachineLearningMastery has published a Python tutorial for building a small, reusable harness that evaluates prompts sent to large language models. The post, by Iván Palomares Carrascosa, argues that teams need a repeatable way to catch prompt regressions without adopting a heavy MLOps or observability stack.
What did MachineLearningMastery publish?
According to MachineLearningMastery, the tutorial walks through a harness of fewer than 150 lines of Python. It combines three checks: normalized exact-match scoring for deterministic tasks, a rubric-based LLM-as-a-judge for open-ended replies, and versioned regression tracking. The example is framed around a support assistant. Some test cases require an exact label, such as BILLING or BUG_REPORT; others require a reply that acknowledges frustration and gives clear next steps. The author says the code can run in a notebook such as Colab, with a mock mode for offline testing and an option to call Gemini API models on a free tier. The tutorial also notes that the model wrapper separates the harness from the model call, while a version_tag argument identifies the prompt or use-case version being tested.
Why is evaluating prompts by eye risky?
The source says many teams test prompts in a playground, tweak a system instruction, choose the version that looks better and ship it. That can work briefly, but a small wording change may silently break a case that passed earlier. The tutorial's answer is to keep a small golden dataset of high-signal examples and score each prompt version against it. It does not claim hundreds or thousands of examples are necessary. The point is repeatability: the same inputs, the same scoring rules and a record of each version. This makes the evaluation less dependent on a reviewer's impression and more useful when a prompt changes.
How does the harness score different tasks?
According to MachineLearningMastery, deterministic tasks use exact-match scoring after normalization. In the sample data, a billing complaint should map to BILLING and a crash report to BUG_REPORT. Open-ended tasks use a rubric-based judge that returns structured Pydantic output. The rubric for an angry cancellation request asks for empathy about downtime and clear, non-pushy cancellation steps. A plan-switch question is judged on facts and tone rather than a single label. The harness sets temperature to 0.0 to reduce random variation between runs, so score changes are more likely to reflect prompt edits than sampling noise. The source presents this as a practical way to combine strict scoring with more flexible judgment.
How does it catch regressions a pass rate can hide?
The source emphasizes case-by-case comparison across prompt versions. An overall pass rate can stay high while one important case flips from pass to fail. The harness logs results by version tag and compares runs. In the mock example, a stricter label instruction in v2_strict bleeds into an open-ended reply: the answer to a plan-switch question becomes BILLING instead of a helpful sentence. That simulated regression shows why versioned tracking matters. The tutorial's method is to keep the prompt version, the test case and the score together, then inspect changes rather than relying only on an aggregate number. This is the part that turns a quick demo into a repeatable check.
What does it take to run the example?
MachineLearningMastery says the code is ready to copy into a notebook environment. It installs google-genai and pydantic, uses a mock mode by default and can switch to live Gemini calls with a GEMINI_API_KEY in Colab Secrets. The model wrapper separates the harness from the model call, and the version_tag argument identifies the prompt or use-case version being tested. The sample dataset mixes exact-match and rubric cases. The author's stated goal is to teach the key steps and elements of the framework, not to provide a production MLOps platform. Readers can therefore start with simulated outputs and later connect a real model endpoint.
How can Grafy users explore this workflow?
For readers who want to build or adapt the harness, Grafy Code is the relevant Grafy app: it is an AI coding studio that can help write and run code. A user could ask it to scaffold the scorer, the Pydantic judge and the version log, then inspect the output. Grafy Chat can be used to compare model responses side by side when designing rubric prompts, while Reader can help work through the original tutorial and related papers. The connection is practical rather than a claim that Grafy ships this exact harness.
Frequently asked questions
Did MachineLearningMastery publish a production MLOps platform?
No. According to MachineLearningMastery, the post is a lightweight tutorial for a reusable evaluation harness in under 150 lines of Python. It focuses on exact-match scoring, rubric-based judging and versioned regression tracking, not a full observability stack.
Does the harness require a paid Gemini API key?
No. The source says the example includes a mock mode and can run on the Gemini API free tier. A free API key from Google AI Studio can be added as GEMINI_API_KEY in Colab Secrets to make live calls; otherwise the mock outputs allow offline testing.
Can the harness catch a regression hidden by a high pass rate?
Yes, according to the source. It logs each prompt version's results and compares runs case by case. The mock example shows a strict label instruction leaking into an open-ended reply, which an overall pass rate could miss.
Source: MachineLearningMastery, https://machinelearningmastery.com/build-a-lightweight-llm-evaluation-harness-in-python/
Source: MachineLearningMastery — Build a Lightweight LLM Evaluation Harness in Python


