{"record":{"id":"f2b4e7dcd259039a","repo":"linshenkx/prompt-optimizer","slug":"values-index-is-not-a-valid-object","errorCode":null,"errorMessage":"values[${index}] is not a valid object.","messagePattern":"values\\[(.+?)\\] is not a valid object\\.","errorType":"validation","errorClass":"VariableValueGenerationParseError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/variable-value-generation/service.ts","lineNumber":220,"sourceCode":"      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.`);\n      }\n\n      if (typeof item.reason !== 'string') {\n        throw new VariableValueGenerationParseError(`values[${index}] is missing a valid \"reason\" field.`);\n      }\n\n      return {\n        name: item.name.trim(),\n        value: item.value,\n        reason: item.reason,","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/variable-value-generation/service.ts#L202-L238","documentation":"Each entry of the values array must be an object. normalizeGenerationResponse maps over data.values and throws VariableValueGenerationParseError with the failing index when an item is null, a primitive (string/number/boolean), or an array.","triggerScenarios":"values: [ \"var1=hello\", { name: 'var2', ... } ] — a mix of strings and objects — or values: [null, {...}] when the model emitted nulls for variables it could not generate.","commonSituations":"Model outputs compact 'name=value' strings for simple cases but objects for complex ones; model emits null placeholders for un-generatable variables; template examples inconsistent about item shape.","solutions":["Filter/normalize non-object entries before parsing: drop nulls, or parse 'name=value' strings into objects","Make the template's few-shot examples consistently object-shaped","If nulls appear for specific variables, decide policy: drop them or re-request those variables individually"],"exampleFix":"// before\nconst out = await gen.generate(req);\n\n// after\nconst parsed = JSON.parse(text);\nparsed.values = (parsed.values ?? []).filter(v => v && typeof v === 'object' && !Array.isArray(v));","handlingStrategy":"type-guard","validationCode":"parsed.values = (parsed.values ?? []).filter(v => v && typeof v === 'object' && !Array.isArray(v));","typeGuard":"const isValueItem = (v: any): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v);","tryCatchPattern":"catch (e) { if (e instanceof VariableValueGenerationParseError && /not a valid object/.test(e.message)) { /* filter non-object items and retry */ } throw e; }","preventionTips":["Keep template examples uniform — every values item must be an object","Drop model-emitted null placeholders before normalization"],"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"}