Skip to main content
bt preprocessors manages preprocessors defined in local TypeScript or JavaScript files. A preprocessor turns a trace into the messages that prompt-based scorers receive for trace template variables such as {{preprocessed}}. Use the CLI to scaffold a starter file, run it against a real trace, and publish it to a project without using the preprocessor editor.
bt v0.26.0 or later is required. bt preprocessors push and bt preprocessors preview require Node.js. The braintrust/preprocessors helper is embedded in the CLI, so install the Braintrust TypeScript SDK v3.36.0 or later only if you want editor types and typechecking.

Subcommands

list, view, invoke, and delete are aliases for bt functions scoped to preprocessors and accept the same flags.

Write a preprocessor

Export each definition with customPreprocessor() from braintrust/preprocessors. Named and default exports are supported, and a file can export more than one definition.
conversation.preprocessor.ts
The handler runs once per span and receives the span’s id, root_span_id, input, output, error, metadata, and span_attributes. It must synchronously return a JSON-serializable value, or null to skip the span. Published handlers run in QuickJS. bt preprocessors push bundles local imports into inline code. Node.js APIs, network access, and unbundled imports are unavailable.

bt preprocessors push

Push one or more preprocessor definitions to Braintrust. bt scans the path for files matching *.preprocessor.ts, *.preprocessor.js, *-preprocessor.ts, or *-preprocessor.js, and pushes every definition each file exports.
If a preprocessor with the same slug already exists, the command fails by default. Add --if-exists replace to update it. Flags Each definition can set project to a project name, or to an object with the project’s id or name. Definitions without one use --project or your configured project.

bt preprocessors bootstrap

Create a starter preprocessor file in the braintrust-preprocessors/ directory (created if it does not exist). The starter returns each LLM span’s output as an assistant message.
Flags

bt preprocessors preview

Run a local preprocessor on a trace in Braintrust’s QuickJS runtime and print the output. Preview doesn’t publish the preprocessor. Open a trace in Braintrust’s logs or an experiment and copy the URL from your browser’s address bar. Pass it to --url in quotes to preserve its query parameters:
You can also select a project logs trace by root span ID. If the URL doesn’t include a project, or you use --trace-id, also pass --project or --project-id:
If the file exports more than one definition, select one with --export <NAME>, or --export default for the default export. Flags

Use a preprocessor in a scorer

Pass --preprocessor to bt scorers create to build a prompt-based scorer’s trace template variables with a pushed preprocessor:

Example workflow

With bt v0.26.0 or later and Node.js installed, bootstrap, preview, and push a preprocessor. Copy a trace URL from your browser’s address bar for the preview step: