unslothai/unsloth · warning · ValueError

save_directory must not be empty

Error message

save_directory must not be empty

What it means

ValueError from _validate_save_directory when the value is present but strips to an empty string (None was already handled by the preceding check). The validator strips whitespace before testing, so a value of only spaces fails here too.

Source

Thrown at studio/backend/models/export.py:18

# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

"""Pydantic schemas for Export API."""

from pathlib import Path, PureWindowsPath

from pydantic import BaseModel, Field, field_validator
from typing import List, Optional, Literal, Dict, Any, Union


def _validate_save_directory(value: str) -> str:
    """Validate save_directory — allows absolute paths (user may want a different drive)."""
    if value is None:
        raise ValueError("save_directory is required")
    raw = str(value).strip()
    if not raw:
        raise ValueError("save_directory must not be empty")
    if "\x00" in raw:
        raise ValueError("save_directory may not contain null bytes")
    if any(ch in raw for ch in ("\r", "\n")):
        raise ValueError("save_directory may not contain control characters")
    path = Path(raw).expanduser()
    path_parts = (*path.parts, *PureWindowsPath(raw).parts, *raw.replace("\\", "/").split("/"))
    if any(len(part) > 255 for part in path_parts if part not in ("", ".", "/", "\\")):
        raise ValueError("save_directory path components must be <= 255 characters")
    if (
        ".." in path.parts
        or ".." in PureWindowsPath(raw).parts
        or ".." in raw.replace("\\", "/").split("/")
    ):
        raise ValueError("save_directory may not contain '..' segments")
    return raw


class LoadCheckpointRequest(BaseModel):

View on GitHub (pinned to 203007d190)

Solutions

  1. Populate save_directory with a real destination path before submitting.
  2. Add client-side validation requiring a non-blank value.
  3. Check template/env interpolation if the value is generated.

Example fix

// before
{ "save_directory": "" }
// after
{ "save_directory": "/exports/model" }
Defensive patterns

Strategy: validation

Validate before calling

def save_directory_nonempty(payload: dict) -> bool:
    v = payload.get("save_directory")
    return isinstance(v, str) and v.strip() != ""

Type guard

def is_nonblank_save_directory(v) -> bool:
    return isinstance(v, str) and v.strip() != ""

Prevention

When it happens

Trigger: Sending save_directory as "" or " " — e.g. an empty form field serialized verbatim, or a templated value like "${EXPORT_DIR}" that resolved to empty.

Common situations: UI text input left blank and submitted without client-side required validation; env-var interpolation producing an empty string in generated payloads.

Related errors


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