mastra-ai/mastra · error · Error

Unknown target type: ${targetType}

Error message

Unknown target type: ${targetType}

What it means

executeTarget's switch statement hits its default branch when the experiment target type is not one of the recognized kinds (agent/tool/workflow/scorer; processor is separately rejected). This indicates an invalid or unrecognized targetType value reached the executor.

Source

Thrown at packages/core/src/datasets/experiment/executor.ts:167

          signal,
          options?.requestContext,
          options?.experimentId,
          options?.versions,
          options?.toolMocks,
          options?.unmockedToolPolicy,
        );
        break;
      case 'workflow':
        executionPromise = executeWorkflow(target as Workflow, item, options?.requestContext);
        break;
      case 'scorer':
        executionPromise = executeScorer(target as MastraScorer<any, any, any, any>, item);
        break;
      case 'processor':
        // Processor targets dropped from roadmap - not a core use case
        throw new Error(`Target type '${targetType}' not yet supported.`);
      default:
        throw new Error(`Unknown target type: ${targetType}`);
    }

    // Race execution against signal abort (ensures timeout works even if target ignores signal)
    if (signal) {
      return await raceWithSignal(executionPromise, signal);
    }

    return await executionPromise;
  } catch (error) {
    return {
      output: null,
      error: {
        message: error instanceof Error ? error.message : String(error),
        stack: error instanceof Error ? error.stack : undefined,
      },
      traceId: null,
    };
  }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Set targetType to one of 'agent' | 'tool' | 'workflow' | 'scorer'
  2. Validate/normalize the targetType string (lowercase, trim) before calling runExperiment
  3. If loaded from storage, migrate the persisted experiment config to a supported target type

Example fix

// before
runExperiment({ targetType: 'Agent', targetId: 'my-agent' });
// after
const targetType = 'agent' as const;
runExperiment({ targetType, targetId: 'my-agent' });
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = ['agent', 'tool', 'workflow', 'scorer'] as const;
if (!SUPPORTED.includes(targetType)) {
  throw new Error(`Invalid targetType: ${targetType}`);
}

Type guard

type SupportedTargetType = 'agent' | 'tool' | 'workflow' | 'scorer';
function isSupportedTargetType(t: unknown): t is SupportedTargetType {
  return typeof t === 'string' && ['agent', 'tool', 'workflow', 'scorer'].includes(t);
}

Try / catch

try {
  await runExperiment(config);
} catch (err) {
  if (err instanceof Error && err.message.startsWith('Unknown target type')) {
    console.error(`Bad targetType in experiment config: ${err.message}`);
  } else throw err;
}

Prevention

When it happens

Trigger: Passing a misspelled or arbitrary targetType (e.g. 'Agent', 'llm', 'model') to runExperiment, or loading a persisted experiment config whose targetType no longer matches the executor's accepted set.

Common situations: Typo or wrong casing in config files; dynamic targetType built from user input; schema drift after upgrading @mastra/core where allowed target types changed.

Related errors


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