linshenkx/prompt-optimizer · error · EvaluationValidationError
Evaluation mode configuration must not be empty.
Error message
Evaluation mode configuration must not be empty.
What it means
Catch-all OptimizationError thrown at the end of optimizePrompt: any error raised inside the method (validation, model lookup, template resolution, LLM call, response validation) is re-wrapped as 'Optimization failed: <original message>'. The original message is embedded, so the underlying cause is discoverable from the string.
Source
Thrown at packages/core/src/services/evaluation/service.ts:458
callbacks.onError(
new EvaluationExecutionError(
this.formatExecutionErrorMessage(error),
error instanceof Error ? error : undefined
)
);
}
}
/**
* 验证评估请求
*/
private validateRequest(request: EvaluationRequest): void {
if (!request.evaluationModelKey?.trim()) {
throw new EvaluationValidationError('Evaluation model key must not be empty.');
}
if (!request.mode) {
throw new EvaluationValidationError('Evaluation mode configuration must not be empty.');
}
if (!request.mode.functionMode) {
throw new EvaluationValidationError('Function mode must not be empty.');
}
if (!request.mode.subMode) {
throw new EvaluationValidationError('Sub mode must not be empty.');
}
switch (request.type) {
case 'result':
if (!request.target?.workspacePrompt?.trim()) {
throw new EvaluationValidationError('Workspace prompt must not be empty.');
}
this.validateTestCase(request.testCase, 'Result evaluation test case');
this.validateSnapshot(request.snapshot, 'Result evaluation snapshot');
if (request.snapshot.testCaseId !== request.testCase.id) {
throw new EvaluationValidationError(
'Result evaluation snapshot testCaseId must match testCase.id.'View on GitHub (pinned to 3e677b1d9f)
Solutions
- Parse the suffix after 'Optimization failed: ' to get the real cause (e.g. '401 Unauthorized' means check API key; timeout means retry).
- Enable request/transport logging on the LLM service to see the raw failure.
- Fix the root cause per the embedded message: credentials, connectivity, model availability, or template config.
- Avoid catching and stringifying errors yourself — check for typed errors (OptimizationError preserves only the message here) and log full context.
Example fix
// before
try { await promptService.optimizePrompt(req); }
catch (e) { console.error(String(e)); }
// after
try { await promptService.optimizePrompt(req); }
catch (e) {
const cause = e instanceof Error && e.message.startsWith('Optimization failed:')
? e.message.slice('Optimization failed:'.length).trim()
: String(e);
console.error('Root cause:', cause);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!providerConfig.apiKey) throw new Error('Missing API key');
if (!(await modelManager.getModel(req.modelKey))) throw new Error('Model not found'); Type guard
function isOptimizationError(e: unknown): e is OptimizationError { return e instanceof OptimizationError; }
function rootCause(e: unknown): string {
const m = e instanceof Error ? e.message : String(e);
return m.replace(/^Optimization failed:\s*/, '');
} Try / catch
try { return await svc.optimizePrompt(req); }
catch (e) { const cause = rootCause(e); if (/401|unauthorized/i.test(cause)) refreshCredentials(); else if (/timeout|network/i.test(cause)) return retry(); else throw e; } Prevention
- Pre-validate model and provider config to avoid the wrapper
- Parse the embedded root-cause message before deciding handling
- Log the full error with stack, not the flattened message
When it happens
Trigger: Any failure inside optimizePrompt that isn't rethrown with its own type — LLM provider network error, timeout, image-understanding service missing, template errors — all surface as this wrapped message.
Common situations: API key invalid/expired causing provider 401, network offline, template manager not initialized, rate limits — anything mid-pipeline; developers lose the error class because it's flattened into a message string.
Related errors
- Workspace prompt must not be empty.
- Evaluation model key must not be empty.
- Iteration requirement must not be empty.
- ${label} promptText must not be empty.
- Failed to add favorite: ${errorMessage}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/91c4ad0b06fe88fc.
Report an issue: GitHub.