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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: let a text Expression column in Data Recipes render empty (#13296)
Daniel Hane7cb12772720
diff --git a/studio/backend/core/data_recipe/service.py b/studio/backend/core/data_recipe/service.pyindex b4ae256ead3..e73fff0bce2 100644--- a/studio/backend/core/data_recipe/service.py+++ b/studio/backend/core/data_recipe/service.py@@ -153,7 +153,7 @@ def _blank_missing_prompt_value(value: Any) -> Any:return value-def _allow_empty_prompt(_rendered_text: str) -> None:+def _allow_empty_prompt(*_args: Any, **_kwargs: Any) -> None:return None@@ -218,6 +218,38 @@ def _apply_data_designer_prompt_blank_patch() -> None:setattr(RecordBasedPromptRenderer, "_unsloth_prompt_blank_patch_applied", True)+def _is_none(value: Any) -> bool:+ return value is None+++def _apply_data_designer_expression_blank_patch() -> None:+ # "" is a real text Expression value (an unanswered optional field); data-designer 0.5 fails the run on it and+ # later releases drop the row. Number / bool dtypes keep that, since "" cannot be cast.+ try:+ from data_designer.engine.column_generators.generators.expression import ( # pyright: ignore[reportMissingImports]+ ExpressionColumnGenerator,+ )+ except ImportError:+ return++ if getattr(ExpressionColumnGenerator, "_unsloth_expression_blank_patch_applied", False):+ return++ original_prepare = ExpressionColumnGenerator.prepare_jinja2_template_renderer++ @functools.wraps(original_prepare)+ def _patched_prepare(self: Any, *args: Any, **kwargs: Any) -> None:+ original_prepare(self, *args, **kwargs)+ env = getattr(getattr(self, "_template_render_fn", None), "func", None)+ env = getattr(env, "__self__", None)+ if env is not None and self.config.dtype == "str":+ env._assert_rendered_text_not_empty = _allow_empty_prompt+ self._is_empty_rendered_expression = _is_none++ ExpressionColumnGenerator.prepare_jinja2_template_renderer = _patched_prepare+ setattr(ExpressionColumnGenerator, "_unsloth_expression_blank_patch_applied", True)++def _require_public_provider_endpoint(endpoint: str) -> None:"""The recipe engine dials providers itself, so a managed account's endpoint cannot use the pinnedtransport: require HTTPS, which binds the peer to its certificate rather than to a DNS answer that@@ -489,6 +521,7 @@ def create_data_designer(recipe: dict[str, Any], *, artifact_path: str | None =account_path(artifact_path)_apply_data_designer_image_context_patch()_apply_data_designer_prompt_blank_patch()+ _apply_data_designer_expression_blank_patch()from data_designer.interface.data_designer import DataDesigner # pyright: ignore[reportMissingImports]if artifact_path is None:diff --git a/studio/backend/tests/test_data_recipe_empty_expression.py b/studio/backend/tests/test_data_recipe_empty_expression.pynew file mode 100644index 00000000000..8dc98bafd43--- /dev/null+++ b/studio/backend/tests/test_data_recipe_empty_expression.py@@ -0,0 +1,156 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import json+import threading+from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer+from pathlib import Path++import pytest++[email protected](name = "provider")+def fixture_provider():+ class Handler(BaseHTTPRequestHandler):+ def do_POST(self):+ body = self.rfile.read(int(self.headers["Content-Length"])).decode()+ if "row 1" in body:+ answer = {"question": "", "answer": "A."}+ else:+ answer = {"question": "Q?", "answer": "B."}+ content = "```json\n" + json.dumps(answer) + "\n```"+ reply = json.dumps(+ {+ "id": "c",+ "object": "chat.completion",+ "created": 0,+ "model": "x",+ "choices": [+ {+ "index": 0,+ "message": {"role": "assistant", "content": content},+ "finish_reason": "stop",+ }+ ],+ "usage": {"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2},+ }+ ).encode()+ self.send_response(200)+ self.send_header("Content-Type", "application/json")+ self.send_header("Content-Length", str(len(reply)))+ self.end_headers()+ self.wfile.write(reply)++ def log_message(self, *args):+ pass++ server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)+ threading.Thread(target = server.serve_forever, daemon = True).start()+ yield f"http://127.0.0.1:{server.server_address[1]}/v1"+ server.shutdown()+++def _preview(+ tmp_path: Path,+ recipe: dict,+ num_records: int = 2,+):+ from core.data_recipe.service import build_config_builder, create_data_designer+ designer = create_data_designer(recipe, artifact_path = str(tmp_path / "artifacts"))+ return designer.preview(build_config_builder(recipe), num_records = num_records).dataset+++def test_flattening_an_empty_structured_field_keeps_the_run(tmp_path: Path, provider) -> None:+ # unslothai/unsloth#4675: {{ response.question }} on an empty optional field failed the whole preview.+ pytest.importorskip("data_designer")+ seed = tmp_path / "seed.csv"+ seed.write_text("n\n1\n2\n", encoding = "utf-8")+ schema = {+ "type": "object",+ "additionalProperties": False,+ "required": [],+ "properties": {"question": {"type": "string"}, "answer": {"type": "string"}},+ }+ recipe = {+ "model_providers": [{"name": "p", "endpoint": provider, "provider_type": "openai"}],+ "model_configs": [+ {+ "alias": "m",+ "model": "x",+ "provider": "p",+ "inference_parameters": {"max_parallel_requests": 1},+ }+ ],+ "seed_config": {+ "source": {"seed_type": "local", "path": str(seed)},+ "sampling_strategy": "ordered",+ },+ "columns": [+ {+ "column_type": "llm-structured",+ "name": "response",+ "model_alias": "m",+ "prompt": "Write a QA pair for row {{ n }}",+ "output_format": schema,+ },+ {"column_type": "expression", "name": "question", "expr": "{{ response.question }}"},+ {+ "column_type": "expression",+ "name": "guarded",+ "expr": "{% if response.question %}{{ response.question }}{% endif %}",+ },+ {"column_type": "expression", "name": "answer", "expr": "{{ response.answer }}"},+ ],+ }++ dataset = _preview(tmp_path, recipe)++ assert sorted(dataset["question"]) == ["", "Q?"]+ assert sorted(dataset["guarded"]) == ["", "Q?"]+ assert sorted(dataset["answer"]) == ["A.", "B."]+++ "expr",+ ["{{ response.question }}", "{{ response.missing }}", "{% if response.question %}x{% endif %}"],+)+def test_text_expression_may_render_empty(tmp_path: Path, expr: str) -> None:+ pytest.importorskip("data_designer")+ seed = tmp_path / "seed.jsonl"+ seed.write_text(+ json.dumps({"response": {"question": ""}})+ + "\n"+ + json.dumps({"response": {"question": "Q?"}})+ + "\n",+ encoding = "utf-8",+ )+ recipe = {+ "seed_config": {+ "source": {"seed_type": "local", "path": str(seed)},+ "sampling_strategy": "ordered",+ },+ "columns": [{"column_type": "expression", "name": "out", "expr": expr}],+ }++ dataset = _preview(tmp_path, recipe)++ assert "" in list(dataset["out"])+++def test_number_expression_still_rejects_empty(tmp_path: Path) -> None:+ pytest.importorskip("data_designer")+ seed = tmp_path / "seed.jsonl"+ seed.write_text(json.dumps({"v": ""}) + "\n", encoding = "utf-8")+ recipe = {+ "seed_config": {+ "source": {"seed_type": "local", "path": str(seed)},+ "sampling_strategy": "ordered",+ },+ "columns": [+ {"column_type": "expression", "name": "out", "expr": "{{ v }}", "dtype": "int"}+ ],+ }++ # data-designer 0.5 fails the template; later releases drop the row, leaving none.+ with pytest.raises(Exception, match = "template is invalid|no valid rows"):+ _preview(tmp_path, recipe, num_records = 1)