unslothai/unsloth · warning · HTTPException
model_path is required
Error message
model_path is required
What it means
Raised by the DELETE /delete-finetuned endpoint in Unsloth Studio (delete_finetuned_model, studio/backend/routes/models.py:2887) when the request body omits model_path or sends only whitespace. model_path is a required Body(...) parameter of type str, so FastAPI would 422 on a missing key; this 400 fires when the key is present but empty or blank. It is a pure client-input validation error, nothing has been touched on disk.
Source
Thrown at studio/backend/routes/models.py:2906
model_path: str = Body(...),
source: str = Body(...),
export_type: Optional[str] = Body(None),
gguf_variant: Optional[str] = Body(None),
current_subject: str = Depends(get_current_subject),
):
"""Delete an Unsloth-trained or exported model from disk.
Only paths under Unsloth's outputs/exports roots are accepted.
Exported GGUF entries can delete one quant variant at a time.
"""
if source not in {"training", "exported"}:
raise HTTPException(
status_code = 400,
detail = "Only trained or exported Unsloth models can be deleted",
)
if not model_path or not model_path.strip():
raise HTTPException(status_code = 400, detail = "model_path is required")
if export_type == "gguf" and not gguf_variant:
raise HTTPException(
status_code = 400,
detail = "gguf_variant is required when export_type is 'gguf'",
)
raw_path = Path(model_path).expanduser()
if source == "training":
target_path = raw_path
allowed_root = outputs_root()
else:
allowed_root = exports_root()
target_path = (
raw_path.parent
if export_type == "gguf" and raw_path.suffix.lower() == ".gguf"
else raw_path
)View on GitHub (pinned to 203007d190)
Solutions
- Send a non-blank model_path in the JSON body, e.g. {"model_path": "/unsloth-outputs/my-run/checkpoint-100", "source": "training"}.
- Confirm the field name is exactly model_path (not path or model_dir) and the Content-Type is application/json on the DELETE request.
- If driving from the UI, re-scan the models list so rows carry a real path, and re-select the row before clicking delete.
- Trim the value client-side and skip the call entirely when it is empty.
Example fix
// before
await fetch('/delete-finetuned', {method: 'DELETE', body: JSON.stringify({source: 'training', model_path: selectedRow?.path ?? ''})});
// after
if (!selectedRow?.path?.trim()) throw new Error('No model selected');
await fetch('/delete-finetuned', {method: 'DELETE', body: JSON.stringify({source: 'training', model_path: selectedRow.path})}); Defensive patterns
Strategy: validation
Validate before calling
function buildDeletePayload(row) {
const model_path = (row?.model_path ?? '').trim();
if (!model_path) throw new Error('model_path is required: select a model row first');
return { model_path, source: row.source };
} Type guard
function isDeletableRow(row) {
return Boolean(row && typeof row.model_path === 'string' && row.model_path.trim() && ['training', 'exported'].includes(row.source));
} Try / catch
try { await api.delete('/delete-finetuned', { data: payload }); } catch (e) { if (e.status === 400 && e.detail === 'model_path is required') { /* reselect row, do not retry blindly */ } else throw e; } Prevention
- Bind the delete button's disabled state to a non-empty trimmed model_path.
- Send exactly the path returned by the models scan API, never a user-typed string.
- Keep one canonical name for the field (model_path) across UI, scripts, and API wrappers.
When it happens
Trigger: Calling DELETE /delete-finetuned with {"source": "training", "model_path": ""} or {"model_path": " "} or a model_path of null coerced to empty string; also sending the path under a wrong body key (e.g. "path") after disabling FastAPI's strict validation, or a UI row that failed to populate its path field.
Common situations: Frontend sends the delete request before the selected row's model_path is bound; the model was recorded in state with an empty path because a scan result was pruned; scripted cleanup clients built from a template that renamed the field.
Related errors
- gguf_variant is required when export_type is 'gguf'
- GGUF variant deletion requires an export directory
- Model path is outside Unsloth storage
- Refusing to delete storage root
- Unload the model before deleting
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/874007592675d001.
Report an issue: GitHub.