{"record":{"id":"362d9d85e0f82d0a","repo":"mastra-ai/mastra","slug":"targettype-and-targetid-are-required-to-start-an-e","errorCode":null,"errorMessage":"targetType and targetId are required to start an experiment","messagePattern":"targetType and targetId are required to start an experiment","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/datasets.ts","lineNumber":795,"sourceCode":"          metadata,\n          version,\n          provenance,\n          grouping,\n        });\n        return {\n          experimentId: created.experimentId,\n          status: created.status,\n          totalItems: created.totalItems,\n          datasetVersion: created.datasetVersion,\n          succeededCount: 0,\n          failedCount: 0,\n          startedAt: created.startedAt,\n          completedAt: null,\n          results: [],\n        };\n      }\n      if (!targetType || !targetId) {\n        throw new HTTPException(400, { message: 'targetType and targetId are required to start an experiment' });\n      }\n      const result = await ds.startExperimentAsync({\n        targetType,\n        targetId,\n        name,\n        description,\n        metadata,\n        scorers: scorerIds,\n        version,\n        agentVersion,\n        maxConcurrency,\n        provenance,\n        grouping,\n        requestContext,\n        versions,\n      });\n      // Return shape matching experimentSummaryResponseSchema\n      return {","sourceCodeStart":777,"sourceCodeEnd":813,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/datasets.ts#L777-L813","documentation":"A client-input HTTPException(400): the trigger/start-experiment route allows a 'dry' path that returns a pre-created experiment shell only when targetType/targetId are resolvable; otherwise it requires both fields to actually start an experiment. The request reached the route without the mandatory targetType or targetId body/query parameters.","triggerScenarios":"POST to the start/trigger experiment endpoint omitting either targetType or targetId while not hitting the pre-created-experiment branch (no already-created experiment with results shell).","commonSituations":"Frontend forms not sending the target fields; API consumers copying an example that only created a placeholder experiment; renaming of fields in client SDKs causing targetType/targetId to serialize as undefined.","solutions":["Include both targetType and targetId in the request payload (e.g. targetType: 'agent' | 'workflow' and the id of that target).","Verify the client SDK/serialization actually sends the fields (no undefined dropped by JSON.stringify).","Update to a matching client/server version if field names diverged."],"exampleFix":"// before\nawait fetch('/api/datasets/ds_1/experiments', { method: 'POST', body: JSON.stringify({ name: 'run' }) });\n// after\nawait fetch('/api/datasets/ds_1/experiments', { method: 'POST', body: JSON.stringify({ name: 'run', targetType: 'agent', targetId: 'my-agent' }) });","handlingStrategy":"validation","validationCode":"if (!targetType || !targetId) {\n  throw new Error('targetType and targetId are required to start an experiment');\n}","typeGuard":"function canStartExperiment(p: unknown): p is { targetType: string; targetId: string } {\n  const q = p as any;\n  return typeof q?.targetType === 'string' && q.targetType.length > 0 && typeof q?.targetId === 'string' && q.targetId.length > 0;\n}","tryCatchPattern":"try {\n  await triggerExperiment(payload);\n} catch (e) {\n  if ((e as Error).message.includes('targetType and targetId are required')) {\n    // correct the payload before retry\n  }\n}","preventionTips":["Build request payloads from a typed schema that requires targetType/targetId.","Add form/schema validation in the UI before submitting.","Beware JSON.stringify dropping undefined fields — default them explicitly."],"tags":["validation","http-400","experiments","client-input"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}