The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(ui): migrate guardrails tabs to antd and fix internal user view
Ryan Crabbea287154905df
diff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.pyindex b1322d0eefd..b88c6524bb7 100644--- a/litellm/proxy/guardrails/guardrail_endpoints.py+++ b/litellm/proxy/guardrails/guardrail_endpoints.py@@ -17,7 +17,6 @@ from litellm.constants import DEFAULT_MAX_RECURSE_DEPTHfrom litellm.integrations.custom_guardrail import CustomGuardrailfrom litellm.litellm_core_utils.safe_json_dumps import safe_dumpsfrom litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth-from litellm.proxy.auth.auth_checks import get_team_membershipfrom litellm.proxy.auth.user_api_key_auth import user_api_key_authfrom litellm.proxy.guardrails.guardrail_hooks.custom_code.code_validator import (CustomCodeValidationError,@@ -616,6 +615,7 @@ async def register_guardrail(# Validate team membership for non-admin users when team differs from keyis_admin = user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMINif not is_admin and team_id != user_api_key_dict.team_id:+ from litellm.proxy.auth.auth_checks import get_team_membershipfrom litellm.proxy.proxy_server import user_api_key_cachemembership = await get_team_membership(diff --git a/ui/litellm-dashboard/src/components/guardrails.tsx b/ui/litellm-dashboard/src/components/guardrails.tsxindex 6bb4b387a88..d52aba15ab0 100644--- a/ui/litellm-dashboard/src/components/guardrails.tsx+++ b/ui/litellm-dashboard/src/components/guardrails.tsx@@ -1,6 +1,6 @@import React, { useState, useEffect } from "react";-import { Button, TabGroup, TabList, Tab, TabPanels, TabPanel } from "@tremor/react";-import { Dropdown } from "antd";+import { Button } from "@tremor/react";+import { Dropdown, Tabs } from "antd";import { DownOutlined, PlusOutlined, CodeOutlined } from "@ant-design/icons";import { getGuardrailsList, deleteGuardrailCall } from "./networking";import AddGuardrailForm from "./guardrails/add_guardrail_form";@@ -48,8 +48,6 @@ const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken, userRoleconst [guardrailToDelete, setGuardrailToDelete] = useState<Guardrail | null>(null);const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);const [selectedGuardrailId, setSelectedGuardrailId] = useState<string | null>(null);- const [activeTab, setActiveTab] = useState<number>(0);-const isAdmin = userRole ? isAdminRole(userRole) : false;const fetchGuardrails = async () => {@@ -135,124 +133,130 @@ const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken, userRolereturn (<div className="w-full mx-auto flex-auto overflow-y-auto m-8 p-2">- <TabGroup index={activeTab} onIndexChange={setActiveTab}>- <TabList className="mb-4">- {isAdmin && <Tab>Guardrail Garden</Tab>}- {isAdmin && <Tab>Guardrails</Tab>}- <Tab disabled={!accessToken || guardrailsList.length === 0}>Test Playground</Tab>- <Tab>Submitted Guardrails</Tab>- </TabList>+ <Tabs+ defaultActiveKey="submitted"+ items={[+ ...(isAdmin+ ? [+ {+ key: "garden",+ label: "Guardrail Garden",+ children: (+ <GuardrailGarden+ accessToken={accessToken}+ onGuardrailCreated={handleSuccess}+ />+ ),+ },+ {+ key: "guardrails",+ label: "Guardrails",+ children: (+ <>+ <div className="flex justify-between items-center mb-4">+ <Dropdown+ menu={{+ items: [+ {+ key: "provider",+ icon: <PlusOutlined />,+ label: "Add Provider Guardrail",+ onClick: handleAddGuardrail,+ },+ {+ key: "custom_code",+ icon: <CodeOutlined />,+ label: "Create Custom Code Guardrail",+ onClick: handleAddCustomCodeGuardrail,+ },+ ],+ }}+ trigger={["click"]}+ disabled={!accessToken}+ >+ <Button disabled={!accessToken}>+ + Add New Guardrail <DownOutlined className="ml-2" />+ </Button>+ </Dropdown>+ </div>- <TabPanels>- {isAdmin && (- <TabPanel>- <GuardrailGarden- accessToken={accessToken}- onGuardrailCreated={handleSuccess}- />- </TabPanel>- )}+ {selectedGuardrailId ? (+ <GuardrailInfoView+ guardrailId={selectedGuardrailId}+ onClose={() => setSelectedGuardrailId(null)}+ accessToken={accessToken}+ isAdmin={isAdmin}+ />+ ) : (+ <GuardrailTable+ guardrailsList={guardrailsList}+ isLoading={isLoading}+ onDeleteClick={handleDeleteClick}+ accessToken={accessToken}+ onGuardrailUpdated={fetchGuardrails}+ isAdmin={isAdmin}+ onGuardrailClick={(id) => setSelectedGuardrailId(id)}+ />+ )}- {isAdmin && (- <TabPanel>- <div className="flex justify-between items-center mb-4">- <Dropdown- menu={{- items: [- {- key: "provider",- icon: <PlusOutlined />,- label: "Add Provider Guardrail",- onClick: handleAddGuardrail,- },- {- key: "custom_code",- icon: <CodeOutlined />,- label: "Create Custom Code Guardrail",- onClick: handleAddCustomCodeGuardrail,- },- ],- }}- trigger={["click"]}- disabled={!accessToken}- >- <Button disabled={!accessToken}>- + Add New Guardrail <DownOutlined className="ml-2" />- </Button>- </Dropdown>- </div>+ <AddGuardrailForm+ visible={isAddModalVisible}+ onClose={handleCloseModal}+ accessToken={accessToken}+ onSuccess={handleSuccess}+ />- {selectedGuardrailId ? (- <GuardrailInfoView- guardrailId={selectedGuardrailId}- onClose={() => setSelectedGuardrailId(null)}- accessToken={accessToken}- isAdmin={isAdmin}- />- ) : (- <GuardrailTable- guardrailsList={guardrailsList}- isLoading={isLoading}- onDeleteClick={handleDeleteClick}- accessToken={accessToken}- onGuardrailUpdated={fetchGuardrails}- isAdmin={isAdmin}- onGuardrailClick={(id) => setSelectedGuardrailId(id)}- />- )}-- <AddGuardrailForm- visible={isAddModalVisible}- onClose={handleCloseModal}- accessToken={accessToken}- onSuccess={handleSuccess}- />+ <CustomCodeModal+ visible={isCustomCodeModalVisible}+ onClose={handleCloseCustomCodeModal}+ accessToken={accessToken}+ onSuccess={handleSuccess}+ />- <CustomCodeModal- visible={isCustomCodeModalVisible}- onClose={handleCloseCustomCodeModal}+ <DeleteResourceModal+ isOpen={isDeleteModalOpen}+ title="Delete Guardrail"+ message={`Are you sure you want to delete guardrail: ${guardrailToDelete?.guardrail_name}? This action cannot be undone.`}+ resourceInformationTitle="Guardrail Information"+ resourceInformation={[+ { label: "Name", value: guardrailToDelete?.guardrail_name },+ { label: "ID", value: guardrailToDelete?.guardrail_id, code: true },+ { label: "Provider", value: providerDisplayName },+ { label: "Mode", value: guardrailToDelete?.litellm_params.mode },+ {+ label: "Default On",+ value: guardrailToDelete?.litellm_params.default_on ? "Yes" : "No",+ },+ ]}+ onCancel={handleDeleteCancel}+ onOk={handleDeleteConfirm}+ confirmLoading={isDeleting}+ />+ </>+ ),+ },+ ]+ : []),+ {+ key: "playground",+ label: "Test Playground",+ disabled: !accessToken || guardrailsList.length === 0,+ children: (+ <GuardrailTestPlayground+ guardrailsList={guardrailsList}+ isLoading={isLoading}accessToken={accessToken}- onSuccess={handleSuccess}- />-- <DeleteResourceModal- isOpen={isDeleteModalOpen}- title="Delete Guardrail"- message={`Are you sure you want to delete guardrail: ${guardrailToDelete?.guardrail_name}? This action cannot be undone.`}- resourceInformationTitle="Guardrail Information"- resourceInformation={[- { label: "Name", value: guardrailToDelete?.guardrail_name },- { label: "ID", value: guardrailToDelete?.guardrail_id, code: true },- { label: "Provider", value: providerDisplayName },- { label: "Mode", value: guardrailToDelete?.litellm_params.mode },- {- label: "Default On",- value: guardrailToDelete?.litellm_params.default_on ? "Yes" : "No",- },- ]}- onCancel={handleDeleteCancel}- onOk={handleDeleteConfirm}- confirmLoading={isDeleting}+ onClose={() => {}}/>- </TabPanel>- )}-- {/* Test Playground Tab */}- <TabPanel>- <GuardrailTestPlayground- guardrailsList={guardrailsList}- isLoading={isLoading}- accessToken={accessToken}- onClose={() => setActiveTab(0)}- />- </TabPanel>-- {/* Team Guardrails Tab */}- <TabPanel>- <TeamGuardrailsTab accessToken={accessToken} />- </TabPanel>- </TabPanels>- </TabGroup>+ ),+ },+ {+ key: "submitted",+ label: "Submitted Guardrails",+ children: <TeamGuardrailsTab accessToken={accessToken} />,+ },+ ]}+ /></div>);};diff --git a/ui/litellm-dashboard/src/components/guardrails/TeamGuardrailsTab.tsx b/ui/litellm-dashboard/src/components/guardrails/TeamGuardrailsTab.tsxindex 8bd2cdd1964..c3c1836e3c6 100644--- a/ui/litellm-dashboard/src/components/guardrails/TeamGuardrailsTab.tsx+++ b/ui/litellm-dashboard/src/components/guardrails/TeamGuardrailsTab.tsx@@ -25,6 +25,8 @@ import {import NotificationsManager from "@/components/molecules/notifications_manager";import TeamDropdown from "@/components/common_components/team_dropdown";import { useRegisterGuardrail } from "@/app/(dashboard)/hooks/guardrails/useRegisterGuardrail";+import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";+import { isAdminRole } from "@/utils/roles";type GuardrailStatus = "active" | "pending" | "rejected";@@ -803,6 +805,8 @@ interface TeamGuardrailsTabProps {}export function TeamGuardrailsTab({ accessToken }: TeamGuardrailsTabProps) {+ const { userRole } = useAuthorized();+ const isAdmin = userRole ? isAdminRole(userRole) : false;const [guardrails, setGuardrails] = useState<TeamGuardrail[]>([]);const [summary, setSummary] = useState({total: 0,@@ -833,7 +837,7 @@ export function TeamGuardrailsTab({ accessToken }: TeamGuardrailsTabProps) {}, [search]);const fetchSubmissions = useCallback(async () => {- if (!accessToken) {+ if (!accessToken || !isAdmin) {setIsLoading(false);return;}@@ -858,7 +862,7 @@ export function TeamGuardrailsTab({ accessToken }: TeamGuardrailsTabProps) {} finally {setIsLoading(false);}- }, [accessToken, statusFilter, searchDebounced]);+ }, [accessToken, isAdmin, statusFilter, searchDebounced]);useEffect(() => {fetchSubmissions();