{"record":{"id":"ecbdcd40215de5e5","repo":"linshenkx/prompt-optimizer","slug":"generation-result-must-have-a-summary-string","errorCode":null,"errorMessage":"Generation result must have a \"summary\" string.","messagePattern":"Generation result must have a \"summary\" string\\.","errorType":"validation","errorClass":"VariableValueGenerationParseError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/variable-value-generation/service.ts","lineNumber":210,"sourceCode":"\n  /**\n   * 标准化并验证生成响应\n   * 🔧 修复：添加变量对齐校验，确保返回的变量与请求一致\n   */\n  private normalizeGenerationResponse(\n    data: any,\n    requestedVariables: VariableToGenerate[]\n  ): VariableValueGenerationResponse {\n    if (!data || typeof data !== 'object') {\n      throw new VariableValueGenerationParseError('Generation result is not a valid object.');\n    }\n\n    if (!Array.isArray(data.values)) {\n      throw new VariableValueGenerationParseError('Generation result must have a \"values\" array.');\n    }\n\n    if (typeof data.summary !== 'string') {\n      throw new VariableValueGenerationParseError('Generation result must have a \"summary\" string.');\n    }\n\n    // 构建请求变量名集合（用于快速查找）\n    // 🔧 对请求变量名也进行trim，避免首尾空格导致匹配失败\n    const requestedNames = new Set(requestedVariables.map(v => v.name.trim()));\n\n    // 标准化每个生成的值\n    const rawValues: GeneratedVariableValue[] = data.values.map((item: any, index: number) => {\n      if (!item || typeof item !== 'object') {\n        throw new VariableValueGenerationParseError(`values[${index}] is not a valid object.`);\n      }\n\n      if (typeof item.name !== 'string' || !item.name.trim()) {\n        throw new VariableValueGenerationParseError(`values[${index}] is missing a valid \"name\" field.`);\n      }\n\n      if (typeof item.value !== 'string') {\n        throw new VariableValueGenerationParseError(`values[${index}] is missing a valid \"value\" field.`);","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/variable-value-generation/service.ts#L192-L228","documentation":"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).","triggerScenarios":"Model returns { values: [...] } with no summary, or summary: 123 / summary: null / summary: { text: '...' }.","commonSituations":"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.","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"],"exampleFix":"// before\nconst out = await gen.generate(req);\n\n// after\nconst parsed = JSON.parse(text);\nif (typeof parsed.summary !== 'string') parsed.summary = '';\n// then proceed / re-serialize if the pipeline re-parses","handlingStrategy":"validation","validationCode":"if (typeof parsed.summary !== 'string') parsed.summary = '';","typeGuard":"const hasSummary = (d: any) => typeof d?.summary === 'string';","tryCatchPattern":"catch (e) { if (e instanceof VariableValueGenerationParseError && /summary/.test(e.message)) { /* default-fill summary and retry */ } throw e; }","preventionTips":["Include summary in the template example to make it non-optional","Default-fill non-critical string fields when you own the payload"],"tags":["llm-output","schema-validation","json","variable-value-generation"],"backgroundTag":"llm-response-schema-invalid","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}