{"record":{"id":"38c163171aadcef8","repo":"unslothai/unsloth","slug":"dataset-appears-to-be-empty-or-could-not-be-read","errorCode":null,"errorMessage":"Dataset appears to be empty or could not be read","messagePattern":"Dataset appears to be empty or could not be read","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"studio/backend/hub/services/datasets/local.py","lineNumber":268,"sourceCode":"        if not candidate_files:\n            raise HTTPException(\n                status_code = 400,\n                detail = \"Unsupported local dataset directory (expected parquet/json/jsonl/csv files)\",\n            )\n        dataset_path = candidate_files[0]\n\n    suffix = dataset_path.suffix.lower()\n    # Parquet/Arrow give a cheap exact total_rows; JSON/CSV carry none, so stream and report None.\n    if suffix == \".parquet\":\n        dataset = load_dataset(\"parquet\", data_files = str(dataset_path), split = train_split)\n        total_rows = len(dataset)\n        preview_slice = dataset.select(range(min(preview_size, total_rows)))\n        return preview_slice, total_rows\n\n    if suffix in (\".json\", \".jsonl\", \".csv\"):\n        preview = _stream_file_preview_slice(dataset_path, preview_size)\n        if preview is None:\n            raise HTTPException(\n                status_code = 400,\n                detail = \"Dataset appears to be empty or could not be read\",\n            )\n        return preview\n\n    raise HTTPException(status_code = 400, detail = f\"Unsupported file format: {dataset_path.suffix}\")\n\n\ndef _sanitize_filename(filename: str) -> str:\n    name = Path(filename).name.strip().replace(\"\\x00\", \"\")\n    if not name:\n        return \"dataset_upload\"\n    return name\n\n\ndef _upload_too_large(limit_label: str) -> HTTPException:\n    return HTTPException(\n        status_code = 413,","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/hub/services/datasets/local.py#L250-L286","documentation":"HTTP 400 from `_load_local_preview_slice` when a .json/.jsonl/.csv file's streaming previewer (`_stream_file_preview_slice`) returned None — it opened the file but could not extract a single valid record within the preview size. Distinct from 809 (no candidate file) and 811 (unknown suffix): here the extension was accepted but content was unreadable or empty.","triggerScenarios":"Zero-byte or whitespace-only json/csv file; JSON not in a layout `datasets` can stream (e.g. arbitrary JSON object, not records/lines); CSV with only a header; BOM/encoding corruption; NDJSON with malformed first lines.","commonSituations":"Truncated uploads; exports that write a JSON dict instead of an array/lines; CSVs with header-only; wrong-encoding exports from Excel.","solutions":["Open the file and confirm it actually contains records — not just a header or `{...}` metadata object.","For JSON, convert to JSON Lines (one object per line) or a top-level array, which the streamer can read.","Re-export from the source tool (UTF-8, no BOM) or re-upload — truncated transfers are a common cause.","If the file is fine, convert to parquet, which takes the exact-count path instead of the streaming previewer."],"exampleFix":"# before: meta.json = {\"columns\": [...], \"rows\": []}\n# after: rows.jsonl = one {\"col\": value} object per line","handlingStrategy":"validation","validationCode":"def file_has_records(path: Path, sample: bytes = 4096) -> bool:\n    if path.stat().st_size == 0:\n        return False\n    head = path.open(\"rb\").read(sample).strip()\n    return len(head) > 0 and not head.startswith(b\"{}\")  # bare metadata object will not stream","typeGuard":null,"tryCatchPattern":"try:\n    slice_, total = load_local_preview_slice(path, ...)\nexcept HTTPException as e:\n    if e.status_code == 400 and \"could not be read\" in e.detail:\n        convert_to_parquet_then_retry(path)\n    else:\n        raise","preventionTips":["Prefer parquet for local datasets — it takes the exact-count path and skips the fragile streamer.","Ship JSON as JSON Lines (one object per line), not a single nested object.","Reject zero-byte and header-only files at upload time."],"tags":["local-dataset","json","csv","http-400","empty-file"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}