Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 16.11 — Testing and Evaluating AI Code
Python · Example 2 of 3

An eval set, scorers and a regression check

The "models" are dictionaries of canned answers. Edit an answer and watch the pass rate change.

Model output is not deterministic, but the code around it must be testable. Use fakes and recorded replies for unit tests, an eval set with scoring functions to measure quality, regression checks to catch drops, and logs of prompts and replies to debug what happened.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write contains_all(reply, words), a scorer that ignores case.

02

Write run_eval(model, cases, scorer) that returns the share of passing cases, and 0.0 for an empty list.

03

Write regression(baseline, current, tolerance) that says whether quality dropped by more than the tolerance.

Explain it without notes

01

What is the difference between a unit test and an eval for AI code?

02

How do you test code that calls a non-deterministic model?

03

How does a regression check work for a prompt change?

04

You use another LLM to grade answers. How do you decide whether you can trust those grades, and how do you set up an eval pipeline for a RAG feature in CI?

An eval set, scorers and a regression check
Sign in to run this example in your browser.

Expected output

prompt v1: pass rate 0.75 failures ['opposite of hot'] -> OK
prompt v2: pass rate 0.50 failures ['2+2', '3*3'] -> REGRESSION
True False