{"record":{"id":"9fa09f8a2d5df59b","repo":"linshenkx/prompt-optimizer","slug":"evaluation-model-key-must-not-be-empty","errorCode":null,"errorMessage":"Evaluation model key must not be empty.","messagePattern":"Evaluation model key must not be empty\\.","errorType":"validation","errorClass":"EvaluationValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/evaluation/service.ts","lineNumber":454,"sourceCode":"\n    try {\n      await this.llmService.sendMessageStream(messages, request.evaluationModelKey, streamHandlers);\n    } catch (error) {\n      callbacks.onError(\n        new EvaluationExecutionError(\n          this.formatExecutionErrorMessage(error),\n          error instanceof Error ? error : undefined\n        )\n      );\n    }\n  }\n\n  /**\n   * 验证评估请求\n   */\n  private validateRequest(request: EvaluationRequest): void {\n    if (!request.evaluationModelKey?.trim()) {\n      throw new EvaluationValidationError('Evaluation model key must not be empty.');\n    }\n\n    if (!request.mode) {\n      throw new EvaluationValidationError('Evaluation mode configuration must not be empty.');\n    }\n    if (!request.mode.functionMode) {\n      throw new EvaluationValidationError('Function mode must not be empty.');\n    }\n    if (!request.mode.subMode) {\n      throw new EvaluationValidationError('Sub mode must not be empty.');\n    }\n\n    switch (request.type) {\n      case 'result':\n        if (!request.target?.workspacePrompt?.trim()) {\n          throw new EvaluationValidationError('Workspace prompt must not be empty.');\n        }\n        this.validateTestCase(request.testCase, 'Result evaluation test case');","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/evaluation/service.ts#L436-L472","documentation":"OptimizationError thrown by optimizePrompt when modelManager.getModel(request.modelKey) resolves to nothing — the requested model key is not in the model registry. It fails before any LLM call, meaning the model was deleted, never existed, or the key is misspelled.","triggerScenarios":"Calling optimizePrompt with a key not present in the model manager — deleted model, typo, key from another environment/profile, or models not yet loaded when the call runs.","commonSituations":"User deletes a model that was set as default; settings imported from another machine referencing missing models; model list loads async and the call races it; key casing or provider-prefix mistakes ('openai/gpt-4' vs 'gpt-4').","solutions":["Verify the key exists first: (await modelManager.listModels()).some(m => m.key === request.modelKey).","Re-point the request at an existing model or re-add the missing model configuration.","Ensure model loading completes (await initialization) before optimization calls.","Fall back to a known-good default model when the requested one is absent."],"exampleFix":"// before\nawait promptService.optimizePrompt({ modelKey: savedKey, targetPrompt: p });\n\n// after\nconst models = await modelManager.listModels();\nconst key = models.some(m => m.key === savedKey) ? savedKey : models[0]?.key;\nif (!key) throw new Error('No models configured');\nawait promptService.optimizePrompt({ modelKey: key, targetPrompt: p });","handlingStrategy":"validation","validationCode":"const models = await modelManager.listModels();\nif (!models.some(m => m.key === request.modelKey)) throw new Error('Model not configured');","typeGuard":"async function modelExists(modelManager: any, key: string): Promise<boolean> {\n  return !!(await modelManager.getModel(key));\n}","tryCatchPattern":"try { await svc.optimizePrompt(req); } catch (e) { if (e instanceof OptimizationError && e.message === 'Model not found') { await refreshModels(); } }","preventionTips":["Validate model keys against the registry before calls","Await model-manager init","Fall back to default model when the saved one is gone"],"tags":["model-config","prompt","not-found"],"backgroundTag":"missing-model-key","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}