linshenkx/prompt-optimizer · error · VariableValueGenerationExecutionError
Template "${templateId}" not found or empty.
Error message
Template "${templateId}" not found or empty. What it means
The value-generation service renders the built-in template with id 'variable-value-generation' from the template manager. If getTemplate returns nothing or the template has empty content, VariableValueGenerationExecutionError is thrown because the LLM prompt cannot be constructed.
Source
Thrown at packages/core/src/services/variable-value-generation/service.ts:116
* 验证模型是否存在
*/
private async validateModel(modelKey: string): Promise<void> {
const model = await this.modelManager.getModel(modelKey);
if (!model) {
throw new VariableValueGenerationModelError(modelKey);
}
}
/**
* 获取变量值生成模板
*/
private async getGenerationTemplate(): Promise<Template> {
const templateId = 'variable-value-generation';
try {
const template = await this.templateManager.getTemplate(templateId);
if (!template?.content) {
throw new VariableValueGenerationExecutionError(`Template "${templateId}" not found or empty.`);
}
return template;
} catch (error) {
if (error instanceof VariableValueGenerationError) {
throw error
}
if (typeof (error as any)?.code === 'string') {
throw toErrorWithCode(error)
}
throw new VariableValueGenerationExecutionError(
`Failed to get template "${templateId}": ${error instanceof Error ? error.message : String(error)}`,
)
}
}
/**
* 构建模板上下文
*/View on GitHub (pinned to 3e677b1d9f)
Solutions
- Check the template manager for id 'variable-value-generation' and inspect its content
- Restore/re-import the default template from the library's bundled defaults or reinstall/reseed templates
- Verify the template storage path/env config used by templateManager is correct
- If you intentionally customize it, ensure the saved content is non-empty after edits
Example fix
// before
await gen.generate(req); // throws Template "variable-value-generation" not found or empty.
// after
const t = await templateManager.getTemplate('variable-value-generation');
if (!t?.content) {
await templateManager.saveTemplate({
id: 'variable-value-generation',
content: DEFAULT_GENERATION_TEMPLATE_CONTENT, // bundled default
});
}
await gen.generate(req); Defensive patterns
Strategy: validation
Validate before calling
const t = await templateManager.getTemplate('variable-value-generation');
if (!t?.content?.trim()) throw new Error('generation template missing — reseed defaults'); Try / catch
catch (e) { if (e instanceof VariableValueGenerationExecutionError && /not found or empty/.test(e.message)) { await reseedDefaultTemplates(); return gen.generate(req); } throw e; } Prevention
- Seed/verify built-in templates during app installation and migrations
- Block template-editor saves that would leave content empty
When it happens
Trigger: Calling generate() when the template manager has no template named 'variable-value-generation', or the template exists but its content is '' / whitespace.
Common situations: Fresh install where the bundled template was never seeded; user edited/deleted the template in the template manager UI; template storage pointing at a stale/missing directory; template sync migration skipped in an upgrade; empty template file created by a failed write.
Related errors
- Failed to get template "${templateId}": ${error instanceof E
- error instanceof Error ? error.message : String(error)
- Prompt content must not be empty.
- Generation model key must not be empty.
- Variables list must not be empty.
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/c61f30aba30419d5.
Report an issue: GitHub.