{"record":{"id":"d9686891f25f3460","repo":"BerriAI/litellm","slug":"admin-access-required-to-test-custom-code-guardrai","errorCode":null,"errorMessage":"Admin access required to test custom code guardrails","messagePattern":"Admin access required to test custom code guardrails","errorType":"http","errorClass":"HTTPException","httpStatus":403,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_endpoints.py","lineNumber":2072,"sourceCode":"        },\n        \"error\": null,\n        \"error_type\": null\n    }\n    ```\n\n    Example Error Response (compilation error):\n    ```json\n    {\n        \"success\": false,\n        \"result\": null,\n        \"error\": \"Syntax error in custom code: invalid syntax (<guardrail>, line 1)\",\n        \"error_type\": \"compilation\"\n    }\n    ```\n    \"\"\"\n\n    if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN:\n        raise HTTPException(\n            status_code=403,\n            detail=\"Admin access required to test custom code guardrails\",\n        )\n\n    EXECUTION_TIMEOUT_SECONDS: Final = 5\n\n    try:\n        exec_globals: Final = build_sandbox_globals()\n\n        try:\n            compiled: Final[CodeType] = compile_sandboxed(request.custom_code)\n            exec(compiled, exec_globals)  # noqa: S102\n        except SyntaxError as e:\n            return TestCustomCodeGuardrailResponse(\n                success=False,\n                error=f\"Syntax error in custom code: {e}\",\n                error_type=\"compilation\",\n            )","sourceCodeStart":2054,"sourceCodeEnd":2090,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_endpoints.py#L2054-L2090","documentation":"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.","triggerScenarios":"Thrown at litellm/proxy/guardrails/guardrail_endpoints.py:2072 when the library encounters an invalid state.","commonSituations":"A non-admin attempted to test a custom code guardrail.","solutions":["Use a proxy admin key to test custom code guardrails."],"exampleFix":"Retry with an admin key in the Authorization header.","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}