BerriAI/litellm · error · HTTPException

Category file not found: {category_name} (tried .yaml and .j

Error message

Category file not found: {category_name} (tried .yaml and .json)

What it means

Raised in the guardrail category-content endpoint when category_name passed the safe_join validation but neither {category_name}.yaml nor {category_name}.json exists in the packaged categories directory — i.e. a well-formed but unknown category name (e.g. 'bias_nonexistent'). Delivered as HTTP 404 naming both extensions that were tried.

Source

Thrown at litellm/proxy/guardrails/guardrail_endpoints.py:1439

    # Try to find the file with either .yaml or .json extension
    try:
        yaml_path: Final = safe_join(categories_dir, f"{category_name}.yaml")
        json_path: Final = safe_join(categories_dir, f"{category_name}.json")
    except ValueError:
        raise HTTPException(status_code=400, detail="Invalid category name")

    category_file_path = None
    file_type = None

    if os.path.exists(yaml_path):
        category_file_path = yaml_path
        file_type = "yaml"
    elif os.path.exists(json_path):
        category_file_path = json_path
        file_type = "json"
    else:
        raise HTTPException(
            status_code=404,
            detail=f"Category file not found: {category_name} (tried .yaml and .json)",
        )

    try:
        # Read and return the raw content
        with open(category_file_path, "r") as f:
            content: Final = f.read()

        return {
            "category_name": category_name,
            "yaml_content": content,  # Keep key name for backwards compatibility
            "file_type": file_type,
        }
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error reading category file: {e}")

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Check the category name spelling and that a .yaml or .json category file exists for it.

Example fix

List available categories and retry with an existing one.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/guardrails/guardrail_endpoints.py:1439 when the library encounters an invalid state.

Common situations: No category file (.yaml/.json) exists for the requested category name.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/003bc1e91c7379f1. Report an issue: GitHub.