linshenkx/prompt-optimizer · error · EvaluationValidationError

${label} promptRef.kind must not be empty.

Error message

${label} promptRef.kind must not be empty.

What it means

EvaluationValidationError thrown when snapshot.promptRef.kind is falsy. promptRef records what kind of prompt produced the run (e.g. a specific prompt/template reference) and its kind discriminator is mandatory. A missing kind makes the reference unresolvable, so validation fails.

Source

Thrown at packages/core/src/services/evaluation/service.ts:1736

  private validateSnapshot(snapshot: EvaluationSnapshot | undefined, label: string): void {
    if (!snapshot?.id?.trim()) {
      throw new EvaluationValidationError(`${label} id must not be empty.`);
    }
    if (!snapshot?.label?.trim()) {
      throw new EvaluationValidationError(`${label} label must not be empty.`);
    }
    if (!snapshot?.testCaseId?.trim()) {
      throw new EvaluationValidationError(`${label} testCaseId must not be empty.`);
    }
    if (!snapshot?.promptText?.trim()) {
      throw new EvaluationValidationError(`${label} promptText must not be empty.`);
    }
    if (!snapshot?.output?.trim()) {
      throw new EvaluationValidationError(`${label} output must not be empty.`);
    }
    if (!snapshot?.promptRef?.kind) {
      throw new EvaluationValidationError(`${label} promptRef.kind must not be empty.`);
    }
    if (snapshot.executionInput) {
      this.validateContentBlock(snapshot.executionInput, `${label} executionInput`);
    }
    if (snapshot.outputBlock) {
      this.validateContentBlock(snapshot.outputBlock, `${label} outputBlock`);
    }
  }

  private normalizeContentBlock(block?: EvaluationContentBlock): NormalizedContentBlock | undefined {
    const label = block?.label?.trim() || '';
    const content = block?.content?.trim() || '';
    if (!label || (!content && !this.hasBlockMedia(block))) {
      return undefined;
    }

    const summary = block?.summary?.trim() || '';
    return {

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Set snapshot.promptRef = { kind: <valid kind>, ... } matching the supported prompt reference kinds
  2. Check the PromptRef type/union in the package for the accepted kind values
  3. Upgrade callers to the schema version that requires promptRef and regenerate types

Example fix

// before
const snap = { ...base, promptRef: { id: prompt.id } };

// after
const snap = { ...base, promptRef: { kind: 'prompt', id: prompt.id } };
Defensive patterns

Strategy: validation

Validate before calling

const PROMPT_REF_KINDS = ['prompt','template'] as const; // check package's PromptRef type for real values
if (!PROMPT_REF_KINDS.includes(snapshot.promptRef?.kind)) throw new Error('promptRef.kind missing/invalid');

Type guard

function isPromptRef(v: unknown): v is { kind: string } { return typeof (v as any)?.kind === 'string' && (v as any).kind !== ''; }

Prevention

When it happens

Trigger: Providing a snapshot with promptRef omitted entirely, set to null, or an object without a kind property (or kind: '').

Common situations: Optional promptRef added in a newer version of the schema but old callers don't send it; constructing promptRef: { id } while forgetting kind; deserialization dropping discriminated-union fields.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/43cb5b019e59a0f4. Report an issue: GitHub.