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

  1. Read {str(e)} from the message to identify the true OSError.
  2. Grant the proxy service account read access to the file.
  3. Ensure the path is a regular UTF-8 text file containing category tokens.
  4. 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

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


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/f735eaf4682d5fcf. Report an issue: GitHub.