Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: say why AI Assist cannot map a dataset with no prompt/response split (#15991)

Daniel Han242812eaf579
diff --git a/studio/backend/hub/services/datasets/formatting.py b/studio/backend/hub/services/datasets/formatting.py
index febffeaf9cf..733c7a9dffe 100644
--- a/studio/backend/hub/services/datasets/formatting.py
+++ b/studio/backend/hub/services/datasets/formatting.py
@@ -720,7 +720,7 @@ def check_format_response(
def ai_assist_mapping_response(
request: AiAssistMappingRequest, hf_token: Optional[str] = None
) -> AiAssistMappingResponse:
- """User-triggered 7B-model advisor; on failure it falls back to simple column classification."""
+ """User-triggered helper-model advisor; on failure it falls back to simple column classification."""
hf_token = account_hf_token(hf_token)
account_path(request.dataset_name, reference = True)
visible_cached_path(getattr(request, "local_path", None), "dataset")
@@ -756,7 +756,8 @@ def ai_assist_mapping_response(
return AiAssistMappingResponse(
success = False,
- warning = "AI could not determine column roles. Please assign them manually.",
+ warning = (result or {}).get("warning")
+ or "AI could not determine column roles. Please assign them manually.",
)
except Exception as e:
diff --git a/studio/backend/hub/utils/llm_assist.py b/studio/backend/hub/utils/llm_assist.py
index a44157bf46f..6e3d86030f3 100644
--- a/studio/backend/hub/utils/llm_assist.py
+++ b/studio/backend/hub/utils/llm_assist.py
@@ -19,6 +19,10 @@ logger = get_logger(__name__)
DEFAULT_HELPER_MODEL_REPO = "unsloth/gemma-4-E2B-it-GGUF"
DEFAULT_HELPER_MODEL_VARIANT = "UD-Q4_K_XL"
README_MAX_CHARS = 1500
+NO_ROLE_SPLIT_WARNING = (
+ "This dataset has no separate prompt and response columns to map. If it is plain "
+ "text, set Advanced > Target Format to Raw Text."
+)
def _helper_disabled() -> bool:
@@ -224,6 +228,7 @@ def _run_multi_pass_advisor(
)
pass1 = _parse_json_response(pass1_raw)
if not pass1:
+ logger.warning("Hub advisor pass 1 returned no JSON: %.300s", pass1_raw)
return None
if pass1.get("is_conversational") and not pass1.get("needs_conversion"):
@@ -270,20 +275,32 @@ def _run_multi_pass_advisor(
512,
)
pass2 = _parse_json_response(pass2_raw)
- if not pass2:
- return None
- column_roles = pass2.get("column_roles")
- if not isinstance(column_roles, dict):
- return None
- roles_present = set(column_roles.values())
- if "user" not in roles_present or "assistant" not in roles_present:
+ column_roles = pass2.get("column_roles") if pass2 else None
+ suggested_mapping = (
+ {
+ col: role
+ for col, role in column_roles.items()
+ if col in columns and role in {"user", "assistant", "system"}
+ }
+ if isinstance(column_roles, dict)
+ else {}
+ )
+ if (
+ "user" not in suggested_mapping.values()
+ or "assistant" not in suggested_mapping.values()
+ ):
+ logger.warning(
+ "Hub advisor gave no user/assistant split: roles=%s notes=%.300s",
+ column_roles,
+ pass2.get("notes") if pass2 else pass2_raw,
+ )
return None
label_mapping = pass2.get("label_mapping") or None
system_prompt = ""
if not pass1.get("is_conversational"):
- user_cols = [col for col, role in column_roles.items() if role == "user"]
- assistant_cols = [col for col, role in column_roles.items() if role == "assistant"]
+ user_cols = [col for col, role in suggested_mapping.items() if role == "user"]
+ assistant_cols = [col for col, role in suggested_mapping.items() if role == "assistant"]
prompt_raw = _generate_with_backend(
backend,
[
@@ -306,17 +323,6 @@ def _run_multi_pass_advisor(
if 20 <= len(cleaned) <= 800 and cleaned.lower() not in {"null", "none"}:
system_prompt = cleaned
- suggested_mapping = {
- col: role
- for col, role in column_roles.items()
- if col in columns and role in {"user", "assistant", "system"}
- }
- if (
- "user" not in suggested_mapping.values()
- or "assistant" not in suggested_mapping.values()
- ):
- return None
-
dtype = str(pass1.get("dataset_type") or "other")
notification_parts = [f"This is a {dtype} dataset."]
description = pass1.get("task_description") or pass1.get("description")
@@ -374,23 +380,26 @@ def _heuristic_mapping(columns: list[str]) -> Optional[dict[str, str]]:
"problem",
"text",
)
+ # Metadata columns (id, url, ...) never fill a missing role.
+ content_cols = [
+ col
+ for col, name in lowered.items()
+ if not any(term == name or name.endswith(f"_{term}") for term in metadata_terms)
+ ]
mapping: dict[str, str] = {}
- for col, name in lowered.items():
- if any(term == name or name.endswith(f"_{term}") for term in metadata_terms):
- continue
+ for col in content_cols:
+ name = lowered[col]
if any(term in name for term in assistant_terms):
mapping[col] = "assistant"
elif any(term in name for term in user_terms):
mapping[col] = "user"
if "assistant" not in mapping.values():
- candidates = [col for col in columns if col not in mapping]
+ candidates = [col for col in content_cols if col not in mapping] or content_cols
if candidates:
mapping[candidates[-1]] = "assistant"
- elif columns:
- mapping[columns[-1]] = "assistant"
if "user" not in mapping.values():
- for col in columns:
+ for col in content_cols:
if mapping.get(col) != "assistant":
mapping[col] = "user"
break
@@ -407,6 +416,9 @@ def llm_conversion_advisor(
model_name: Optional[str] = None,
model_type: Optional[str] = None,
) -> Optional[dict[str, Any]]:
+ if len(column_names) < 2:
+ return {"success": False, "warning": NO_ROLE_SPLIT_WARNING}
+
dataset_card = None
dataset_metadata = None
if dataset_name and "/" in dataset_name:
@@ -432,8 +444,8 @@ def llm_conversion_advisor(
"dataset_type": None,
"is_conversational": None,
"warning": (
- "The helper model was unavailable, so Hub used column-name heuristics. "
+ "The helper model gave no usable mapping, so Hub used column-name heuristics. "
"Review the suggested mapping before training."
),
}
- return None
+ return {"success": False, "warning": NO_ROLE_SPLIT_WARNING}
diff --git a/studio/backend/tests/test_hub_ai_assist_no_role_split.py b/studio/backend/tests/test_hub_ai_assist_no_role_split.py
new file mode 100644
index 00000000000..d1e9b18d976
--- /dev/null
+++ b/studio/backend/tests/test_hub_ai_assist_no_role_split.py
@@ -0,0 +1,169 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""AI Assist on datasets with no prompt/response split (#15901)."""
+
+from __future__ import annotations
+
+import json
+import sys
+import types
+from pathlib import Path
+
+import pytest
+
+_BACKEND_DIR = str(Path(__file__).resolve().parent.parent)
+if _BACKEND_DIR not in sys.path:
+ sys.path.insert(0, _BACKEND_DIR)
+
+from hub.schemas.datasets import AiAssistMappingRequest
+from hub.services.datasets import formatting as dataset_formatting
+from hub.utils import llm_assist
+
+PASS1 = json.dumps(
+ {
+ "dataset_type": "other",
+ "is_conversational": False,
+ "needs_conversion": True,
+ "description": "Prose passages.",
+ "task_description": "Continued pretraining.",
+ }
+)
+SYSTEM_PROMPT = "You answer questions about sloths accurately."
+
+
+class _FakeBackend:
+ replies: list[str] = []
+ calls = 0
+ loads = 0
+
+ def load_model(self, intent):
+ type(self).loads += 1
+ return True
+
+ def unload_model(self):
+ pass
+
+ def generate_chat_completion(self, **kwargs):
+ type(self).calls += 1
+ yield type(self).replies.pop(0)
+
+
+def backend(monkeypatch):
+ module = types.ModuleType("core.inference.llama_cpp")
+ module.LlamaCppBackend = _FakeBackend
+ module.GgufLoadIntent = lambda **kwargs: kwargs
+ monkeypatch.setitem(sys.modules, "core.inference.llama_cpp", module)
+ monkeypatch.delenv("UNSLOTH_HELPER_MODEL_DISABLE", raising = False)
+ _FakeBackend.replies, _FakeBackend.calls, _FakeBackend.loads = [], 0, 0
+ return _FakeBackend
+
+
+def warnings(monkeypatch):
+ seen: list[str] = []
+ monkeypatch.setattr(
+ llm_assist.logger, "warning", lambda msg, *args: seen.append(msg % args), raising = False
+ )
+ return seen
+
+
+def _roles(roles, notes = "plain prose, nothing to answer"):
+ return json.dumps({"column_roles": roles, "label_mapping": None, "notes": notes})
+
+
+def _advise(columns):
+ samples = [{col: "Sloths move slowly through the canopy." for col in columns}]
+ return llm_assist.llm_conversion_advisor(columns, samples, dataset_name = "local.jsonl")
+
+
+def test_single_column_skips_the_helper_model(backend):
+ result = _advise(["content"])
+
+ assert result == {"success": False, "warning": llm_assist.NO_ROLE_SPLIT_WARNING}
+ assert backend.loads == 0
+
+
+ "roles", [{"text": "assistant", "id": "skip"}, {"text": "skip", "id": "skip"}]
+)
+def test_text_plus_metadata_reports_no_split_and_logs_notes(backend, warnings, roles):
+ backend.replies = [PASS1, _roles(roles)]
+
+ result = _advise(["text", "id"])
+
+ assert result == {"success": False, "warning": llm_assist.NO_ROLE_SPLIT_WARNING}
+ assert backend.calls == 2
+ assert any("plain prose, nothing to answer" in line for line in warnings)
+
+
+def test_unparseable_pass2_is_logged(backend, warnings):
+ backend.replies = [PASS1, "I am not sure"]
+
+ assert (
+ llm_assist._run_multi_pass_advisor(
+ columns = ["question", "answer"],
+ samples = [],
+ dataset_name = None,
+ dataset_card = None,
+ dataset_metadata = None,
+ model_name = None,
+ model_type = None,
+ )
+ is None
+ )
+ assert any("I am not sure" in line for line in warnings)
+
+
+def test_valid_split_still_maps(backend):
+ backend.replies = [
+ PASS1,
+ _roles({"question": "user", "answer": "assistant", "ghost": "user"}),
+ SYSTEM_PROMPT,
+ ]
+
+ result = _advise(["question", "answer"])
+
+ assert result["success"] is True
+ assert result["suggested_mapping"] == {"question": "user", "answer": "assistant"}
+ assert result["system_prompt"] == SYSTEM_PROMPT
+
+
+def test_rejected_split_falls_back_to_name_heuristics(backend):
+ backend.replies = [PASS1, _roles({"question": "assistant", "answer": "skip"})]
+
+ result = _advise(["question", "answer"])
+
+ assert result["success"] is True
+ assert result["suggested_mapping"] == {"question": "user", "answer": "assistant"}
+ assert "Review the suggested mapping" in result["warning"]
+
+
+ "columns, expected",
+ [
+ (["text", "id"], None),
+ (["content", "url", "source"], None),
+ (["question_id", "question"], None),
+ (["id", "question", "answer"], {"question": "user", "answer": "assistant"}),
+ (["prompt", "chosen", "rejected"], {"prompt": "user", "rejected": "assistant"}),
+ (["context", "summary"], {"context": "user", "summary": "assistant"}),
+ (["a", "b"], {"a": "user", "b": "assistant"}),
+ ],
+)
+def test_heuristic_never_assigns_metadata_columns(columns, expected):
+ assert llm_assist._heuristic_mapping(columns) == expected
+
+
+def test_service_returns_the_advisor_warning(monkeypatch):
+ fake = types.ModuleType("hub.utils.llm_assist")
+ fake.llm_conversion_advisor = lambda **kwargs: {"success": False, "warning": "specific reason"}
+ monkeypatch.setitem(sys.modules, "hub.utils.llm_assist", fake)
+
+ response = dataset_formatting.ai_assist_mapping_response(
+ AiAssistMappingRequest(columns = ["content"], samples = [{"content": "x"}]),
+ )
+
+ assert response.success is False
+ assert response.warning == "specific reason"