{"record":{"id":"78bd7654183c5213","repo":"BerriAI/litellm","slug":"model-name-not-set-for-llamaguard","errorCode":null,"errorMessage":"model_name not set for LlamaGuard","messagePattern":"model_name not set for LlamaGuard","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"enterprise/litellm_enterprise/enterprise_callbacks/llama_guard.py","lineNumber":34,"sourceCode":")  # Adds the parent directory to the system path\nimport sys\nfrom typing import Literal, Optional\n\nfrom fastapi import HTTPException\n\nimport litellm\nfrom litellm._logging import verbose_proxy_logger\nfrom litellm.integrations.custom_logger import CustomLogger\nfrom litellm.proxy._types import UserAPIKeyAuth\nfrom litellm.types.utils import CallTypesLiteral, Choices, ModelResponse\n\n\nclass _ENTERPRISE_LlamaGuard(CustomLogger):\n    # Class variables or attributes\n    def __init__(self, model_name: Optional[str] = None):\n        _model = model_name or litellm.llamaguard_model_name\n        if _model is None:\n            raise ValueError(\"model_name not set for LlamaGuard\")\n        self.model = _model\n        file_path = litellm.llamaguard_unsafe_content_categories\n        data = None\n\n        if file_path is not None:\n            try:\n                with open(file_path, \"r\") as file:\n                    data = file.read()\n            except FileNotFoundError:\n                raise Exception(f\"File not found. file_path={file_path}\")\n            except Exception as e:\n                raise Exception(f\"An error occurred: {str(e)}, file_path={file_path}\")\n\n        self.unsafe_content_categories = data\n\n        verbose_proxy_logger.debug(\n            f\"self.unsafe_content_categories: {self.unsafe_content_categories}\"\n        )","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/enterprise_callbacks/llama_guard.py#L16-L52","documentation":"ValueError raised in _ENTERPRISE_LlamaGuard.__init__ when neither the constructor's model_name argument nor litellm.llamaguard_model_name is set. LlamaGuard moderation needs a base LLM to classify safety, so the hook refuses to initialize without one.","triggerScenarios":"Adding the llama_guard callback/hook without setting llamaguard_model_name in litellm settings (e.g. litellm_settings.llamaguard_model_name: groq/llama-guard-3-8b) and without passing model_name programmatically. Initialization happens at proxy startup or hook registration.","commonSituations":"Copy-pasting an enterprise config that references the LlamaGuard hook but omitting the model setting; expecting the hook to work self-hosted without any underlying model; name typos in llamaguard_model_name.","solutions":["Set litellm_settings.llamaguard_model_name in the proxy config to a model available in model_list (e.g. an 8B LlamaGuard deployment on Groq, Together, or Ollama).","Or pass model_name explicitly when constructing _ENTERPRISE_LlamaGuard in code.","Verify the referenced model also exists in model_list so the moderation call itself can route.","If LlamaGuard is unwanted, remove the callback from config."],"exampleFix":"# before\nlitellm_settings:\n  callbacks: llama_guard  # no model configured -> ValueError\n\n# after\nlitellm_settings:\n  llamaguard_model_name: groq/llama-guard-3-8b\n  callbacks: llama_guard","handlingStrategy":"validation","validationCode":"import litellm\n\nif not (getattr(litellm, \"llamaguard_model_name\", None) or explicit_model_name):\n    raise SystemExit(\"set litellm_settings.llamaguard_model_name before enabling llama_guard\")","typeGuard":"from typing import Optional\n\ndef has_llamaguard_model(model_name: Optional[str]) -> bool:\n    return bool(model_name or getattr(litellm, \"llamaguard_model_name\", None))","tryCatchPattern":"try:\n    guard = _ENTERPRISE_LlamaGuard(model_name=name)\nexcept ValueError as e:\n    if \"model_name not set\" in str(e):\n        logger.error(\"configure llamaguard_model_name in litellm_settings\")\n    raise","preventionTips":["Set llamaguard_model_name in config before adding the llama_guard callback.","Ensure the guard model is also present in model_list so moderation calls route.","Add a config lint step that fails when llama_guard is enabled without a model.","Pin a specific guard model version to avoid silent behavior changes."],"tags":["enterprise","llama-guard","config","startup"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}