linshenkx/prompt-optimizer · error · VariableValueGenerationParseError
Generation result must have a "summary" string.
Error message
Generation result must have a "summary" string.
What it means
The generation response envelope must include a string 'summary' field describing the generated values. normalizeGenerationResponse rejects responses where summary is missing or not a string (a number/object/null fails).
Source
Thrown at packages/core/src/services/variable-value-generation/service.ts:210
/**
* 标准化并验证生成响应
* 🔧 修复:添加变量对齐校验,确保返回的变量与请求一致
*/
private normalizeGenerationResponse(
data: any,
requestedVariables: VariableToGenerate[]
): VariableValueGenerationResponse {
if (!data || typeof data !== 'object') {
throw new VariableValueGenerationParseError('Generation result is not a valid object.');
}
if (!Array.isArray(data.values)) {
throw new VariableValueGenerationParseError('Generation result must have a "values" array.');
}
if (typeof data.summary !== 'string') {
throw new VariableValueGenerationParseError('Generation result must have a "summary" string.');
}
// 构建请求变量名集合(用于快速查找)
// 🔧 对请求变量名也进行trim,避免首尾空格导致匹配失败
const requestedNames = new Set(requestedVariables.map(v => v.name.trim()));
// 标准化每个生成的值
const rawValues: GeneratedVariableValue[] = data.values.map((item: any, index: number) => {
if (!item || typeof item !== 'object') {
throw new VariableValueGenerationParseError(`values[${index}] is not a valid object.`);
}
if (typeof item.name !== 'string' || !item.name.trim()) {
throw new VariableValueGenerationParseError(`values[${index}] is missing a valid "name" field.`);
}
if (typeof item.value !== 'string') {
throw new VariableValueGenerationParseError(`values[${index}] is missing a valid "value" field.`);View on GitHub (pinned to 3e677b1d9f)
Solutions
- Default-fill summary ('' or 'n/a') in pre-processing if you own the payload
- Add an explicit example with summary in the template
- Increase max_tokens so trailing fields are not truncated
- Retry generation once — summary omission is often stochastic
Example fix
// before const out = await gen.generate(req); // after const parsed = JSON.parse(text); if (typeof parsed.summary !== 'string') parsed.summary = ''; // then proceed / re-serialize if the pipeline re-parses
Defensive patterns
Strategy: validation
Validate before calling
if (typeof parsed.summary !== 'string') parsed.summary = '';
Type guard
const hasSummary = (d: any) => typeof d?.summary === 'string';
Try / catch
catch (e) { if (e instanceof VariableValueGenerationParseError && /summary/.test(e.message)) { /* default-fill summary and retry */ } throw e; } Prevention
- Include summary in the template example to make it non-optional
- Default-fill non-critical string fields when you own the payload
When it happens
Trigger: Model returns { values: [...] } with no summary, or summary: 123 / summary: null / summary: { text: '...' }.
Common situations: Model considers summary optional and drops it when token-constrained; customized template that removed the summary requirement; summary emitted as a nested object by overly literal models; max_tokens truncation after values but before summary.
Related errors
- Generation result is not a valid object.
- Generation result must have a "values" array.
- values[${index}] is not a valid object.
- values[${index}] is missing a valid "name" field.
- values[${index}] is missing a valid "value" field.
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/ecbdcd40215de5e5.
Report an issue: GitHub.