{"record":{"id":"68afa8e38861144a","repo":"mastra-ai/mastra","slug":"experiment-result-missing-experiment-id","errorCode":"EXPERIMENT_RESULT_MISSING_EXPERIMENT_ID","errorMessage":"updateExperimentResult requires experimentId when called via a Dataset handle","messagePattern":"updateExperimentResult requires experimentId when called via a Dataset handle","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/datasets/dataset.ts","lineNumber":569,"sourceCode":"    const experimentsStore = await this.#getExperimentsStore();\n    return experimentsStore.listExperimentResults({\n      experimentId: args.experimentId,\n      ...(args.traceId !== undefined ? { traceId: args.traceId } : {}),\n      ...(args.status !== undefined ? { status: args.status } : {}),\n      ...(args.filters !== undefined ? { filters: args.filters } : {}),\n      pagination: { page: args?.page ?? 0, perPage: args?.perPage ?? 20 },\n    });\n  }\n\n  /**\n   * Update an experiment result's status or tags.\n   */\n  async updateExperimentResult(input: UpdateExperimentResultInput & { experimentId: string }) {\n    // The result's parent experiment must belong to this dataset. If the\n    // caller supplied `experimentId`, verify ownership on that; otherwise we\n    // cannot bind the update to this dataset and must reject.\n    if (!input.experimentId) {\n      throw new MastraError({\n        id: 'EXPERIMENT_RESULT_MISSING_EXPERIMENT_ID',\n        text: 'updateExperimentResult requires experimentId when called via a Dataset handle',\n        domain: 'STORAGE',\n        category: 'USER',\n      });\n    }\n    await this.#assertExperimentOwnership(input.experimentId);\n    const experimentsStore = await this.#getExperimentsStore();\n    return experimentsStore.updateExperimentResult(input);\n  }\n\n  // ---------------------------------------------------------------------------\n  // Caller-driven experiments (caller owns the loop)\n  // ---------------------------------------------------------------------------\n\n  /**\n   * Load an experiment owned by this dataset (tenancy + dataset ownership).\n   * Used by the caller-driven methods so a caller cannot mutate another","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/datasets/dataset.ts#L551-L587","documentation":"updateExperimentResult called on a Dataset handle requires input.experimentId, because the update must be bound to a specific experiment owned by this dataset. Without it, Mastra cannot verify which experiment's result to modify and rejects the call.","triggerScenarios":"Calling dataset.updateExperimentResult({ ...resultFields }) without experimentId in the input object.","commonSituations":"Reusing an update payload shaped for a flat/global experiments API; forgetting the id after destructuring; migration from a non-Dataset entry point.","solutions":["Include experimentId in the input object","If you only have the result id, look up the experiment id first and pass it","Use the experiment-level API (where the experiment is already bound) if updating a single experiment's results"],"exampleFix":"// before\nawait dataset.updateExperimentResult({ resultId: 'r1', score: 0.9 });\n// after\nawait dataset.updateExperimentResult({ experimentId: 'exp1', resultId: 'r1', score: 0.9 });","handlingStrategy":"validation","validationCode":"function requireExperimentId(input: { experimentId?: string }): string {\n  if (!input.experimentId) throw new Error('experimentId is required for dataset-scoped updateExperimentResult');\n  return input.experimentId;\n}","typeGuard":"function hasExperimentId<T extends { experimentId?: string }>(input: T): input is T & { experimentId: string } { return typeof input.experimentId === 'string' && input.experimentId.length > 0; }","tryCatchPattern":"try {\n  await dataset.updateExperimentResult(input);\n} catch (e) {\n  if (isMastraError(e) && e.id === 'EXPERIMENT_RESULT_MISSING_EXPERIMENT_ID') {\n    console.error('Pass experimentId in the update input');\n  } else throw e;\n}","preventionTips":["Type update payloads with experimentId: string (required) at call sites","Validate payloads at system boundaries before calling the dataset API","Prefer experiment-level update APIs where the experiment is already bound"],"tags":["storage","experiment","validation","missing-argument"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}