{"record":{"id":"f735eaf4682d5fcf","repo":"BerriAI/litellm","slug":"an-error-occurred-str-e-file-path-file-path","errorCode":null,"errorMessage":"An error occurred: {str(e)}, file_path={file_path}","messagePattern":"An error occurred: (.+?), file_path=(.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"enterprise/litellm_enterprise/enterprise_callbacks/llama_guard.py","lineNumber":46,"sourceCode":"\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        )\n\n    def print_verbose(self, print_statement):\n        try:\n            verbose_proxy_logger.debug(print_statement)\n            if litellm.set_verbose:\n                print(print_statement)  # noqa\n        except Exception:\n            pass\n\n    def set_custom_prompt_template(self, messages: list):\n        if self.unsafe_content_categories is not None and self.model is not None:\n            role = \"Agent\" if len(messages) % 2 == 0 else \"User\"","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/enterprise_callbacks/llama_guard.py#L28-L64","documentation":"Exception raised in _ENTERPRISE_LlamaGuard.__init__ when reading the llamaguard_unsafe_content_categories file raises anything other than FileNotFoundError (broad except). The underlying error is only preserved as str(e) in the message, with the file path included for context.","triggerScenarios":"The categories file path exists but open()/read() fails: PermissionError (proxy user cannot read it), IsADirectoryError, or a UnicodeDecodeError on non-UTF-8 content.","commonSituations":"Secret-mounted files with restrictive ownership in Kubernetes; pointing the setting at a directory; files authored on Windows with a non-UTF-8 codepage.","solutions":["Read {str(e)} from the message to identify the true OSError.","Grant the proxy service account read access to the file.","Ensure the path is a regular UTF-8 text file containing category tokens.","Fall back to defaults by unsetting llamaguard_unsafe_content_categories."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef readable(p: str) -> bool:\n    try:\n        Path(p).read_text(encoding=\"utf-8\")\n        return True\n    except OSError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    guard = _ENTERPRISE_LlamaGuard(model_name=name)\nexcept Exception as e:\n    logger.error(\"categories file unreadable: %s\", e)  # str(e) has the OSError\n    raise","preventionTips":["chown/chmod the categories file for the proxy service account.","Keep the file plain UTF-8 text of category tokens.","Include the file in image builds; verify readability in CI.","Default to unset (LlamaGuard defaults) when a custom file adds no value."],"tags":["enterprise","llama-guard","file-io","permissions","startup"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}