Implementation:Promptfoo Promptfoo writeOutput
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Reporting, Evaluation |
| Last Updated | 2026-02-14 08:00 GMT |
Overview
Concrete tool for serializing evaluation results to multiple file formats and external services, provided by the Promptfoo framework.
Description
The writeOutput function takes an output path, a completed Eval record, and an optional shareable URL, then serializes the results to the appropriate format based on file extension. It supports CSV, JSON, YAML, HTML, JSONL, TXT, and Google Sheets.
Usage
Import this function when evaluation results need to be saved. This is the standard way to produce output artifacts in both CLI and programmatic flows.
Code Reference
Source Location
- Repository: promptfoo
- File: src/util/output.ts
- Lines: L111-200
Signature
export async function writeOutput(
outputPath: string,
evalRecord: Eval,
shareableUrl: string | null,
): Promise<void>
Import
import { writeOutput } from './util/output';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| outputPath | string | Yes | File path or Google Sheets URL for output destination |
| evalRecord | Eval | Yes | Complete evaluation record with all results |
| shareableUrl | string or null | Yes | Optional shareable URL to include in output |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | void | File written to the specified output path |
Usage Examples
Write JSON Results
import { writeOutput } from './util/output';
await writeOutput('./results.json', evalRecord, null);
// Creates results.json with full evaluation data
Write CSV for Spreadsheet Review
await writeOutput('./results.csv', evalRecord, 'https://app.promptfoo.dev/eval/abc123');
// Creates CSV with one row per test result
Related Pages
Implements Principle
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment