unslothai/unsloth · error · ValueError

hf_dataset is too long (max 256 chars)

Error message

hf_dataset is too long (max 256 chars)

What it means

Raised by the _check_hf_dataset field validator on TrainingStartRequest. The hf_dataset field (a Hugging Face dataset id like ' username/dataset') is capped at 256 characters after trimming. Long ids are virtually always malformed (pasted URLs, embedded tokens, concatenated ids), so the validator rejects them outright rather than passing them to the Hub API where they would 404 or hang. Empty-after-trim values are normalized to None instead.

Source

Thrown at studio/backend/models/training.py:233

            self.dataset_slice_start is not None
            and self.dataset_slice_end is not None
            and self.dataset_slice_end < self.dataset_slice_start
        ):
            raise ValueError(
                "dataset_slice_end must be greater than or equal to dataset_slice_start"
            )
        return self

    @field_validator("hf_dataset")
    @classmethod
    def _check_hf_dataset(cls, v: Optional[str]) -> Optional[str]:
        if v is None:
            return v
        v = v.strip()
        if not v:
            return None
        if len(v) > 256:
            raise ValueError("hf_dataset is too long (max 256 chars)")
        if ".." in v:
            raise ValueError("hf_dataset must not contain '..'")
        if any(_HF_DATASET_ID_SEGMENT_RE.fullmatch(segment) is None for segment in v.split("/")):
            raise ValueError("hf_dataset contains invalid characters or path segments")
        return v

    @field_validator("subset")
    @classmethod
    def _check_subset(cls, v: Optional[str]) -> Optional[str]:
        if v is None:
            return v
        v = v.strip()
        if not v:
            return None
        if len(v) > MAX_HF_DATASET_OPTION_LENGTH:
            raise ValueError(f"subset is too long (max {MAX_HF_DATASET_OPTION_LENGTH} chars)")
        if not valid_hf_dataset_config_name(v):
            raise ValueError("subset contains invalid characters")

View on GitHub (pinned to 203007d190)

Solutions

  1. Use the bare dataset id (owner/name), max 256 chars, e.g. 'fka/awesome-chat-api'.
  2. If you have a URL, extract the path segments after /datasets/ and drop query params.
  3. Put config/subset/split in their own fields, not appended to hf_dataset.

Example fix

// before
{ hf_dataset: "https://huggingface.co/datasets/user/data?token=verylong..." }
// after
{ hf_dataset: "user/data", subset: "default" }
Defensive patterns

Strategy: validation

Validate before calling

def dataset_id_short_enough(body: dict) -> bool:
    v = (body.get("hf_dataset") or "").strip()
    return len(v) <= 256

Type guard

function datasetIdOk(id: string): boolean {
  return id.trim().length <= 256;
}

Prevention

When it happens

Trigger: POST a training start request with an hf_dataset value longer than 256 chars after strip() — e.g. a pasted HTTPS URL with query params, or a dataset id accidentally concatenated with a token or path.

Common situations: Users pasting the full HF URL (https://huggingface.co/datasets/...) plus auth query strings; copy-paste that includes trailing text; programmatic construction that appends config/subset into the dataset id instead of the dedicated fields.

Related errors


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