Test LLM Translation Prompts with CSV and Excel Data
Drive promptfoo test cases from CSV or Excel files, including JSON style fields for translation prompts.
Why it matters
Validate and compare multiple language translation prompt variations using structured test cases from CSV or Excel files, enabling systematic evaluation of different translation styles and configurations.
Outcomes
What it gets done
Load test cases from CSV or Excel files with JSON configuration fields
Compare formal translator prompts against conversational assistant prompts
Configure translation style parameters like tone and length via structured data
Assert translation quality using case-insensitive content matching
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-simple-csv | bash Steps
Steps in the chain
Overview
Simple Csv
A promptfoo example demonstrating CSV and Excel test-case files, including multi-sheet Excel support and JSON style fields, using a translation-prompt illustration. Use it when test cases are more naturally maintained as a spreadsheet. Excel support requires the optional read-excel-file peer dependency.
What it does
This promptfoo example demonstrates using CSV and Excel (XLSX) files as the source of test cases, including JSON-valued fields for configuring style. It uses a translation task as the illustration: two prompt templates (a formal translator and a conversational language assistant) are tested against French and Pirate translations, with tone and length controlled via JSON fields per test row, and results checked with case-insensitive icontains assertions.
When to use - and when NOT to
Use this pattern when your test cases are more naturally maintained as a spreadsheet than as YAML - each row becomes a test case and each column header becomes a variable name, for both CSV and Excel. Excel support is optional and requires installing the read-excel-file peer dependency; without it, only CSV files work out of the box.
Inputs and outputs
npx promptfoo@latest init --example simple-csv
cd simple-csv
promptfoo eval
promptfoo view
To switch from tests.csv to tests.xlsx, install read-excel-file and point promptfooconfig.yaml's tests field at the Excel file. For workbooks with multiple sheets, specify which one to use by name (file://tests.xlsx#MyDataSheet) or by 1-based index (file://tests.xlsx#2).
Integrations
The project ships prompts.txt (both prompt templates), tests.csv and the optional tests.xlsx (the same test cases in each format), and promptfooconfig.yaml tying them together. See promptfoo's CSV Format documentation for the full field reference.
Who it's for
Teams who want to author and maintain promptfoo test cases in a spreadsheet - CSV or Excel, including multi-sheet workbooks - rather than hand-writing YAML test blocks.
Source README
simple-csv (Simple CSV Example)
You can run this example with:
npx promptfoo@latest init --example simple-csv
cd simple-csv
This example demonstrates how to use CSV and Excel files for test cases in promptfoo, including working with JSON fields for language translation tasks.
Features Demonstrated
- CSV and Excel (XLSX) test case formats with JSON configuration fields
- Multiple prompt variations for different translation styles
- Style configuration via JSON fields (tone, length)
- Case-insensitive test assertions (icontains)
Project Structure
promptfooconfig.yaml: Main configuration fileprompts.txt: Contains two prompt templates:- A formal translator prompt
- A conversational language assistant prompt
tests.csv: Test cases for French and Pirate translationstests.xlsx: Same test cases in Excel format (optional)
Using Excel Files
To use Excel files instead of CSV:
Install the read-excel-file package (optional peer dependency):
npm install read-excel-fileUpdate
promptfooconfig.yamlto use the Excel file:tests: file://tests.xlsx
Excel files work exactly like CSV files - each row becomes a test case, and column headers become variable names.
Multi-sheet Excel Files
For workbooks with multiple sheets, you can specify which sheet to use:
### Use a specific sheet by name
tests: file://tests.xlsx#MyDataSheet
### Or by 1-based index (2 = second sheet)
tests: file://tests.xlsx#2
Running the Tests
From the root of this example, you can run the eval as:
promptfoo eval
To view the results in your browser:
promptfoo view
For more details on using CSV and Excel files in promptfoo, see our CSV Format documentation.
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.