mastra-ai/mastra · error · MastraError
EXPERIMENT_TARGET_NOT_FOUND
EXPERIMENT_TARGET_NOT_FOUND
Error message
Target not found: ${args!.targetType} "${args!.targetId}" What it means
createExperiment resolves the target (agent, workflow, etc.) in the local Mastra registry at creation time so typos fail immediately. If resolveTarget finds nothing for the given targetType/targetId, this error is thrown.
Source
Thrown at packages/core/src/datasets/dataset.ts:676
text: `targetType and targetId must be provided together (got targetType: ${args?.targetType ?? 'none'}, targetId: ${args?.targetId ?? 'none'})`,
domain: 'STORAGE',
category: 'USER',
});
}
if (args?.scorers?.length && !hasTargetType) {
throw new MastraError({
id: 'EXPERIMENT_INVALID_TARGET',
text: 'scorers require a target: without a target Mastra never executes or scores items; submit flat scores via submitExperimentResult instead',
domain: 'STORAGE',
category: 'USER',
});
}
// Validate the target exists in this Mastra registry at create time so a
// typo fails fast instead of failing on the first runExperimentItem call.
if (hasTargetType) {
const resolved = await resolveTarget(this.#mastra, args!.targetType!, args!.targetId!);
if (!resolved) {
throw new MastraError({
id: 'EXPERIMENT_TARGET_NOT_FOUND',
text: `Target not found: ${args!.targetType} "${args!.targetId}"`,
domain: 'STORAGE',
category: 'USER',
});
}
}
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',
});
}
View on GitHub (pinned to 75dd419e61)
Solutions
- Register the target (mastra.registerAgent / add workflow) before creating the experiment
- Fix the targetId spelling to match the registry
- Ensure createExperiment is called on the same Mastra instance where the target lives
Example fix
// before
await dataset.createExperiment({ targetType: 'agent', targetId: 'summarizer' }); // not registered
// after
mastra.registerAgent({ name: 'summarizer', ... });
await dataset.createExperiment({ targetType: 'agent', targetId: 'summarizer' }); Defensive patterns
Strategy: validation
Validate before calling
const resolved = await resolveTarget(mastra, args.targetType, args.targetId);
if (!resolved) throw new Error(`Target ${args.targetType} "${args.targetId}" is not registered in this Mastra instance`); Type guard
function isRegisteredTarget(t: { targetType: string; targetId: string }, mastra: Mastra): boolean { return resolveTarget(mastra, t.targetType, t.targetId) != null; } Try / catch
try {
await dataset.createExperiment(args);
} catch (e) {
if (isMastraError(e) && e.id === 'EXPERIMENT_TARGET_NOT_FOUND') {
console.error(`Register ${args.targetType} "${args.targetId}" before creating the experiment`);
} else throw e;
} Prevention
- Register all agents/workflows during app bootstrap before experiments
- Keep target ids in a shared constants module to avoid typos
- Validate experiment configs against the registry in CI
When it happens
Trigger: Calling createExperiment with a targetId that doesn't exist in this Mastra instance, or a targetType with no registered entity of that id.
Common situations: Typo in agent/workflow name; target registered on a different Mastra instance than the Dataset handle uses; renaming an agent without updating experiments; target registered after createExperiment is called.
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
- Experiment not found: ${experimentIdA}
- Experiment not found: ${experimentIdB}
- Target not found: ${targetType}/${targetId}
- Version-control repository not found.
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/e0ba4c4308601c4f.
Report an issue: GitHub.