mastra-ai/mastra · error · Error
Dataset not found: ${args.datasetId}
Error message
Dataset not found: ${args.datasetId} What it means
updateItem() fetches the parent dataset via getDatasetById before updating an item; if the dataset doesn't exist (or is hidden by args.filters) it throws "Dataset not found: <datasetId>". Items cannot exist without a valid parent dataset, so this is the missing-parent guard.
Source
Thrown at packages/core/src/storage/domains/datasets/base.ts:175
* Subclasses implement _doAddItem which handles SCD-2 versioning internally.
*/
async addItem(args: AddDatasetItemInput): Promise<DatasetItem> {
const { datasetId, filters, ...item } = args;
const [result] = await this.batchInsertItems({ datasetId, filters, items: [item] });
return result!;
}
/** Subclasses implement actual storage add logic with SCD-2 versioning */
protected abstract _doAddItem(args: AddDatasetItemInput): Promise<DatasetItem>;
/**
* Update an item in a dataset. Validates changed fields against dataset schemas.
* Subclasses implement _doUpdateItem which handles SCD-2 versioning internally.
*/
async updateItem(args: UpdateDatasetItemInput): Promise<DatasetItem> {
const dataset = await this.getDatasetById({ id: args.datasetId, filters: args.filters });
if (!dataset) {
throw new Error(`Dataset not found: ${args.datasetId}`);
}
const { id: _id, datasetId: _datasetId, filters: _filters, ...payload } = args;
validateDatasetItemPayloadSerialization(payload, 'item');
// Validate new values against schemas if enabled
const validator = getSchemaValidator();
const cacheKey = `dataset:${args.datasetId}`;
if (args.input !== undefined && dataset.inputSchema) {
validator.validate(args.input, dataset.inputSchema, 'input', `${cacheKey}:input`);
}
if (args.groundTruth !== undefined && dataset.groundTruthSchema) {
validator.validate(args.groundTruth, dataset.groundTruthSchema, 'groundTruth', `${cacheKey}:output`);
}
return this._doUpdateItem(args);View on GitHub (pinned to 75dd419e61)
Solutions
- Confirm the dataset exists with getDatasetById using the same filters
- Verify the datasetId source isn't stale (was the dataset deleted?)
- Check storage backend/environment alignment
- Create the dataset first if it genuinely doesn't exist
Example fix
// before
await storage.updateItem({ datasetId: oldId, id: itemId, values })
// after
const ds = await storage.getDatasetById({ id: oldId });
if (!ds) throw new Error(`Dataset ${oldId} missing; refresh dataset reference`);
await storage.updateItem({ datasetId: oldId, id: itemId, values }); Defensive patterns
Strategy: validation
Validate before calling
const dataset = await storage.getDatasetById({ id: args.datasetId, filters: args.filters });
if (!dataset) throw new Error(`dataset ${args.datasetId} not found`); Type guard
null
Try / catch
try {
await storage.updateItem(args);
} catch (e) {
if (e.message.startsWith('Dataset not found:')) { /* refresh dataset reference */ }
throw e;
} Prevention
- Resolve datasetId from a live lookup, not cached state
- Check filters match dataset scope
- Watch for deletes invalidating stored datasetId references
- Use the same storage instance/config that created the dataset
When it happens
Trigger: Calling storage.updateItem({ datasetId }) where the dataset id is wrong, the dataset was deleted, or args.filters exclude it.
Common situations: Stale datasetId cached in application state after deletion, cross-environment ids (dev id used in prod), id built from concatenation producing a wrong value, filters mismatch.
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
- DATASET_NOT_FOUND
- Dataset not found: ${args.id}
- Dataset not found: ${input.datasetId}
- Dataset not found: ${args.id}
- Dataset not found: ${args.datasetId}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/282936b5de30c3cb.
Report an issue: GitHub.