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
- Correct request.type to one of the four supported literals
- Type the request as the library's EvaluationRequest union so TypeScript rejects unknown types at compile time
- Validate inbound payloads (e.g. zod enum) before forwarding to evaluate
- 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
- Type requests as EvaluationRequest so TS catches bad discriminants
- Validate external payloads (zod enum) before forwarding
- Keep client and service versions aligned
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
- ${label} promptRef.kind must not be empty.
- Result evaluation snapshot testCaseId must match testCase.id
- Image result evaluation requires at least one output image e
- Compare evaluation requires at least one test case.
- Compare evaluation requires at least two snapshots.
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/2c710d93d3b07852.
Report an issue: GitHub.