linshenkx/prompt-optimizer · error · EvaluationValidationError

Unknown evaluation type: ${(request as any).type}

Error message

Unknown evaluation type: ${(request as any).type}

What it means

Thrown by validateRequest's default branch when request.type is not one of 'result' | 'compare' | 'prompt-only' | 'prompt-iterate'. The message interpolates the offending type value. This is an EvaluationValidationError and typically indicates a typo, a version mismatch, or an unvalidated payload reaching the service.

Source

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

        break;

      case 'prompt-only':
        if (!request.target?.workspacePrompt?.trim()) {
          throw new EvaluationValidationError('Workspace prompt must not be empty.');
        }
        break;

      case 'prompt-iterate':
        if (!request.target?.workspacePrompt?.trim()) {
          throw new EvaluationValidationError('Workspace prompt must not be empty.');
        }
        if (!request.iterateRequirement?.trim()) {
          throw new EvaluationValidationError('Iteration requirement must not be empty.');
        }
        break;

      default:
        throw new EvaluationValidationError(`Unknown evaluation type: ${(request as any).type}`);
    }
  }

  /**
   * 验证评估模型
   */
  private async validateModel(modelKey: string): Promise<TextModelConfig> {
    const model = await this.modelManager.getModel(modelKey);
    if (!model) {
      throw new EvaluationModelError(modelKey);
    }
    return model;
  }

  /**
   * 获取评估模板
   */
  private async getEvaluationTemplate(type: EvaluationType, mode: EvaluationModeConfig): Promise<Template> {

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Correct request.type to one of the four supported literals
  2. Type the request as the library's EvaluationRequest union so TypeScript rejects unknown types at compile time
  3. Validate inbound payloads (e.g. zod enum) before forwarding to evaluate
  4. Align client and service versions if the type is genuinely new

Example fix

// before
await svc.evaluate({ type: 'comparison', ... } as any);

// after
import type { EvaluationRequest } from '...';
const req: EvaluationRequest = { type: 'compare', ... };
await svc.evaluate(req);
Defensive patterns

Strategy: type-guard

Validate before calling

const TYPES = ['result','compare','prompt-only','prompt-iterate'] as const;
if (!TYPES.includes(req.type)) throw new Error(`Unsupported type ${req.type}`);

Type guard

const isEvaluationType = (t: unknown): t is 'result'|'compare'|'prompt-only'|'prompt-iterate' =>
  ['result','compare','prompt-only','prompt-iterate'].includes(t as string);

Prevention

When it happens

Trigger: evaluate({type:'results'}), type:'comparison', type:undefined, or any string outside the four supported literals (e.g. after a new type was added upstream but the caller is on an older SDK, or vice versa).

Common situations: Typos in the type field; sending raw JSON from an API without validating the discriminant; version skew where a newer client sends a type an older service build doesn't know; discriminated-union not enforced in caller types.

Related errors


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