{"record":{"id":"31c3efd1897fca2c","repo":"microsoft/graphrag","slug":"value-is-not-a-list-value-type-value","errorCode":null,"errorMessage":"value is not a list: {value} ({type(value)})","messagePattern":"value is not a list: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/graphrag/graphrag/query/input/loaders/utils.py","lineNumber":58,"sourceCode":"    return str(value)\n\n\ndef to_optional_str(data: Mapping[str, Any], column_name: str | None) -> str | None:\n    \"\"\"Convert and validate a value to an optional string.\"\"\"\n    value = _get_value(data, column_name, required=True)\n    return None if value is None else str(value)\n\n\ndef to_list(\n    data: Mapping[str, Any], column_name: str | None, item_type: type | None = None\n) -> list:\n    \"\"\"Convert and validate a value to a list.\"\"\"\n    value = _get_value(data, column_name, required=True)\n    if isinstance(value, np.ndarray):\n        value = value.tolist()\n    if not isinstance(value, list):\n        msg = f\"value is not a list: {value} ({type(value)})\"\n        raise TypeError(msg)\n    if item_type is not None:\n        for v in value:\n            if not isinstance(v, item_type):\n                msg = f\"list item is not [{item_type}]: {v} ({type(v)})\"\n                raise TypeError(msg)\n    return value\n\n\ndef to_optional_list(\n    data: Mapping[str, Any], column_name: str | None, item_type: type | None = None\n) -> list | None:\n    \"\"\"Convert and validate a value to an optional list.\"\"\"\n    if column_name is None or column_name not in data:\n        return None\n    value = data[column_name]\n    if value is None:\n        return None\n    if isinstance(value, np.ndarray):","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/microsoft/graphrag/blob/f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704/packages/graphrag/graphrag/query/input/loaders/utils.py#L40-L76","documentation":"to_list coerces a fetched value to a Python list (numpy arrays are converted via .tolist()), but if the value is any other non-list type — a scalar string, a JSON-encoded string, None, or a dict — it raises TypeError 'value is not a list'. Callers like read_indexer_communities and vector-store similarity search use this to parse list-typed columns such as text_unit_ids.","triggerScenarios":"Calling to_list on a parquet column stored as a string (e.g. \"['a', 'b']\" serialized JSON) instead of a real list/ndarray; a column containing None or scalar values; similarity_search_by_vector receiving malformed stored embeddings metadata.","commonSituations":"Parquet round-trips where list columns were saved as strings; artifacts produced by external tools or hand-edited; pandas dtype changes (object column of scalars) after filtering/concatenation.","solutions":["Parse stringified lists before calling: ast.literal_eval / json.loads on str values","Ensure the column is stored as a genuine list or numpy array in the parquet artifact","Check for None/scalars in the column and fill or drop those rows"],"exampleFix":"# before\nids = to_list(row, 'text_unit_ids')  # value is \"['a','b']\" string\n# after\nimport ast, json\nraw = row['text_unit_ids']\nids = to_list({'text_unit_ids': ast.literal_eval(raw) if isinstance(raw, str) else raw}, 'text_unit_ids')","handlingStrategy":"type-guard","validationCode":"import ast, json\nraw = data.get(col)\nif isinstance(raw, str):\n    raw = ast.literal_eval(raw) if raw.startswith('[') else [raw]\ndata = {**data, col: raw}","typeGuard":"def is_list_like(v: object) -> bool:\n    return isinstance(v, (list, np.ndarray))","tryCatchPattern":"try:\n    vals = to_list(data, col)\nexcept TypeError:\n    vals = json.loads(data[col]) if isinstance(data[col], str) else []","preventionTips":["Ensure list columns are written as native lists, not strings, when saving parquet","Check dtype of list columns after any pandas transformations"],"tags":["graphrag","data-loading","type-error","serialization"],"backgroundTag":"type-validation-failed","analyzedSha":"f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704","analyzedAt":"2026-08-27T11:16:29.677Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}