mastra-ai/mastra · error · MastraError

EXPERIMENT_RESULT_MISSING_EXPERIMENT_ID

EXPERIMENT_RESULT_MISSING_EXPERIMENT_ID

Error message

updateExperimentResult requires experimentId when called via a Dataset handle

What it means

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.

Source

Thrown at packages/core/src/datasets/dataset.ts:569

    const experimentsStore = await this.#getExperimentsStore();
    return experimentsStore.listExperimentResults({
      experimentId: args.experimentId,
      ...(args.traceId !== undefined ? { traceId: args.traceId } : {}),
      ...(args.status !== undefined ? { status: args.status } : {}),
      ...(args.filters !== undefined ? { filters: args.filters } : {}),
      pagination: { page: args?.page ?? 0, perPage: args?.perPage ?? 20 },
    });
  }

  /**
   * Update an experiment result's status or tags.
   */
  async updateExperimentResult(input: UpdateExperimentResultInput & { experimentId: string }) {
    // The result's parent experiment must belong to this dataset. If the
    // caller supplied `experimentId`, verify ownership on that; otherwise we
    // cannot bind the update to this dataset and must reject.
    if (!input.experimentId) {
      throw new MastraError({
        id: 'EXPERIMENT_RESULT_MISSING_EXPERIMENT_ID',
        text: 'updateExperimentResult requires experimentId when called via a Dataset handle',
        domain: 'STORAGE',
        category: 'USER',
      });
    }
    await this.#assertExperimentOwnership(input.experimentId);
    const experimentsStore = await this.#getExperimentsStore();
    return experimentsStore.updateExperimentResult(input);
  }

  // ---------------------------------------------------------------------------
  // Caller-driven experiments (caller owns the loop)
  // ---------------------------------------------------------------------------

  /**
   * Load an experiment owned by this dataset (tenancy + dataset ownership).
   * Used by the caller-driven methods so a caller cannot mutate another

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Include experimentId in the input object
  2. If you only have the result id, look up the experiment id first and pass it
  3. Use the experiment-level API (where the experiment is already bound) if updating a single experiment's results

Example fix

// before
await dataset.updateExperimentResult({ resultId: 'r1', score: 0.9 });
// after
await dataset.updateExperimentResult({ experimentId: 'exp1', resultId: 'r1', score: 0.9 });
Defensive patterns

Strategy: validation

Validate before calling

function requireExperimentId(input: { experimentId?: string }): string {
  if (!input.experimentId) throw new Error('experimentId is required for dataset-scoped updateExperimentResult');
  return input.experimentId;
}

Type guard

function hasExperimentId<T extends { experimentId?: string }>(input: T): input is T & { experimentId: string } { return typeof input.experimentId === 'string' && input.experimentId.length > 0; }

Try / catch

try {
  await dataset.updateExperimentResult(input);
} catch (e) {
  if (isMastraError(e) && e.id === 'EXPERIMENT_RESULT_MISSING_EXPERIMENT_ID') {
    console.error('Pass experimentId in the update input');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling dataset.updateExperimentResult({ ...resultFields }) without experimentId in the input object.

Common situations: Reusing an update payload shaped for a flat/global experiments API; forgetting the id after destructuring; migration from a non-Dataset entry point.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/68afa8e38861144a. Report an issue: GitHub.