mastra-ai/mastra · error · Error
No data source: provide datasetId or data
Error message
No data source: provide datasetId or data
What it means
runExperiment requires exactly one data source: either a storage-backed datasetId or inline `data`. When neither is supplied, this plain Error is thrown from the data-source resolution branch, and the run is marked failed during setup before any items execute.
Source
Thrown at packages/core/src/datasets/experiment/index.ts:296
domain: 'STORAGE',
category: 'USER',
});
}
items = versionItems.map(v => ({
id: v.id,
datasetVersion: v.datasetVersion,
input: v.input,
groundTruth: v.groundTruth,
expectedTrajectory: v.expectedTrajectory as TrajectoryExpectation | undefined,
requestContext: v.requestContext,
metadata: v.metadata,
toolMocks: v.toolMocks,
unmockedToolPolicy: v.unmockedToolPolicy,
scorerIds: v.scorerIds,
}));
} else {
throw new Error('No data source: provide datasetId or data');
}
} catch (err) {
await markFailedOnSetupError(err);
throw err; // unreachable, but satisfies TS control flow
}
// Phase B — Resolve task function
let execFn: (item: ExperimentItem, signal?: AbortSignal) => Promise<ExecutionResult>;
try {
if (config.task) {
// Inline task path
const taskFn = config.task;
execFn = async (item, itemSignal) => {
try {
const result = await taskFn({
input: item.input,
mastra,View on GitHub (pinned to 75dd419e61)
Solutions
- Pass inline `data: [...]` items to runExperiment
- Or pass a `datasetId` pointing at a stored dataset
- Validate the config object before calling (ensure data or datasetId is a non-empty value)
- Fix the upstream code that was supposed to populate `data` (e.g. check the fetch/loading result)
Example fix
// before
const data = await loadData(); // may return undefined
await runExperiment({ ...config, data });
// after
const data = await loadData();
if (!data || data.length === 0) throw new Error('loadData returned no data');
await runExperiment({ ...config, data }); Defensive patterns
Strategy: validation
Validate before calling
if (!config.datasetId && !(Array.isArray(config.data) && config.data.length > 0)) {
throw new Error('runExperiment requires datasetId or non-empty data');
} Type guard
function hasDataSource(c: { datasetId?: string; data?: unknown[] }): boolean {
return typeof c.datasetId === 'string' || (Array.isArray(c.data) && c.data.length > 0);
} Try / catch
try {
await runExperiment(config);
} catch (err) {
if (err instanceof Error && err.message.includes('No data source')) {
console.error('Experiment config missing both datasetId and data');
} else throw err;
} Prevention
- Validate experiment configs with a zod schema enforcing data XOR datasetId
- Avoid assigning possibly-undefined results to the data field
- Log the assembled config before running in CI pipelines
- Provide defaults for data loading with explicit failure when empty
When it happens
Trigger: Calling runExperiment (or startExperiment/startExperimentAsync/executeRun) with a config that omits both datasetId and data.
Common situations: Building config programmatically where the data field ends up undefined (failed fetch assigned to data); spreading a partial options object; forgetting to pass data after removing a datasetId.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Unknown target type: ${targetType}
- No task: provide targetType+targetId or task
- AGENT_DURABLE_METHOD_NOT_AVAILABLE
- Unsupported output format: ${format}
- Experiment not found: ${experimentIdA}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/92f2d7fcff2645bf.
Report an issue: GitHub.