{"record":{"id":"27056009d1f6d815","repo":"mastra-ai/mastra","slug":"no-task-provide-targettype-targetid-or-task","errorCode":null,"errorMessage":"No task: provide targetType+targetId or task","messagePattern":"No task: provide targetType\\+targetId or task","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/datasets/experiment/index.ts","lineNumber":353,"sourceCode":"        throw new Error(`Target not found: ${targetType}/${targetId}`);\n      }\n      const { target } = resolved;\n      execFn = (item, itemSignal) => {\n        // Merge global request context with per-item request context (item takes precedence)\n        const mergedRequestContext =\n          globalRequestContext || item.requestContext ? { ...globalRequestContext, ...item.requestContext } : undefined;\n        return executeTarget(target, targetType, item, {\n          signal: itemSignal,\n          requestContext: mergedRequestContext,\n          experimentId,\n          versions,\n          toolMocks: targetType === 'agent' ? item.toolMocks : undefined,\n          unmockedToolPolicy:\n            targetType === 'agent' ? (item.unmockedToolPolicy ?? config.unmockedToolPolicy ?? 'allow') : undefined,\n        });\n      };\n    } else {\n      throw new Error('No task: provide targetType+targetId or task');\n    }\n  } catch (err) {\n    await markFailedOnSetupError(err);\n    throw err; // unreachable, but satisfies TS control flow\n  }\n\n  // Tool mocks only apply to agent targets. If a dataset carrying toolMocks is reused\n  // against a task/workflow/scorer target, the mocks are silently ignored — warn once\n  // (not per item) so the misconfiguration is visible without log spam.\n  const itemsWithToolMocks = items.filter(item => item.toolMocks?.length).length;\n  if (targetType !== 'agent' && itemsWithToolMocks > 0) {\n    mastra\n      .getLogger()\n      ?.warn(\n        `Experiment target is \"${config.task ? 'task' : targetType}\" but ${itemsWithToolMocks} of ${items.length} dataset items declare toolMocks. ` +\n          `Tool mocks only apply to agent targets and will be ignored.`,\n      );\n  }","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/datasets/experiment/index.ts#L335-L371","documentation":"runExperiment needs a task to run per item: either a registered target (targetType+targetId) or an inline `task` function. If neither is present the config cannot produce an execFn, so this plain Error is thrown during setup and the run is marked failed before execution.","triggerScenarios":"Calling runExperiment (or startExperiment/startExperimentAsync/executeRun) with a config containing neither targetType+targetId nor a task function — e.g. both fields undefined after config assembly.","commonSituations":"Programmatic config building where task was expected to be injected; copying an example that used datasetId+task but dropping the task; conditional logic that skips both branches (e.g. only setting targetType when some flag is true).","solutions":["Provide a `task` function (item, signal) => result for inline execution","Or provide both targetType and targetId referencing a registered agent/tool/workflow/scorer","Validate the config before calling: ensure (targetType && targetId) || typeof task === 'function'","Trace why neither branch was populated (e.g. a flag or lookup returning undefined)"],"exampleFix":"// before\nawait runExperiment({ datasetId: 'ds_123' }); // no task, no target\n// after\nawait runExperiment({\n  datasetId: 'ds_123',\n  targetType: 'agent',\n  targetId: 'my-agent',\n});","handlingStrategy":"validation","validationCode":"if (!((config.targetType && config.targetId) || typeof config.task === 'function')) {\n  throw new Error('runExperiment requires targetType+targetId or a task function');\n}","typeGuard":"function hasTask(c: { targetType?: string; targetId?: string; task?: unknown }): boolean {\n  return (typeof c.targetType === 'string' && typeof c.targetId === 'string') || typeof c.task === 'function';\n}","tryCatchPattern":"try {\n  await runExperiment(config);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('No task')) {\n    console.error('Experiment config must define targetType+targetId or task');\n  } else throw err;\n}","preventionTips":["Validate the full experiment config with a schema requiring task XOR target","Never leave both task and target fields conditionally unset","Type the config so task/target are a discriminated union","Add a CI check that renders and validates experiment configs before runs"],"tags":["configuration","experiment","invalid-argument","user-input"],"backgroundTag":"missing-required-argument","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}