Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Promptfoo Promptfoo CSV Parser

From Leeroopedia
Knowledge Sources
Domains Data_Parsing, Testing
Last Updated 2026-02-14 07:45 GMT

Overview

Concrete tool for parsing CSV-based evaluation files into structured test cases and assertions, shared by both frontend and backend.

Description

The CSV_Parser module converts CSV row data into promptfoo TestCase and Assertion objects. It handles parsing assertion strings (e.g., contains:hello, javascript:fn(), similar(0.9):expected) into structured Assertion objects with proper types, thresholds, and values. It supports all base assertion types defined in the schema, including negation (not-), threshold values, and various shorthand syntaxes.

Usage

Import this module when loading test cases from CSV files or Google Sheets. It is used internally by the test case reader to handle CSV-format inputs.

Code Reference

Source Location

Signature

export function assertionFromString(expected: string): Assertion

export function testCaseFromCsvRow(row: CsvRow): TestCase

export function testCasesFromCsv(
  csvInput: string | object[],
  vars?: string[]
): TestCase[]

Import

import { assertionFromString, testCaseFromCsvRow, testCasesFromCsv } from './csv';

I/O Contract

Inputs

Name Type Required Description
expected string Yes Assertion string (e.g., "contains:hello", "similar(0.9):text")
row CsvRow Yes Single CSV row as key-value object
csvInput string or object[] Yes Raw CSV string or array of row objects
vars string[] No Optional list of variable column names

Outputs

Name Type Description
Assertion Assertion Structured assertion with type, value, threshold
TestCase TestCase Test case with vars, assertions, and metadata
TestCase[] TestCase[] Array of test cases parsed from CSV

Usage Examples

import { assertionFromString, testCasesFromCsv } from './csv';

// Parse a single assertion string
const assertion = assertionFromString('similar(0.9):expected output');
// Result: { type: 'similar', value: 'expected output', threshold: 0.9 }

// Parse CSV rows into test cases
const testCases = testCasesFromCsv([
  { question: 'What is AI?', __expected: 'contains:artificial intelligence' },
  { question: 'Hello', __expected: 'icontains:hi' },
]);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment