{"record":{"id":"5238878705a8feef","repo":"unslothai/unsloth","slug":"model-self-active-model-name-has-no-chat-templ","errorCode":null,"errorMessage":"Model '{self.active_model_name}' has no chat_template set in its tokenizer_config.json. This is usually a problem with the model's HuggingFace repository — it is missing a 'chat_template' key. Please use a model that includes a chat template, or manually set one via tokenizer.chat_template before inference.","messagePattern":"Model '(.+?)' has no chat_template set in its tokenizer_config\\.json\\. This is usually a problem with the model's HuggingFace repository — it is missing a 'chat_template' key\\. Please use a model that includes a chat template, or manually set one via tokenizer\\.chat_template before inference\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/inference.py","lineNumber":1204,"sourceCode":"                    model_info[\"chat_turn_end_eos_ids\"] = sorted(set(existing) | set(refreshed))\n                except Exception as e:\n                    logger.warning(f\"Could not refresh chat turn-end eos after template: {e}\")\n            else:\n                logger.info(\n                    f\"No registered Unsloth template for {self.active_model_name}, using tokenizer default\"\n                )\n        except Exception as e:\n            logger.warning(f\"Could not apply get_chat_template: {e}\")\n\n        # Step 2: format with tokenizer.apply_chat_template().\n        if system_prompt:\n            template_messages = [{\"role\": \"system\", \"content\": system_prompt}] + messages\n        else:\n            template_messages = messages\n        reasoning_channel_markers_resolved = False\n        try:\n            if not (hasattr(tokenizer, \"chat_template\") and tokenizer.chat_template):\n                raise ValueError(\n                    f\"Model '{self.active_model_name}' has no chat_template set in its \"\n                    f\"tokenizer_config.json. This is usually a problem with the model's \"\n                    f\"HuggingFace repository — it is missing a 'chat_template' key. \"\n                    f\"Please use a model that includes a chat template, or manually set \"\n                    f\"one via tokenizer.chat_template before inference.\"\n                )\n            reasoning_channel_markers = None\n            formatted_prompt = self._apply_chat_template_for_generation(\n                tokenizer,\n                template_messages,\n                tools = tools,\n                enable_thinking = enable_thinking,\n                reasoning_effort = reasoning_effort,\n                preserve_thinking = preserve_thinking,\n                continue_final_message = continue_final_message,\n            )\n\n            # If tools were requested but the (possibly overridden) template ignored","sourceCodeStart":1186,"sourceCodeEnd":1222,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/inference.py#L1186-L1222","documentation":"Before formatting the chat prompt, the engine verifies tokenizer.chat_template is present; if missing it raises ValueError explaining the model's HuggingFace repo lacks a 'chat_template' key in tokenizer_config.json, and instructs to use a model with a template or set tokenizer.chat_template manually. A preceding step may have tried get_chat_template and failed (logged as a warning), making this the final refusal.","triggerScenarios":"Loading a base model (often shipped without chat templates, e.g. base Llama/Qwen checkpoints) or a repo with a stripped tokenizer_config.json, then issuing a chat-format generation.","commonSituations":"User loads 'model-base' instead of 'model-instruct'; repo author removed the template; an older transformers version fails to read a template stored in a newer format (chat_template.jinja); custom fine-tunes uploaded without tokenizer config updates.","solutions":["Switch to an instruct/chat-tuned variant of the model","Set a template manually: tokenizer.chat_template = \"<known jinja template>\" (or via the engine's custom-template hook if the earlier get_chat_template step provides one)","Upgrade transformers so chat_template.jinja sidecar files are read","Re-upload/fix the model repo's tokenizer_config.json to include the chat_template"],"exampleFix":"# before\nload_model(\"meta-llama/Llama-3.1-8B\")  # base, no template\n# after\nload_model(\"meta-llama/Llama-3.1-8B-Instruct\")\n# or\ntokenizer.chat_template = CHATML_TEMPLATE","handlingStrategy":"type-guard","validationCode":"# After load, before first chat\ntok = model_info[\"tokenizer\"]\ntok = getattr(tok, \"tokenizer\", tok)\nif not (hasattr(tok, \"chat_template\") and tok.chat_template):\n    tok.chat_template = FALLBACK_TEMPLATE  # or refuse early with a clear 409","typeGuard":"def has_chat_template(tokenizer) -> bool:\n    return bool(getattr(tokenizer, \"chat_template\", None))","tryCatchPattern":"try:\n    formatted = tokenizer.apply_chat_template(msgs, ...)\nexcept ValueError as e:\n    if \"no chat_template\" in str(e):\n        surface(\"use an instruct model or set tokenizer.chat_template\", 409)\n    raise","preventionTips":["Prefer -Instruct/-It variants for chat workloads","Verify chat_template right after model load, not at generation time","Keep a known-good jinja template handy for base models you must support"],"tags":["chat-template","tokenizer","huggingface","model-config"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}