deleteExperiment()
Deletes an experiment and its result records, then attempts to delete the observability traces produced by the experiment. Trace deletion cascades to spans and trace-linked signals. Unsupported observability storage leaves the traces in place and logs a warning.
Use dataset.deleteExperiment() when you have a Dataset instance. Use mastra.datasets.deleteExperiment() to delete by experiment ID without a dataset reference, including experiments orphaned by dataset deletion.
Delete from a datasetDirect link to Delete from a dataset
import { Mastra } from '@mastra/core'
const mastra = new Mastra({/* storage config */})
const dataset = await mastra.datasets.get({ id: 'dataset-id' })
await dataset.deleteExperiment({ experimentId: 'experiment-id' })
The experiment must belong to the dataset. A missing experiment or an experiment associated with another dataset throws an error.
ParametersDirect link to Parameters
experimentId:
Returns Promise<void>, which resolves when deletion completes.
Delete without a dataset referenceDirect link to Delete without a dataset reference
import { Mastra } from '@mastra/core'
const mastra = new Mastra({/* storage config */})
await mastra.datasets.deleteExperiment({
experimentId: 'experiment-id',
organizationId: 'organization-id',
projectId: 'project-id',
})
The manager method doesn't require the experiment to remain associated with a dataset. Use it to delete an orphaned experiment whose datasetId was cleared when its dataset was deleted.
When organizationId or projectId is provided, deletion is scoped to those values. A tenancy mismatch is a silent no-op.
ParametersDirect link to Parameters
experimentId:
organizationId?:
projectId?:
Returns Promise<void>, which resolves when deletion completes or when a tenancy-scoped request doesn't match the experiment.
Trace deletion supportDirect link to Trace deletion support
Before deleting the result records, Mastra collects their trace IDs for the cascade. Storage without observability or trace deletion support leaves those traces in place, logs a warning, and still deletes the experiment with its result records.