unslothai/unsloth · error · HTTPException

Dataset appears to be empty or could not be streamed

Error message

Dataset appears to be empty or could not be streamed

What it means

HTTP 400 raised when streaming preview succeeded in calling `load_dataset(streaming=True)` but `islice(streamed_ds, PREVIEW_SIZE)` yielded zero rows. The loader connected and opened the dataset, yet the first page of records was empty — so the dataset is effectively empty from the API's perspective or the stream could not produce rows.

Source

Thrown at studio/backend/hub/services/datasets/formatting.py:440

            if preview_slice is None:
                # Tier 2: full streaming (resolves all files — slow for large repos)
                logger.info("Tier 2: falling back to full streaming load_dataset")
                try:
                    load_kwargs = {
                        "path": request.dataset_name,
                        "split": request.train_split or "train",
                        "streaming": True,
                    }
                    if request.subset:
                        load_kwargs["name"] = request.subset
                    if hf_token:
                        load_kwargs["token"] = hf_token

                    streamed_ds = load_dataset(**load_kwargs)

                    rows = list(islice(streamed_ds, PREVIEW_SIZE))
                    if not rows:
                        raise HTTPException(
                            status_code = 400,
                            detail = "Dataset appears to be empty or could not be streamed",
                        )

                    preview_slice = Dataset.from_list(rows)
                    total_rows = None
                except Exception:
                    cached_preview = _load_any_cached_hf_preview_slice(
                        request,
                        PREVIEW_SIZE,
                        hf_token,
                    )
                    if cached_preview is None:
                        raise
                    preview_slice, total_rows = cached_preview

        result = check_dataset_format(preview_slice, is_vlm = request.is_vlm)

View on GitHub (pinned to 203007d190)

Solutions

  1. Verify on huggingface.co that the dataset's chosen config/split actually contains rows.
  2. Retry the preview — transient empty first pages from the hub CDN do occur.
  3. Try a different subset or train_split value that matches the dataset's README config.
  4. If it persists, download the dataset fully and preview from local cache instead of streaming.

Example fix

# before
req.train_split = "validation"  # split with 0 rows
# after
req.train_split = "train"      # non-empty split
Defensive patterns

Strategy: fallback

Validate before calling

files = list_repo_files(client, repo_id)  # hub API
data_files = [f for f in files if f.endswith((".parquet", ".json", ".jsonl", ".csv"))]
if not data_files:
    show_empty_dataset_warning()  # streaming preview will 400; skip the call

Try / catch

try:
    preview = get_preview(client, req)
except HTTPStatusError as e:
    if e.response.status_code == 400 and "empty" in e.response.text:
        preview = try_full_download_preview(client, req)  # fall back to non-streaming load
    else:
        raise

Prevention

When it happens

Trigger: Previewing a genuinely empty hub dataset; a dataset whose train split has 0 rows; streaming over a flaky connection that returns an empty first page; a gated/revision mismatch where the resolved revision contains no data files.

Common situations: Newly created hub repos with metadata but no data pushed yet; wrong config/subset selected so the chosen split is empty; CDN serving an empty first shard.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/9ffa3ba4f7147e67. Report an issue: GitHub.