AgenticBook
Back to Handbook
Chapter 07 · Evaluation GuideIssue 02 · November 2026

Test agent success, cost, and safety with Promptfoo

Build a regression loop around user-visible outcomes, tool trajectories, safety boundaries, latency, and spend. Use evaluator models as one signal—not as the definition of truth.

01

Define a test set from real tasks

A useful agent evaluation starts with a clear pass condition and representative inputs.

Create cases from common requests, ambiguous requests, permission boundaries, and resolved production failures. For each case, specify required outcomes, forbidden actions, acceptable alternatives, and the evidence needed to verify success. Prefer deterministic checks for IDs, state changes, and access control; use human review or an evaluator model for qualities such as completeness and clarity. Keep the dataset versioned so a changing test set does not hide a regression.

  • Separate task success from answer similarity; equivalent safe answers should be allowed.
  • Include negative cases for prompt injection, unauthorized tools, and missing information.
  • Measure the full trajectory: tool choice, arguments, retries, and stop behavior.
Editor's takeaway

The benchmark is a product contract. If the team cannot agree on what passes, a single aggregate score will not resolve the disagreement.

02

Run evaluations in CI and block regressions

Make prompt, model, tool, and framework changes answer to the same repeatable test suite.

Promptfoo’s official README describes local evaluations, model comparisons, red teaming, and CI/CD integrations. Start with a small, deterministic suite and add cases as failures are found. For each release, compare the candidate against the current baseline; gate on task success and safety first, then latency and budget. Record the provider, model, prompt version, tool version, and evaluation dataset version with the results.

  • Keep secrets in CI secret storage and do not print them in test logs.
  • Set explicit thresholds for safety failures, task success, p95 latency, and cost per task.
  • Use a canary or shadow run when a model change is too variable for a single offline test.
Editor's takeaway

An evaluation suite is most useful when it can stop an unsafe or costly release before users see it.

03

Pair offline tests with production traces

Offline datasets cover known cases; carefully sampled traces reveal the next cases to add.

Tracing tools help explain where an agent failed: a bad retrieval, tool argument, handoff, or repeated step. Langfuse provides traces, datasets, experiments, and evaluator workflows; Phoenix provides tracing, evaluations, datasets, experiments, and a self-hosted option. Choose based on integrations, data residency, operational cost, and license—not a feature checklist alone. Review trace privacy, retention, and access before collecting user conversations.

  • Sample and redact traces according to a documented privacy and retention policy.
  • Turn confirmed failures into minimal regression cases instead of storing entire conversations by default.
  • Track task success, safety, cost, latency, and user correction separately; avoid hiding trade-offs in one score.
Editor's takeaway

A strong evaluation loop compounds: production feedback becomes a small, safe test case that protects future releases.

Run the Promptfoo getting-started evaluation

npm install -g promptfoo
promptfoo init --example getting-started
cd getting-started
promptfoo eval
promptfoo view

The repository documents this quick start. Configure provider credentials through environment variables or CI secrets; never paste keys into a checked-in config.

Primary sources

First-party repositories and documentation used for this chapter. Check the upstream README and release notes before implementation.

  • Promptfoo — Local evals, red teaming, CI/CD; README states MIT license and OpenAI affiliation
  • Langfuse — Tracing, datasets, evaluations, experiments; MIT except ee folders
  • Arize Phoenix — Tracing, evaluations, datasets, experiments; ELv2 license
More chapters