mastra-datasets-experiments
Skill2 starsChanged 29 days agoApache-2.0View on GitHub
Build a repeatable eval loop in Mastra: versioned datasets of test cases, experiments that run a dataset through an agent, workflow, or scorer, comparisons between runs, gates and thresholds that produce a passed, scored, or failed verdict, CI scripts, and Vitest matchers. Use this skill whenever the user wants a golden dataset, regression tests for an agent, to compare prompts or models, to block a deploy on eval results, to mock tools during evals, or to run evals in Vitest or GitHub Actions. Triggers on mastra.datasets, dataset.addItems, dataset.startExperiment, startExperimentAsync, compareExperiments, runExperimentItem, submitExperimentResult, toolMocks, unmockedToolPolicy, runEvals gates, verdict, threshold, expectEvals, expectEval, MastraEvalsReporter, @mastra/evals/vitest, toHaveVerdict, eval loop. Also triggers when the user asks whether a prompt or model change made the agent better or worse.
In this repository46 other files it gives its agents.
- mastra-a2a-acpSkill
- mastra-agent-approval-hitlSkill
- mastra-agentic-uiSkill
- mastra-agent-skillsSkill
- mastra-agentsSkill
- mastra-authSkill
- mastra-browserSkill
- mastra-build-playbookSkill
- mastra-channelsSkill
- mastra-classifierSkill
- mastra-cli-apiSkill
- mastra-client-sdkSkill
- mastra-deploymentSkill
- mastra-evalsSkill
- mastra-file-based-agentsSkill
- mastra-framework-integrationSkill
- mastra-guideSkill
- mastra-harnessSkill
- mastra-knowledgeSkill
- mastra-mcpSkill
- mastra-memorySkill
- mastra-migrationsSkill
- mastra-modelsSkill
- mastra-multi-agentSkill
- mastra-observabilitySkill
- mastra-observational-memorySkill
- mastra-platformSkill
- mastra-processors-guardrailsSkill
- mastra-project-setupSkill
- mastra-ragSkill
- mastra-schedulesSkill
- mastra-semantic-recallSkill
- mastra-serverSkill
- mastra-signalsSkill
- mastra-storageSkill
- mastra-streamingSkill
- mastra-structured-outputSkill
- mastra-studio-editorSkill
- mastra-tool-integrationsSkill
- mastra-toolsSkill
- mastra-troubleshootingSkill
- mastra-vector-storesSkill
- mastra-voiceSkill
- mastra-workflowsSkill
- mastra-workflow-suspend-resumeSkill
- mastra-workspace-sandboxSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 88
Verify the API: If node_modules/@mastra/ exists, read node_modules/@mastra/core/dist/docs/ and node_modules/@mastra/evals/dist/docs/ plus …
- Very specific: line 137
Expecting scorer sources to merge: Run-level scorers override item scorerIds, which override dataset scorerIds.
- Very specific: line 138
Experiments sending real emails or refunds: Add toolMocks and unmockedToolPolicy: 'deny'.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mastra Datasets and Experiments
Turn scorers into a repeatable loop: curate a versioned dataset, run experiments against it, compare runs, and gate releases on a verdict.
When to use
- Creating a golden dataset of inputs and ground truth, in code or from production traces
- Running an experiment against a registered agent, workflow, or scorer
- Comparing two or more experiments (prompt change, model swap, code change)
- Making evals deterministic with tool mocks
- Failing CI when quality drops, with gates, thresholds, and a verdict
- Running evals as Vitest tests with matchers and a score reporter
- Driving experiments from an external orchestrator (Temporal, Airflow, workers)
When NOT to use
- Choosing or writing scorers, Quick Checks, live scoring (use
mastra-evals) - Traces, logs, metrics, user feedback (use
mastra-observability) - The Studio UI for datasets and experiments (use
mastra-studio-editor) - Configuring storage adapters (use
mastra-storage) - The
mastra apiCLI in depth (usemastra-cli-api) - Overall build process from idea to production (use
mastra-build-playbook)
Required inputs
- The target and how it is registered (
targetTypeplustargetId, or an agent frommastra.getAgent()) - A storage adapter with the
datasetsdomain (LibSQL, PostgreSQL, MongoDB, and others) - Five or more representative cases with
inputandgroundTruth(expected meaning, not exact wording) - The scorers, registered on the
Mastrainstance (seemastra-evals) - Pass criteria: which checks are hard gates, which scores need a threshold
- Whether tools have side effects that must be mocked
The framework: dataset, experiment, verdict
| Concept | API | Persisted | Answers |
| Dataset | mastra.datasets.create(), dataset.addItems() | Yes, versioned on every change | What should the agent handle? |
| Experiment | dataset.startExperiment() | Yes (results, scores, traces) | How did this version do on each item? |
| Comparison | mastra.datasets.compareExperiments() | Read-only | What changed between runs? |
| Verdict | runEvals({ gates, scorers: [{ scorer, threshold }] }) | Scores only | Should this ship? |
Experiment status and counts describe execution, not quality. A completed experiment with failedCount: 0 can still score 0 on every item. Verdicts belong to runEvals.
import { mastra } from '../src/mastra'
const dataset = await mastra.datasets.create({ name: 'translation-pairs' })
await dataset.addItems({
items: [
{ input: 'Hello', groundTruth: 'Hola' },
{ input: 'Thank you', groundTruth: 'Gracias' },
],
})
const summary = await dataset.startExperiment({
name: 'baseline',
targetType: 'agent',
targetId: 'translation-agent',
scorers: ['accuracy'],
})
for (const item of summary.results) {
for (const s of item.scores) console.log(item.itemId, s.scorerName, s.score, s.reason)
}Workflow
- Verify the API. If
node_modules/@mastra/exists, readnode_modules/@mastra/core/dist/docs/andnode_modules/@mastra/evals/dist/docs/plus the installed types. Otherwise fetchhttps://mastra.ai/docs/evals/datasets.md,https://mastra.ai/docs/evals/experiments.md, andhttps://mastra.ai/reference/datasets/startExperiment.md. Trust these over memory. Datasets need@mastra/core1.4.0 or later. - Configure storage on
new Mastra({ storage })with an adapter that provides thedatasetsdomain. - Seed a small golden dataset. Five to ten cases you can read by hand. Add
inputSchemaandgroundTruthSchemato reject malformed items. Pass a fixedidwhen scripts need to find it again. - Register the target and scorers on the
Mastrainstance. Experiments reference them by ID. - Mock side-effecting tools with per-item
toolMocks, and setunmockedToolPolicy: 'deny'when a live call would be harmful. - Run a baseline experiment with a descriptive
name. Read every output, score, and reason. - Change one thing (instructions, model through
agentModel, a tool). Keep the dataset version and scorers fixed. Run again. - Compare in Studio or with
compareExperiments({ experimentIds, baselineId }). - Grow the dataset from production traces (Studio: Add full trace to dataset) whenever a new failure appears.
- Gate releases with a
runEvalsscript or Vitest test that requiresverdict === 'passed'and exits non-zero otherwise.
Deep dive: gates, thresholds, verdict
import { runEvals } from '@mastra/core/evals'
import { checks } from '@mastra/evals/checks'
import { mastra } from '../src/mastra'
const result = await runEvals({
target: mastra.getAgent('weatherAgent'),
data: [{ input: 'What is the weather in Brooklyn?' }],
gates: [checks.calledTool('get_weather'), checks.noToolErrors()],
scorers: [
{ scorer: mastra.getScorer('faithfulnessScorer'), threshold: 0.7 },
{ scorer: mastra.getScorer('hallucinationScorer'), threshold: { max: 0.3 } },
checks.includes('Brooklyn'), // tracked only
],
})
if (result.verdict !== 'passed') process.exitCode = 1| Verdict | Meaning |
failed | A gate averaged below 1.0 (a throwing gate counts as 0) |
scored | Gates passed, a threshold was missed |
passed | All gates at 1.0 and all thresholds met |
| absent | No gates or thresholds, or all returned notScorable() |
Averages hide single failures. Five 1s and one 0 average 0.83. For "every item must pass", use a binary scorer with threshold: 1 or make it a gate.
Failure patterns
- Treating
status: 'completed'as success. It only means items executed. Readresults[].scores. startExperimentthrows on scorer ID. The ID inscorers(run or dataset level) is not registered. Register it onnew Mastra({ scorers }). A stale item-level ID fails only that item withEXPERIMENT_ITEM_SCORER_NOT_FOUND.- Expecting scorer sources to merge. Run-level
scorersoverride itemscorerIds, which override datasetscorerIds.[]means no scorers.nullon an item update restores inheritance. - Experiments sending real emails or refunds. Add
toolMocksandunmockedToolPolicy: 'deny'. Mocks matchargsstrictly unlessmatchArgs: 'ignore'. - Tool mocks on a workflow target. Supported for
agenttargets only. MySQL rejects mocks. - Memory leaks between items. A shared resource id shares working memory and semantic recall. Use a dedicated evaluation resource or let the runner isolate each item.
- Comparing runs on different data. Pin
versionso both experiments use the same dataset snapshot. - Vitest timeouts. LLM evals exceed the 5-second default. Set
timeoutper test ortestTimeout, and lowerconcurrencyor setfileParallelism: falseon rate limits. - Gate never fires on a judge scored 1 to 10. Thresholds are 0 to 1 and the judge's number is stored as returned. Fix the judge prompt (see
mastra-evals). listItems({ version })returning a bare array. That form is deprecated. PasspageandperPagefor the paginated shape.- Importing the agent into
runEvalsdirectly. Scores do not persist and registry lookups fail. Usemastra.getAgent().
Output format
A finished eval-loop delivery contains:
- A seed script (for example
scripts/seed-dataset.ts) that creates the dataset with schemas and a fixedid - Registered target and scorers in
src/mastra/index.ts, with dataset-capablestorage - An experiment script or Studio instructions, with named baseline and candidate runs
- A regression check (
scripts/eval-regression.tsor*.eval.test.ts) that fails on any verdict other thanpassed - CI wiring that runs the check before deploy, with provider keys as secrets
- A short readme section on how to add a case from a production trace
Reference files
references/api.md-DatasetsManager,Datasetmethods,startExperimentoptions and summary, caller-driven experiments, tool mocks, Vitest API.references/examples.md- Golden dataset and baseline, tool-mocked experiment, CI regression script, Vitest suite.references/checklist.md- Dataset quality and CI gating checklist.
Live docs
- https://mastra.ai/docs/evals/datasets
- https://mastra.ai/docs/evals/experiments
- https://mastra.ai/docs/evals/gates-and-verdicts
- https://mastra.ai/docs/evals/running-in-ci
- https://mastra.ai/docs/evals/vitest-integration
- https://mastra.ai/docs/guides/build-an-eval-loop
- https://mastra.ai/reference/datasets/startExperiment
- https://mastra.ai/reference/datasets/dataset
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

