Cogitator
Evaluation Framework

Datasets

Load evaluation test cases from JSONL files, CSV files, or build them programmatically with filtering, sampling, and shuffling.

Overview

A Dataset is an immutable collection of EvalCase objects. Each case has an input string and optional expected, context, and metadata fields, plus the optional agent fields turns, expectedToolCalls and expectedPassages. Datasets are validated with Zod on construction, invalid cases throw immediately.

interface EvalCase {
  input: string;
  expected?: string;
  context?: Record<string, unknown>;
  metadata?: Record<string, unknown>;
  turns?: string[];
  expectedToolCalls?: { name: string; arguments?: Record<string, unknown> }[];
  expectedPassages?: string[];
}
FieldUsed by
turnsFurther user turns after input, run on the same conversation, see multi-turn cases
expectedToolCallsThe calls the agent should make, for toolCalls() and trajectory()
expectedPassagesIds or texts the retrieval should surface, for the retrieval metrics

Programmatic Construction

Build a dataset from an array of cases:

import { Dataset } from '@cogitator-ai/evals';

const dataset = Dataset.from([
  { input: 'What is 2+2?', expected: '4' },
  { input: 'Capital of France?', expected: 'Paris' },
  {
    input: 'Summarize this document',
    context: { document: 'Long text here...' },
    metadata: { category: 'summarization' },
  },
]);

console.log(dataset.length); // 3

The expected field is optional — some metrics (like LLM-as-judge) don't need it. context is passed to agent targets as the run's context and to custom metrics; metadata is for your own filtering.

JSONL Loading

Load cases from a JSONL file where each line is a JSON object:

const dataset = await Dataset.fromJsonl('./data/eval-cases.jsonl');

Example JSONL file:

{"input": "What is 2+2?", "expected": "4"}
{"input": "Capital of France?", "expected": "Paris"}
{"input": "Translate hello to Spanish", "expected": "hola"}
{"input": "Weather in Paris?", "expectedToolCalls": [{"name": "get_weather", "arguments": {"city": "Paris"}}]}
{"input": "My name is Ada.", "turns": ["What is my name?"], "expected": "Ada"}

Each line is validated against the EvalCase schema. Invalid JSON or a case the schema refuses throws with the line number and the fields at fault, such as Invalid case at line 3: input: Invalid input. The CSV loader names the line of the row too, counting quoted fields that span several lines. It reads commas as the delimiter and throws on a malformed row, such as a quote that is never closed, naming its line.

You can also use the standalone loader:

import { loadJsonl } from '@cogitator-ai/evals';

const cases = await loadJsonl('./data/eval-cases.jsonl');
const dataset = Dataset.from(cases);

CSV Loading

Load cases from a CSV file. Requires papaparse as a peer dependency.

pnpm add papaparse
const dataset = await Dataset.fromCsv('./data/eval-cases.csv');

Example CSV file:

input,expected,metadata.category,context.topic
What is 2+2?,4,math,arithmetic
Capital of France?,Paris,geography,europe

The CSV must have an input column (otherwise loading throws). The expected column is optional; empty cells leave expected unset. Columns prefixed with metadata. are extracted into the metadata object, and columns prefixed with context. go into the context object — all values are strings. Other columns are ignored.

The agent fields turns, expectedToolCalls and expectedPassages take a column each whose cells hold a JSON array, quoted the CSV way (inner quotes doubled). An empty cell leaves the field out, and a cell that is not valid JSON throws with its line, such as Invalid case at line 2: turns: not valid JSON:

input,turns,expectedToolCalls,expectedPassages
Book a table,"[""For two, please""]","[{""name"":""book_table"",""arguments"":{""guests"":2}}]",
How long do refunds take?,,"[{""name"":""rag_search""}]","[""refund is issued within 5 days""]"

Nested data is easier to write and read in JSONL, so prefer it for agent datasets.

Standalone loader:

import { loadCsv } from '@cogitator-ai/evals';

const cases = await loadCsv('./data/eval-cases.csv');

Filtering

Create a subset of cases matching a predicate. Returns a new Dataset — the original is unchanged.

const mathOnly = dataset.filter((c) => c.metadata?.category === 'math');

const withExpected = dataset.filter((c) => c.expected !== undefined);

Sampling

Randomly sample n cases from the dataset. Useful for quick smoke tests on large datasets.

const sample = dataset.sample(10);
console.log(sample.length); // 10 (or less if dataset is smaller)

If n exceeds the dataset size, all cases are returned (shuffled), and n <= 0 gives an empty dataset.

Pass a seed (a number or a string) to pick the same cases on every run, so a sampled eval in CI compares like with like:

const nightly = dataset.sample(50, { seed: 'nightly' });

Shuffling

Randomize the order of cases. Returns a new Dataset.

const shuffled = dataset.shuffle();
const repeatable = dataset.shuffle({ seed: 42 }); // the same order on every run

Iteration

Datasets are iterable and expose a cases property:

for (const evalCase of dataset) {
  console.log(evalCase.input);
}

const allCases = dataset.cases; // readonly EvalCase[]

Chaining

Filter, sample, and shuffle are chainable:

const subset = dataset
  .filter((c) => c.metadata?.difficulty === 'hard')
  .shuffle()
  .sample(50);

On this page