{"record":{"id":"e4b36c8f0080c822","repo":"n8n-io/n8n","slug":"invalid-response-from-python-script-expected-work","errorCode":null,"errorMessage":"Invalid response from Python script. Expected WorkflowSimilarityResult shape but got: ${stdout.slice(0, 200)}","messagePattern":"Invalid response from Python script\\. Expected WorkflowSimilarityResult shape but got: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/ai-workflow-builder.ee/evaluations/programmatic/evaluators/workflow-similarity.ts","lineNumber":170,"sourceCode":"\n\t\t\t// Only throw if we don't have valid output\n\t\t\tif (!stdout || stdout.trim() === '') {\n\t\t\t\tthrow execError;\n\t\t\t}\n\t\t}\n\n\t\t// Check if stdout is empty\n\t\tif (!stdout || stdout.trim() === '') {\n\t\t\tthrow new Error(\n\t\t\t\t`Python script produced no output. stderr: ${stderr || 'none'}. Command: uvx ${args.join(' ')}`,\n\t\t\t);\n\t\t}\n\n\t\t// Parse result\n\t\tconst parsed: unknown = JSON.parse(stdout);\n\n\t\tif (!isWorkflowSimilarityResult(parsed)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid response from Python script. Expected WorkflowSimilarityResult shape but got: ${stdout.slice(0, 200)}`,\n\t\t\t);\n\t\t}\n\n\t\t// Convert Python result to SingleEvaluatorResult format\n\t\tconst violations = parsed.top_edits.map((edit) => ({\n\t\t\tname: mapEditTypeToViolationName(edit.type),\n\t\t\ttype: edit.priority,\n\t\t\tdescription: edit.description,\n\t\t\tpointsDeducted: Math.round(edit.cost),\n\t\t}));\n\n\t\treturn {\n\t\t\tviolations,\n\t\t\tscore: parsed.similarity_score,\n\t\t};\n\t} catch (error) {\n\t\t// Handle specific error cases","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/ai-workflow-builder.ee/evaluations/programmatic/evaluators/workflow-similarity.ts#L152-L188","documentation":"Schema-validation error in evaluateWorkflowSimilarity. It fires after JSON.parse succeeded but the parsed object fails the isWorkflowSimilarityResult type guard — the script emitted JSON that is not the expected result shape. The first 200 characters of stdout are included for diagnosis.","triggerScenarios":"Thrown at packages/@n8n/ai-workflow-builder.ee/evaluations/programmatic/evaluators/workflow-similarity.ts:170 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the Python script and uvx environment; the script exited 0 but printed non-JSON or wrong-shaped output.","Run the same uvx command manually and inspect stdout for warnings or progress text polluting the JSON.","Pin/refresh the similarity script's dependencies so its output schema matches isWorkflowSimilarityResult."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","contentChangedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}