BerriAI/litellm · error · HTTPException

Admin access required to test custom code guardrails

Error message

Admin access required to test custom code guardrails

What it means

Raised by the custom-code guardrail test endpoint when the caller's role is not PROXY_ADMIN. The endpoint compiles and executes arbitrary user-supplied guardrail code, so trying it is admin-only by design; the role check runs before any code compilation or the 5-second sandboxed execution begins.

Source

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

        },
        "error": null,
        "error_type": null
    }
    ```

    Example Error Response (compilation error):
    ```json
    {
        "success": false,
        "result": null,
        "error": "Syntax error in custom code: invalid syntax (<guardrail>, line 1)",
        "error_type": "compilation"
    }
    ```
    """

    if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN:
        raise HTTPException(
            status_code=403,
            detail="Admin access required to test custom code guardrails",
        )

    EXECUTION_TIMEOUT_SECONDS: Final = 5

    try:
        exec_globals: Final = build_sandbox_globals()

        try:
            compiled: Final[CodeType] = compile_sandboxed(request.custom_code)
            exec(compiled, exec_globals)  # noqa: S102
        except SyntaxError as e:
            return TestCustomCodeGuardrailResponse(
                success=False,
                error=f"Syntax error in custom code: {e}",
                error_type="compilation",
            )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Use a proxy admin key to test custom code guardrails.

Example fix

Retry with an admin key in the Authorization header.
Defensive patterns

Strategy: validation

When it happens

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

Common situations: A non-admin attempted to test a custom code guardrail.


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