Skip to content

datarobot_genai.eval.converter

converter

convert_csv_to_cases

convert_csv_to_cases(csv_path: Path) -> list[dict[str, Any]]

Read a CSV dataset and return a list of case dicts.

Required columns: id, source, input. All other columns are preserved as-is. Empty cells come through as empty strings (CSV has no null).

Source code in datarobot_genai/eval/converter.py
def convert_csv_to_cases(csv_path: Path) -> list[dict[str, Any]]:
    """Read a CSV dataset and return a list of case dicts.

    Required columns: id, source, input.
    All other columns are preserved as-is.
    Empty cells come through as empty strings (CSV has no null).
    """
    with open(csv_path, encoding="utf-8", newline="") as f:
        reader = csv.DictReader(f)

        if not reader.fieldnames:
            raise ValueError(f"{csv_path}: CSV has no header row")

        headers = set(reader.fieldnames)
        missing = REQUIRED_FIELDS - headers
        if missing:
            raise ValueError(f"{csv_path}: missing required columns: {sorted(missing)}")

        if "notes" not in headers:
            warnings.warn(
                f"{csv_path}: no 'notes' column found — notes are recommended for "
                "describing expected behavior per case",
                UserWarning,
                stacklevel=2,
            )

        return [dict(row) for row in reader]