Setup
Install thebraintrust package alongside Vitest:
Separate evals from unit tests
This is optional — eval files are just regular Vitest files and can live anywhere in your project. Evals can run slower, and log results to Braintrust. A common convention is a.eval.ts suffix or a dedicated evals/ directory, with a separate Vitest config that targets them:
vitest.eval.config.ts
Run your first eval
CallwrapVitest once at the top of your test file, passing in the Vitest globals. Use the returned object in place of the standard test, describe, and expect.
my-eval.eval.ts
Example: evaluating an LLM summarizer
This example evaluates a function that summarizes news articles. It loads a dataset from Braintrust, attaches multiple scorers, and logs structured outputs per test case.summarizer.eval.ts
Terminal output
Key concepts
wrapVitest
Wraps Vitest’s test, describe, and expect with Braintrust tracking.
Experiments and suites
Eachdescribe creates one Braintrust experiment. Braintrust appends a timestamp to make each run unique. The project groups experiments together and defaults to the suite name if projectName is not set in the config.
Results are pushed to Braintrust regardless of whether individual tests pass or fail, so every run is recorded.
Test configuration
test accepts an optional config object between the name and the test function:
Scorers
A scorer is any function that receives{ output, expected, input, metadata } and returns a name and score:
Logging helpers
UselogOutputs and logFeedback inside a test to log additional data to the current span: