linshenkx/prompt-optimizer · error · EvaluationTemplateError

${templateId}

Error message

${templateId}

What it means

EvaluationTemplateError is thrown by getEvaluationTemplate when the template for the computed templateId exists but has no content, or when the underlying lookup throws a non-EvaluationTemplateError. The message is the templateId; code is TEMPLATE_NOT_FOUND with params.context = templateId. Evaluation templates are selected per (evaluationType, mode.functionMode, mode.subMode).

Source

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

   */
  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> {
    const templateId = this.getTemplateId(type, mode);

    try {
      const template = await this.templateManager.getTemplate(templateId);
      if (!template?.content) {
        throw new EvaluationTemplateError(templateId);
      }
      return template;
    } catch (error) {
      if (error instanceof EvaluationTemplateError) {
        throw error;
      }
      throw new EvaluationTemplateError(templateId);
    }
  }

  /**
   * 根据评估类型和模式获取模板ID
   */
  private getTemplateId(type: EvaluationType, mode: EvaluationModeConfig): string {
    return `evaluation-${mode.functionMode}-${mode.subMode}-${type}`;
  }

  /**

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Register the built-in evaluation templates (or your custom template) with TemplateManager for the failing templateId
  2. Check that the template record actually has non-empty content
  3. Verify functionMode/subMode values map to an existing template id via getTemplateId
  4. Re-seed template data after upgrades that change template ids

Example fix

// before
const svc = new EvaluationService({ templateManager }); // templates never registered
await svc.evaluate(req);

// after
await templateManager.registerTemplate(builtinEvaluationTemplates);
const svc = new EvaluationService({ templateManager });
await svc.evaluate(req);
Defensive patterns

Strategy: try-catch

Validate before calling

const t = await templateManager.getTemplate(expectedTemplateId);
if (!t?.content) throw new Error(`Template '${expectedTemplateId}' missing; register built-ins`);

Try / catch

try { await svc.evaluate(req); } catch (e) { if (e instanceof EvaluationTemplateError) { await seedBuiltinTemplates(); return svc.evaluate(req); } throw e; }

Prevention

When it happens

Trigger: Calling evaluate/evaluateStream or the template() accessor where templateManager.getTemplate(templateId) resolves to null/undefined or a template whose content is empty — e.g. built-in evaluation templates were not registered or a custom mode combination has no template.

Common situations: Skipping template registration during service bootstrap; upgrading the library where template ids changed; custom functionMode/subMode combos that no bundled template covers; template stored in DB with empty content.

Related errors


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