{"record":{"id":"483fa3c326523779","repo":"unslothai/unsloth","slug":"the-template-produced-an-empty-prompt","errorCode":null,"errorMessage":"the template produced an empty prompt","messagePattern":"the template produced an empty prompt","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/mlx_inference.py","lineNumber":1331,"sourceCode":"\n        Must use the same target the real request does. The recovery renderer\n        returns None instead of raising for a model outside mlx-vlm's family\n        list, so probing it would pass a template that cannot render at all.\n        \"\"\"\n        from core.inference.chat_template_helpers import (\n            apply_chat_template_for_generation,\n            chat_render_target,\n        )\n\n        messages = [{\"role\": \"user\", \"content\": \"hi\"}]\n        target = (\n            chat_render_target(self._processor)\n            if is_vision and self._processor is not None\n            else self._tokenizer\n        )\n        rendered = apply_chat_template_for_generation(target, messages)\n        if not rendered or not rendered.strip():\n            raise ValueError(\"the template produced an empty prompt\")\n        return rendered\n\n    def _populate_chat_template_info(\n        self,\n        model_name: str,\n        native_template = _TEMPLATE_NOT_CAPTURED,\n    ) -> None:\n        \"\"\"Mirror InferenceBackend._load_chat_template_info for MLX.\n\n        Stores ``chat_template_info`` on ``self.models[model_name]``. The\n        template recorded is the one the model shipped with, not an override:\n        the capability classification and the editor's notion of \"default\"\n        both read it, so an override installed on the tokenizer must not\n        show up here.\"\"\"\n        entry = self.models.get(model_name)\n        if not entry:\n            return\n        tok = entry.get(\"tokenizer\")","sourceCodeStart":1313,"sourceCodeEnd":1349,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/mlx_inference.py#L1313-L1349","documentation":"Part of the MLX backend's chat-template capability probe: it renders a minimal [{'role':'user','content':'hi'}] conversation through apply_chat_template_for_generation (against the processor for VLMs, the tokenizer otherwise) and requires a non-empty string. An empty/whitespace result means the model's chat template cannot render even a trivial text turn, so template-dependent features (tool calls, reasoning tags) would be garbage — hence ValueError.","triggerScenarios":"Loading a model whose tokenizer/chat_template is missing, empty, raises internally and returns None, or renders to '' for plain text input; e.g. base models shipped without a chat_template, corrupted tokenizer files, or a template that only handles multimodal content while the probe targets the tokenizer.","commonSituations":"Raw pretrained checkpoints with no chat template; partially downloaded/corrupt tokenizer assets; exotic community repos with broken jinja templates.","solutions":["Use an instruct/chat-tuned variant of the model (repo names containing -Instruct / -it) which ships a valid chat_template.","Re-download the repo to rule out corrupt tokenizer files (clear the HF cache entry and reload).","Manually inspect tokenizer_config.json's chat_template field; if empty, supply a compatible template override or pick a different checkpoint."],"exampleFix":"# before\nbackend.load('org/model-base')  # no chat template -> probe renders '' -> ValueError\n\n# after\nbackend.load('org/model-base-instruct')  # ships valid chat_template","handlingStrategy":"validation","validationCode":"probe = apply_chat_template_for_generation(tokenizer, [{'role': 'user', 'content': 'hi'}])\nif not probe or not probe.strip():\n    mark_model_unsupported(model_name, reason='chat template renders empty')","typeGuard":null,"tryCatchPattern":"try:\n    template_probe = backend.probe_chat_template()\nexcept ValueError as e:\n    if 'empty prompt' in str(e):\n        # load a fallback instruct checkpoint or reject the model in the UI\n        raise ModelUnsupportedError(model_name) from e\n    raise","preventionTips":["Run the trivial 'hi' render as part of load-time capability detection and record the result on the model entry.","Prefer -Instruct/-it repos for chat workloads.","Verify repo integrity (HF cache) when probes fail unexpectedly on known-good models."],"tags":["mlx","chat-template","tokenizer","model-loading"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}