BerriAI/litellm · error · Exception
An error occurred: {str(e)}, file_path={file_path}
Error message
An error occurred: {str(e)}, file_path={file_path} What it means
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.
Source
Thrown at enterprise/litellm_enterprise/enterprise_callbacks/llama_guard.py:46
class _ENTERPRISE_LlamaGuard(CustomLogger):
# Class variables or attributes
def __init__(self, model_name: Optional[str] = None):
_model = model_name or litellm.llamaguard_model_name
if _model is None:
raise ValueError("model_name not set for LlamaGuard")
self.model = _model
file_path = litellm.llamaguard_unsafe_content_categories
data = None
if file_path is not None:
try:
with open(file_path, "r") as file:
data = file.read()
except FileNotFoundError:
raise Exception(f"File not found. file_path={file_path}")
except Exception as e:
raise Exception(f"An error occurred: {str(e)}, file_path={file_path}")
self.unsafe_content_categories = data
verbose_proxy_logger.debug(
f"self.unsafe_content_categories: {self.unsafe_content_categories}"
)
def print_verbose(self, print_statement):
try:
verbose_proxy_logger.debug(print_statement)
if litellm.set_verbose:
print(print_statement) # noqa
except Exception:
pass
def set_custom_prompt_template(self, messages: list):
if self.unsafe_content_categories is not None and self.model is not None:
role = "Agent" if len(messages) % 2 == 0 else "User"View on GitHub (pinned to 6c2dcb801b)
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.
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def readable(p: str) -> bool:
try:
Path(p).read_text(encoding="utf-8")
return True
except OSError:
return False Try / catch
try:
guard = _ENTERPRISE_LlamaGuard(model_name=name)
except Exception as e:
logger.error("categories file unreadable: %s", e) # str(e) has the OSError
raise Prevention
- 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.
When it happens
Trigger: The categories file path exists but open()/read() fails: PermissionError (proxy user cannot read it), IsADirectoryError, or a UnicodeDecodeError on non-UTF-8 content.
Common situations: Secret-mounted files with restrictive ownership in Kubernetes; pointing the setting at a directory; files authored on Windows with a non-UTF-8 codepage.
Related errors
- An error occurred: {str(e)}, blocked_user_list={blocked_user
- File not found. file_path={file_path}
- File not found. blocked_user_list={blocked_user_list}
- model_name not set for LlamaGuard
- Missing google.cloud package. Run `pip install --upgrade goo
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/f735eaf4682d5fcf.
Report an issue: GitHub.