unslothai/unsloth · error · ValueError

Streaming chat-format standardization failed on the first ro

Error message

Streaming chat-format standardization failed on the first row: {exc}

What it means

ValueError raised eagerly for streaming datasets after dataset.map(_standardize_dataset): the first mapped row is forced through (next(iter(result))) so per-row schema/type errors surface now, at setup time, instead of mid-training when iteration first hits them. The original exception is chained (from exc), so the real cause — usually a missing chat column or malformed turn in row 0 — is in exc, and IterableDataset re-iterates from the source generator making this probe safe/non-destructive.

Source

Thrown at studio/backend/utils/datasets/format_conversion.py:186

        if num_proc is None or type(num_proc) is not int:
            num_proc = dataset_map_num_proc()
        else:
            num_proc = dataset_map_num_proc(num_proc)

        dataset_map_kwargs["num_proc"] = num_proc
        dataset_map_kwargs["desc"] = "Standardizing chat format"

    result = dataset.map(_standardize_dataset, **dataset_map_kwargs)

    # For streaming, force the first mapped row through now so any
    # column/format errors surface before training begins (not mid-iteration).
    # IterableDataset re-iterates from the generator source, so this is safe.
    if is_streaming_dataset(dataset):
        try:
            next(iter(result))
        except Exception as exc:
            raise ValueError(
                f"Streaming chat-format standardization failed on the first row: {exc}"
            ) from exc

    return result


def convert_chatml_to_alpaca(
    dataset,
    batch_size = 1000,
    num_proc = None,
    chat_column: str | None = None,
):
    """
    Convert ChatML (messages OR conversations) to Alpaca format.

    Supports:
    - "messages" or "conversations" column
    - "role"/"content" (standard) or "from"/"value" (ShareGPT)

View on GitHub (pinned to 203007d190)

Solutions

  1. Read the chained exception (raise ... from exc) — fix the underlying per-row error it names, not this wrapper
  2. Materialize and inspect the first row before standardizing: row = next(iter(dataset)); print(row[chat_column])
  3. Verify chat_column actually exists in the streaming schema (dataset.features) and matches the turn structure

Example fix

# before
result = standardize_chat_format(stream_ds, tok, ..., chat_column='messages')
# raises 'failed on the first row: KeyError ...' because column is 'conversation'

# after
print(next(iter(stream_ds)).keys())  # -> 'conversation'
result = standardize_chat_format(stream_ds, tok, ..., chat_column='conversation')
Defensive patterns

Strategy: try-catch

Validate before calling

def first_row_scan_ready(stream_ds, chat_column: str) -> bool:
    row = next(iter(stream_ds), None)
    if row is None or chat_column not in row:
        return False
    turns = row[chat_column] or []
    return bool(turns) and isinstance(turns[0], dict)

Try / catch

try:
    result = standardize_chat_format(stream_ds, tok, ..., chat_column=col)
except ValueError as e:
    if "failed on the first row" in str(e) and e.__cause__ is not None:
        diagnose_from(e.__cause__)  # the real per-row error
        raise
    raise

Prevention

When it happens

Trigger: Calling standardize_chat_format on a streaming dataset where the source rows lack chat_column, contain turns that are not dicts, or where _standardize_dataset raises KeyError/TypeError on the very first row.

Common situations: Streaming remote datasets whose first shard has a different schema; conversation fields nested under a different name than chat_column; server-side data changes after the stream handle was created.

Related errors


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