{"record":{"id":"73fc3bba8eeeeb16","repo":"linshenkx/prompt-optimizer","slug":"compare-evaluation-requires-at-least-two-snapshots","errorCode":null,"errorMessage":"Compare evaluation requires at least two snapshots.","messagePattern":"Compare evaluation requires at least two snapshots\\.","errorType":"validation","errorClass":"EvaluationValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/evaluation/service.ts","lineNumber":494,"sourceCode":"            'Result evaluation snapshot testCaseId must match testCase.id.'\n          );\n        }\n        if (this.isImageText2ImageMode(request) && !this.hasSnapshotOutputMedia(request.snapshot)) {\n          throw new EvaluationValidationError(\n            'Image result evaluation requires at least one output image evidence item.'\n          );\n        }\n        break;\n\n      case 'compare':\n        if (!request.target?.workspacePrompt?.trim()) {\n          throw new EvaluationValidationError('Workspace prompt must not be empty.');\n        }\n        if (!Array.isArray(request.testCases) || request.testCases.length < 1) {\n          throw new EvaluationValidationError('Compare evaluation requires at least one test case.');\n        }\n        if (!Array.isArray(request.snapshots) || request.snapshots.length < 2) {\n          throw new EvaluationValidationError('Compare evaluation requires at least two snapshots.');\n        }\n\n        const testCaseIds = new Set<string>();\n        request.testCases.forEach((testCase, index) => {\n          this.validateTestCase(testCase, `Compare test case #${index + 1}`);\n          if (testCaseIds.has(testCase.id)) {\n            throw new EvaluationValidationError(\n              `Compare test case #${index + 1} id must be unique.`\n            );\n          }\n          testCaseIds.add(testCase.id);\n        });\n\n        request.snapshots.forEach((snapshot, index) => {\n          this.validateSnapshot(snapshot, `Compare snapshot #${index + 1}`);\n          if (!testCaseIds.has(snapshot.testCaseId)) {\n            throw new EvaluationValidationError(\n              `Compare snapshot #${index + 1} references unknown testCaseId \"${snapshot.testCaseId}\".`","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/evaluation/service.ts#L476-L512","documentation":"Thrown for type:'compare' when request.snapshots is missing, not an array, or has fewer than two entries. A comparison needs at least two candidate snapshots to rank against each other, so the service rejects the request during validateRequest with an EvaluationValidationError.","triggerScenarios":"evaluate({type:'compare', snapshots: []}) or snapshots with only one element, or snapshots not an array.","commonSituations":"Only one variant finished generating so the second snapshot is missing; snapshot list built from a single selected run; race where the second snapshot is still being captured when compare fires.","solutions":["Provide at least two snapshots (one per variant/candidate) before comparing","Wait for all variant runs to complete and capture their snapshots before enabling compare","If only one snapshot exists, run a 'result' evaluation instead"],"exampleFix":"// before\nawait svc.evaluate({ type: 'compare', testCases, snapshots: [snapA], ... });\n\n// after\nawait svc.evaluate({ type: 'compare', testCases, snapshots: [snapA, snapB], ... });","handlingStrategy":"validation","validationCode":"if (!Array.isArray(req.snapshots) || req.snapshots.length < 2) throw new Error('Need >=2 snapshots to compare');\nawait svc.evaluate(req);","typeGuard":"const comparable = (r: CompareRequest) => Array.isArray(r.snapshots) && r.snapshots.length >= 2;","tryCatchPattern":null,"preventionTips":["Wait for all variant runs before enabling compare","Show snapshot count in the compare button state"],"tags":["evaluation","validation","compare","snapshot"],"backgroundTag":"insufficient-inputs-for-operation","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}