linshenkx/prompt-optimizer · error · VariableValueGenerationModelError
VariableValueGenerationModelError(modelKey)
Error message
VariableValueGenerationModelError(modelKey)
What it means
generate() calls validateModel which looks the key up via modelManager.getModel(modelKey); if the manager returns nothing, VariableValueGenerationModelError is thrown. The key passed validation (non-empty string) but no model with that key is registered.
Source
Thrown at packages/core/src/services/variable-value-generation/service.ts:103
throw new VariableValueGenerationValidationError('Variables list must not be empty.');
}
// 验证每个变量
for (let i = 0; i < request.variables.length; i++) {
const variable = request.variables[i];
if (!variable.name?.trim()) {
throw new VariableValueGenerationValidationError(`Variable at index ${i} has empty name.`);
}
}
}
/**
* 验证模型是否存在
*/
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 errorView on GitHub (pinned to 3e677b1d9f)
Solutions
- Call modelManager.getModel(key) (or list all models) before generate to verify the key exists
- Register the missing model via the model manager, or fix the key to match an existing model's exact id
- Persist and reload the model registry consistently across app restarts/environments
- Catch VariableValueGenerationModelError and prompt the user to pick an available model
Example fix
// before
await gen.generate({ ...req, generationModelKey: 'gpt-4o' });
// after
const model = await modelManager.getModel('gpt-4o');
if (!model) {
const available = await modelManager.listModels();
throw new Error(`Model not found. Available: ${available.map(m => m.key).join(', ')}`);
}
await gen.generate({ ...req, generationModelKey: 'gpt-4o' }); Defensive patterns
Strategy: validation
Validate before calling
const model = await modelManager.getModel(key);
if (!model) { const available = await modelManager.listModels(); throw new Error(`Unknown model ${key}. Available: ${available.map(m => m.key).join(', ')}`); } Try / catch
catch (e) { if (e instanceof VariableValueGenerationModelError) { /* re-prompt user to select a valid model */ } throw e; } Prevention
- Validate model keys against the manager's registry before any generate() call
- Keep model configuration persisted and re-validated on startup
When it happens
Trigger: generate({ ..., generationModelKey: 'my-model' }) when 'my-model' was never added to (or was removed from) the model manager's registry.
Common situations: Model was deleted or renamed by the user after the request was built; models stored in a config/database that differs between environments (dev vs prod); key casing or whitespace mismatch; the model manager was initialized with a different storage path; fresh install with no models configured yet.
Related errors
- Generation model key must not be empty.
- Data must be an object
- Evaluation model key must not be empty.
- Function mode must not be empty.
- Model config cannot be empty
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/377a50f129710b1d.
Report an issue: GitHub.