{"record":{"id":"e1d7134e09ea689d","repo":"deepset-ai/haystack","slug":"all-lists-in-the-json-must-have-the-same-length","errorCode":null,"errorMessage":"All lists in the JSON must have the same length","messagePattern":"All lists in the JSON must have the same length","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/evaluation/eval_run_result.py","lineNumber":75,"sourceCode":"            if len(outputs[\"individual_scores\"]) != expected_len:\n                raise ValueError(\n                    f\"Length of individual scores for '{metric}' should be the same as the inputs. \"\n                    f\"Got {len(outputs['individual_scores'])} but expected {expected_len}.\"\n                )\n\n    @staticmethod\n    def _write_to_csv(csv_file: str, data: dict[str, list[Any]]) -> str:\n        \"\"\"\n        Write data to a CSV file.\n\n        :param csv_file: Path to the CSV file to write\n        :param data: Dictionary containing the data to write\n        :return: Status message indicating success or failure\n        \"\"\"\n        list_lengths = [len(value) for value in data.values()]\n\n        if len(set(list_lengths)) != 1:\n            raise ValueError(\"All lists in the JSON must have the same length\")\n\n        try:\n            headers = list(data.keys())\n            num_rows = list_lengths[0]\n            rows = []\n\n            for i in range(num_rows):\n                row = [data[header][i] for header in headers]\n                rows.append(row)\n\n            with open(csv_file, \"w\", newline=\"\") as csvfile:\n                writer = csv.writer(csvfile)\n                writer.writerow(headers)\n                writer.writerows(rows)\n\n            return f\"Data successfully written to {csv_file}\"\n        except PermissionError:\n            return f\"Error: Permission denied when writing to {csv_file}\"","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/evaluation/eval_run_result.py#L57-L93","documentation":"EvaluationRunResult._write_to_csv writes a rectangular table, so every list in the data dict must have the same length. If the lengths differ, no row alignment is possible and a ValueError is raised before any file is written.","triggerScenarios":"Calling aggregated_report/detailed_report(output_format='csv', csv_file=...) when the internal data dict has columns of unequal length — normally caused by constructing EvaluationRunResult with mismatched individual_scores that bypassed checks (e.g. mutated after construction).","commonSituations":"Manually mutating a result object's results dict after construction; a custom subclass overriding report generation; corrupted evaluation data loaded back from disk.","solutions":["Make all columns equal length before requesting CSV output (pad with None or trim).","Re-create the EvaluationRunResult with validated, length-matched data.","Use output_format='json' or 'df' if ragged data is intentional."],"exampleFix":"// before\ndata = {'inputs': [1, 2, 3], 'scores': [1, 2]}\n_write_to_csv('out.csv', data)\n// after\ndata['scores'] = data['scores'] + [None]\n_write_to_csv('out.csv', data)","handlingStrategy":"validation","validationCode":"lengths = {k: len(v) for k, v in data.items()}\nif len(set(lengths.values())) != 1:\n    raise ValueError(f'Unequal column lengths: {lengths}')","typeGuard":"null","tryCatchPattern":"try:\n    run.detailed_report(output_format='csv', csv_file='out.csv')\nexcept ValueError as e:\n    if 'same length' in str(e):\n        run.detailed_report(output_format='json')  # fall back to non-rectangular format\n    else:\n        raise","preventionTips":["Keep all result columns the same length as the inputs","Avoid mutating EvaluationRunResult internals after construction","Pad missing values with None instead of dropping rows"],"tags":["python","csv","evaluation"],"backgroundTag":"length-mismatch","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}