mastra-ai/mastra · error · MastraError
DATASET_NOT_FOUND
DATASET_NOT_FOUND
Error message
Dataset not found: ${datasetId} What it means
runExperiment looked up the dataset via datasetsStore.getDatasetById with the given ID (and optional filters) and got no record back. A MastraError with id DATASET_NOT_FOUND (domain STORAGE, category USER) is thrown so callers can match on the error code.
Source
Thrown at packages/core/src/datasets/experiment/index.ts:260
requestContext: dataItem.requestContext,
metadata: dataItem.metadata,
resumeSteps: dataItem.resumeSteps,
resumeData: dataItem.resumeData,
toolMocks: dataItem.toolMocks,
unmockedToolPolicy: dataItem.unmockedToolPolicy,
scorerIds: dataItem.scorerIds,
};
});
datasetVersion = null;
} else if (datasetId) {
// Storage-backed data path (existing)
if (!datasetsStore) {
throw new Error('DatasetsStorage not configured. Configure storage in Mastra instance.');
}
datasetRecord = await datasetsStore.getDatasetById({ id: datasetId, filters: config.filters });
if (!datasetRecord) {
throw new MastraError({
id: 'DATASET_NOT_FOUND',
text: `Dataset not found: ${datasetId}`,
domain: 'STORAGE',
category: 'USER',
});
}
datasetVersion = version ?? datasetRecord.version;
const versionItems = await datasetsStore.getItemsByVersion({
datasetId,
version: datasetVersion,
});
if (versionItems.length === 0) {
throw new MastraError({
id: 'EXPERIMENT_NO_ITEMS',
text: `No items in dataset ${datasetId} at version ${datasetVersion}`,
domain: 'STORAGE',View on GitHub (pinned to 75dd419e61)
Solutions
- Check the dataset exists: await datasetsStore.getDatasetById({ id: datasetId }) and inspect the result
- Remove or loosen config.filters that may be hiding the dataset
- Create the dataset (or upload items) before running the experiment
- Confirm the Mastra instance points at the storage environment where the dataset lives
Example fix
// before
await runExperiment({ datasetId: 'ds_123', ... });
// after
const ds = await datasetsStore.getDatasetById({ id: 'ds_123', filters });
if (!ds) throw new Error(`Dataset ds_123 not found — create it or fix filters first`);
await runExperiment({ datasetId: 'ds_123', ... }); Defensive patterns
Strategy: try-catch
Validate before calling
const ds = await datasetsStore.getDatasetById({ id: datasetId, filters: config.filters });
if (!ds) throw new Error(`Dataset ${datasetId} not found (check filters)`); Type guard
function isDatasetRecord(r: unknown): r is { id: string } {
return !!r && typeof r === 'object' && 'id' in r;
} Try / catch
try {
await runExperiment(config);
} catch (err) {
if (err instanceof MastraError && err.id === 'DATASET_NOT_FOUND') {
// create dataset or fix filters/ID
} else throw err;
} Prevention
- Match on the DATASET_NOT_FOUND MastraError id rather than message text
- Pre-check dataset existence with the same filters you will run with
- Create datasets via a setup script before running experiments
- Keep dataset IDs in per-environment config, not hardcoded
When it happens
Trigger: Calling runExperiment with a datasetId that does not exist, was deleted, or is not visible under the supplied config.filters (e.g. scope/tenant filters exclude it).
Common situations: Dataset removed between creating and running the experiment; wrong environment's storage; filters (e.g. projectId/tenant) that exclude the dataset; ID copied from a different workspace.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Experiment not found: ${experimentIdA}
- Experiment not found: ${experimentIdB}
- Dataset not found: ${args.id}
- Version-control repository not found.
- Project repository not found for this organization.
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/a4a2e1a862f3a74b.
Report an issue: GitHub.