microsoft/graphrag · error · TypeError

value is not a list: {value} ({type(value)})

Error message

value is not a list: {value} ({type(value)})

What it means

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.

Source

Thrown at packages/graphrag/graphrag/query/input/loaders/utils.py:58

    return str(value)


def to_optional_str(data: Mapping[str, Any], column_name: str | None) -> str | None:
    """Convert and validate a value to an optional string."""
    value = _get_value(data, column_name, required=True)
    return None if value is None else str(value)


def to_list(
    data: Mapping[str, Any], column_name: str | None, item_type: type | None = None
) -> list:
    """Convert and validate a value to a list."""
    value = _get_value(data, column_name, required=True)
    if isinstance(value, np.ndarray):
        value = value.tolist()
    if not isinstance(value, list):
        msg = f"value is not a list: {value} ({type(value)})"
        raise TypeError(msg)
    if item_type is not None:
        for v in value:
            if not isinstance(v, item_type):
                msg = f"list item is not [{item_type}]: {v} ({type(v)})"
                raise TypeError(msg)
    return value


def to_optional_list(
    data: Mapping[str, Any], column_name: str | None, item_type: type | None = None
) -> list | None:
    """Convert and validate a value to an optional list."""
    if column_name is None or column_name not in data:
        return None
    value = data[column_name]
    if value is None:
        return None
    if isinstance(value, np.ndarray):

View on GitHub (pinned to f40e9a26ce)

Solutions

  1. Parse stringified lists before calling: ast.literal_eval / json.loads on str values
  2. Ensure the column is stored as a genuine list or numpy array in the parquet artifact
  3. Check for None/scalars in the column and fill or drop those rows

Example fix

# before
ids = to_list(row, 'text_unit_ids')  # value is "['a','b']" string
# after
import ast, json
raw = row['text_unit_ids']
ids = to_list({'text_unit_ids': ast.literal_eval(raw) if isinstance(raw, str) else raw}, 'text_unit_ids')
Defensive patterns

Strategy: type-guard

Validate before calling

import ast, json
raw = data.get(col)
if isinstance(raw, str):
    raw = ast.literal_eval(raw) if raw.startswith('[') else [raw]
data = {**data, col: raw}

Type guard

def is_list_like(v: object) -> bool:
    return isinstance(v, (list, np.ndarray))

Try / catch

try:
    vals = to_list(data, col)
except TypeError:
    vals = json.loads(data[col]) if isinstance(data[col], str) else []

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/graphrag@f40e9a26ce (2026-08-27). Data as JSON: /api/errors/31c3efd1897fca2c. Report an issue: GitHub.