mastra-ai/mastra · error · MastraError
EXPERIMENT_NO_ITEMS
EXPERIMENT_NO_ITEMS
Error message
Cannot run experiment: dataset "${this.id}" has no items at version ${targetVersion} What it means
Thrown by Dataset.startExperimentAsync when the datasets store returns zero items for the dataset at the resolved target version. An experiment with no items to run would produce empty results, so Mastra refuses to start it. The target version defaults to the dataset's current version unless config.version is given.
Source
Thrown at packages/core/src/datasets/dataset.ts:395
const dataset = await datasetsStore.getDatasetById({ id: this.id, filters: this.#scope });
if (!dataset) {
throw new MastraError({
id: 'DATASET_NOT_FOUND',
text: `Dataset not found: ${this.id}`,
domain: 'STORAGE',
category: 'USER',
});
}
// Validate that dataset has items before creating experiment record
const targetVersion = config.version ?? dataset.version;
const items = await datasetsStore.getItemsByVersion({
datasetId: this.id,
version: targetVersion,
});
if (items.length === 0) {
throw new MastraError({
id: 'EXPERIMENT_NO_ITEMS',
text: `Cannot run experiment: dataset "${this.id}" has no items at version ${targetVersion}`,
domain: 'STORAGE',
category: 'USER',
});
}
const experimentId = crypto.randomUUID();
if (experimentsStore) {
await experimentsStore.createExperiment({
id: experimentId,
datasetId: this.id,
datasetVersion: targetVersion,
targetType: config.targetType ?? 'agent',
targetId: config.targetId ?? 'inline',
totalItems: items.length,
name: config.name,View on GitHub (pinned to 75dd419e61)
Solutions
- Check the dataset actually has items at the target version (listItems / getItemsByVersion) before starting
- Omit config.version to use the dataset's current version, or pass the correct version that contains items
- Add items to the dataset at the desired version before creating the experiment
Example fix
// before
await dataset.startExperimentAsync({ version: 3, targetId: 'myAgent' });
// after
const items = await dataset.getItemsByVersion({ datasetId: dataset.id, version: 3 });
if (items.length > 0) await dataset.startExperimentAsync({ version: 3, targetId: 'myAgent' }); Defensive patterns
Strategy: validation
Validate before calling
const items = await datasetsStore.getItemsByVersion({ datasetId: dataset.id, version: config.version ?? dataset.version });
if (!items.length) throw new Error(`Dataset ${dataset.id} has no items at version ${config.version ?? dataset.version}`); Type guard
function hasItems<T>(items: T[] | undefined | null): items is T[] { return Array.isArray(items) && items.length > 0; } Try / catch
try {
await dataset.startExperimentAsync(config);
} catch (e) {
if (isMastraError(e) && e.id === 'EXPERIMENT_NO_ITEMS') {
console.warn(`Skipping experiment: no items at version ${config.version ?? 'current'}`);
} else throw e;
} Prevention
- Seed items before starting experiments; assert item count in setup
- Default to the dataset's current version unless you specifically need a historical one
- Add an integration check that every experiment version has items
When it happens
Trigger: Calling startExperimentAsync on a dataset whose items were never added, or at a config.version that predates any items (or after items were all removed from that version).
Common situations: Typo in version number; dataset created but items not yet inserted; items deleted from an old version; pointing at version 1 of a dataset whose data only exists in version 2; empty dataset in a fresh environment.
Related errors
- EXPERIMENT_NO_ITEMS
- EXPERIMENT_NOT_FOUND
- EXPERIMENT_RESULT_MISSING_EXPERIMENT_ID
- EXPERIMENT_INVALID_TARGET
- EXPERIMENT_TARGET_NOT_FOUND
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/b9dfa697275d1ad6.
Report an issue: GitHub.