Skip to content
CodeKruPro

Promptfoo assertions, a CI gate, and moving an eval

90/99

Module · Frameworks and other languages

advanced

about 40 min

What this lesson teaches

The idea

Promptfoo is another popular eval tool. You describe tests in a YAML file and run them from the command line, which fits neatly into CI.

Why a tester cares

It can grade replies you recorded earlier without calling a model. For data that must stay private, you switch off its telemetry.

Words you will meet

Promptfoo:
an eval tool driven by a YAML file.
Assertion:
one condition each reply must meet.
Telemetry:
usage data a tool sends back to its makers.

What you will do

  1. 1Add the assertions
  2. 2Switch off telemetry
  3. 3Check good and bad recordings
  4. 4Map the checks
Jump to practice

Promptfoo is another widely used eval tool. Where DeepEval is Python and pytest, promptfoo is a YAML config run from the command line, which makes it easy to drop into CI: npx promptfoo eval exits non-zero when assertions fail.

A neat trick grades recorded replies without calling any model. The echo provider returns the prompt unchanged, so with the prompt {{output}}, each test's recorded reply is exactly what the assertions see. Tests and assertions can use the test's vars, such as {{must_mention}}.

Promptfoo sends anonymous usage telemetry and can call its servers to generate test cases. In a CI job that handles customer data, switch both off with PROMPTFOO_DISABLE_TELEMETRY and PROMPTFOO_DISABLE_REMOTE_GENERATION, which the config's env: section can set.

Assertion types used here: icontains, contains, not-icontains, not-contains, regex, not-regex, equals, starts-with, is-json, and the -any forms. The runner checks your config and applies these the way promptfoo documents them, so no Node install is needed. On your own machine, the same file runs with the real tool.

Your task

  1. Finish the config: every reply must mention its phrase, contain no email address, stay under 400 characters, and never say "as an AI". Switch telemetry and remote generation off.
  2. Map each DeepEval check from lesson 89 to its promptfoo equivalent.

Sign in to practise

The lesson is free to read. A free account lets you talk to the practice bots, run your code and save your score. You will come back to this lesson.

1

Write it up

How this is checked: When you submit, it is saved as promptfooconfig.yaml and used by the run.

2

Your code

Provided by the lesson. You can read it but not change it.

on recorded replies

How this is checked: When you submit, your script runs on 3 sets of data, 1 of them hidden, and the server compares what it prints with the right values. Run tries it on the data you can see.

3

Write it up

How this is checked: When you submit, the server checks that it is valid JSON and follows the rules in the task. Your result names any rule it breaks.

Core checks earn 50 points and the harder checks the other 50. You can submit as many times as you like.

About this lesson

Promptfoo config with the echo provider and assertions, telemetry off, as a CI gate

AI Testing for QA EngineersAdvancedFrameworks and other languages

How it works

Promptfoo is another widely used eval tool. Where DeepEval is Python and pytest, promptfoo is a YAML configuration run from the command line, which makes it easy to drop into CI, where a failed assertion makes the run exit non-zero.

Recorded replies can be graded without calling a model. The echo provider returns the prompt unchanged, so with a prompt that is just the output variable, each test's recorded reply is exactly what the assertions see. Assertion values can use a test's variables, such as the phrase it must mention.

Promptfoo sends anonymous telemetry and can call its servers to generate test cases. For CI jobs that touch customer data, both are switched off with environment settings the config can carry.

About the assignment

Finish the config so every reply must mention its phrase, contain no email address, stay under a length limit and never call itself an AI, with telemetry and remote generation off, and map each DeepEval check to a promptfoo assertion.

What you will do

  1. Put shared assertions under the default test, so every recorded test gets them.
  2. Choose assertion types for each rule from the list on the page.
  3. Set both environment variables, then check good and bad recordings.

Common mistakes

  • Backslashes in YAML strings

    Inside double quotes, each regex backslash must be written twice.

  • An email pattern that is too narrow

    Addresses can contain a plus sign and two-part domains.

In a real test suite

Teams often keep the same checks in both tools for a while when migrating. A mapping table between them, like the one in this lesson, is what makes the move safe.