writing-evals
Writing and running evals
The harness under products/posthog_ai/eval_harness/ runs two kinds of suites: sandboxed suites execute the real coding agent inside a real sandbox against a seeded Hedgebox project and score what it did, and one-shot suites score a single in-process model invocation per case.
Neither runs under pytest — the standalone harness boots the shared infrastructure the selected suites need (for sandboxed suites: test DB, Django live server, LLM gateway, MCP server, Temporal, personhog; for one-shot suites: just the test DB, personhog, and demo data) and runs every selected suite concurrently, with Braintrust as the eval engine.
Read before writing anything:
- products/posthog_ai/eval_harness/README.md — usage, CLI flags, providers.
- products/posthog_ai/evals/AGENTS.md — the Hedgebox dataset reference. Your prompts,
expectedvalues, and scorers must match that taxonomy exactly (signed_up, notsign_up). - products/posthog_ai/eval_harness/harness/AGENTS.md — invariants when touching the harness itself.
Field-level API detail (case fields, the output dict, LogParser, seeder inventory) lives in references/authoring-reference.md.
Writing a suite
Suites are discovered by convention, not registered: any coroutine named eval_* in a file named eval_*.py, taking a single ctx: EvalContext and returning None.
The harness discovers suites from two root sets:
products/posthog_ai/evals/<domain>/— the built-in tree, reserved for Max and other agent suites. The directory is the domain; the suite id is<domain>/<module>::<fn>(import pathproducts.posthog_ai.evals.<domain>.<module>).products/<product>/evals/— where a product ships eval suites next to its own code. Note the pluralevals/: the singularproducts/signals/eval/is an existing pytest tree and is not collected by the harness. The product is the domain; the suite id is<product>/<module>::<fn>(import pathproducts.<product>.evals.<module>).
New product-owned evals belong under products/<product>/evals/. Both root sets use the same conventions (the eval_*-coroutine-in-eval_*.py rule, the SUITE_KIND marker, and substring selectors).
No evals/ tree needs a pytest-collection exclusion: pytest's default python_files matches test_*.py, so eval_*.py files there are never collected as tests. Do not add a conftest.py under an evals/ tree.
from products.posthog_ai.eval_harness.base import SandboxedEval
from products.posthog_ai.eval_harness.config import SandboxedEvalCase
from products.posthog_ai.eval_harness.harness.context import EvalContext
async def eval_my_thing(ctx: EvalContext) -> None:
await SandboxedEval(
experiment_name="sandboxed-my-thing-cli",
cases=[SandboxedEvalCase(name="my_case", prompt="...")],
scorers=[],
ctx=ctx,
)- One suite = one experiment. Bundle related cases into one suite; split only when the scorecard would be heterogeneous (self-skipping scorers stretch a shared scorer list across mildly different cases, but a scorecard where half the scorers skip half the cases is a sign to split).
experiment_nameidentifies local and PostHog runs — keep it stable for cross-run comparison. Existing sandboxed suites end in-clibecause the MCP server serves theclisurface.SandboxedEvalandOneShotEvalalways run Braintrust locally without uploading to it. Withoffline_suiteand a publishing credential, results publish to PostHog by default. Setsend_to_posthog=Falsefor local-only results; local logs are always written. Ordinary SDK and trace clients still honorOPT_OUT_CAPTURE. See evaluation result reporting.- To enroll a suite in PostHog reporting, register its scorer kinds and immutable version UUIDs in the owning
offline_config.pycatalog, then passoffline_suite=offline_suite("<domain>/<module>::<function>", metrics=[...])to the runner. Use the PostHog AI catalog for built-in suites and the Slack app catalog for Slack suites. List every explicit scorer's_name()inmetrics; the catalog addsexit_code_zeroonly for sandboxed suites. For one-shot suites, passsuite_kind=SUITE_KIND. The enrollment test discovers catalog-using modules and checks every suite function against its scorer list. - Uploading and tagging require
POSTHOG_OFFLINE_EVAL_API_KEYto be a personal key withoffline_evaluation_ingestion:writeandevaluation:write. Ingestion-only personal or project secret keys can upload without tags. Upload success is recorded before the separate, bounded tag update, so a tagging failure or interruption keeps the results link.
One-shot suites
A module-level SUITE_KIND declares how a module's suites execute; absent means sandboxed, so existing suites need nothing.
SuiteKind.ONE_SHOT suites skip the sandbox entirely: the harness boots only the test DB, personhog, and demo data for them, a
