unslothai/unsloth · error · HTTPException

Invalid repo_id format

Error message

Invalid repo_id format

What it means

HTTPException 400 raised by delete_cached_dataset_response when the repo_id argument fails _is_valid_repo_id — the basic HF id format check (namespace/name with allowed characters). The delete is rejected before any cache lookup or destructive action.

Source

Thrown at studio/backend/hub/services/datasets/cache_inventory.py:540

    return sorted(seen_lower.values(), key = lambda c: c["repo_id"])


async def list_cached_datasets_response() -> dict:
    """List dataset repos already downloaded into the HF cache."""
    try:
        return {"cached": await asyncio.to_thread(_scan_hf_dataset_caches)}
    except Exception as exc:
        logger.error("Error listing cached datasets: %s", exc, exc_info = True)
        raise HTTPException(
            status_code = 500,
            detail = "Failed to read the local dataset cache.",
        ) from exc


async def delete_cached_dataset_response(repo_id: str, cache_path: Optional[str] = None) -> dict:
    """Remove a cached dataset repo from the HF cache."""
    if not _is_valid_repo_id(repo_id):
        raise HTTPException(status_code = 400, detail = "Invalid repo_id format")

    repo_key = await asyncio.to_thread(resolve_cached_repo_id_case, repo_id, repo_type = "dataset")
    if not downloads.registry.begin_delete(repo_key):
        raise HTTPException(
            status_code = 400,
            detail = "Cancel the active download before deleting.",
        )
    try:
        return await asyncio.to_thread(_delete_cached_dataset_blocking, repo_key, cache_path)
    finally:
        downloads.registry.end_delete(repo_key)
        hf_cache_scan.invalidate_hf_cache_scans()


def _delete_cached_dataset_blocking(repo_id: str, cache_path: Optional[str] = None) -> dict:
    scans, _seen_roots = _collect_hf_cache_scans()
    app_entry = app_processed_dataset_cache_from_path(repo_id, cache_path) if cache_path else None

View on GitHub (pinned to 203007d190)

Solutions

  1. Send a properly formatted repo id like 'username/dataset-name' (or a bare name for no-namespace repos).
  2. Trim whitespace and strip any leading '#' or URL prefix before calling the API.
  3. Validate with the same pattern client-side: ^[\w.-]+(/[\w.-]+)?$ style check.

Example fix

# before
requests.delete(api + "/datasets/%20user%2Fmodel%2F")  # 400 Invalid repo_id format

# after
repo_id = "user/model".strip().strip("/")
requests.delete(api + f"/datasets/{repo_id}")
Defensive patterns

Strategy: validation

Validate before calling

import re

_REPO_ID_RE = re.compile(r"^[\w.-]+(?:/[\w.-]+)?$")

def normalize_repo_id(raw: str) -> str:
    rid = raw.strip().strip("/")
    rid = rid.replace("https://huggingface.co/", "").replace("http://huggingface.co/", "")
    if not _REPO_ID_RE.fullmatch(rid):
        raise ValueError(f"Invalid repo_id format: {raw!r}")
    return rid

Type guard

def is_valid_repo_id(repo_id: str) -> bool:
    import re
    return bool(re.fullmatch(r"[\w.-]+(?:/[\w.-]+)?", repo_id.strip()))

Try / catch

import httpx

resp = httpx.delete(f"{api}/hub/datasets/{repo_id}")
if resp.status_code == 400 and "Invalid repo_id format" in resp.text:
    repo_id = normalize_repo_id(repo_id)
    resp = httpx.delete(f"{api}/hub/datasets/{repo_id}")

Prevention

When it happens

Trigger: Calling the cached-dataset delete endpoint with a repo_id that is not a well-formed HF id: empty string, leading/trailing slashes, double slashes, invalid characters, or an overlong namespace/name segment.

Common situations: Frontend forwarding an untrimmed input; URL-decoding artifacts injecting %2F or spaces; users pasting full HF URLs instead of the id.

Related errors


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