Skip to content

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]

[Feat] UI: Allow clicking into a guardrail (#10904)

Ishaan Jaff888c4130bb0e
diff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.py
index 80c25683cfc..a71718e9b89 100644
--- a/litellm/proxy/guardrails/guardrail_endpoints.py
+++ b/litellm/proxy/guardrails/guardrail_endpoints.py
@@ -433,6 +433,71 @@ async def delete_guardrail(guardrail_id: str):
raise HTTPException(status_code=500, detail=str(e))
+ "/guardrails/{guardrail_id}/info",
+ tags=["Guardrails"],
+ dependencies=[Depends(user_api_key_auth)],
+)
+async def get_guardrail_info(guardrail_id: str):
+ """
+ Get detailed information about a specific guardrail by ID
+
+ 👉 [Guardrail docs](https://docs.litellm.ai/docs/proxy/guardrails/quick_start)
+
+ Example Request:
+ ```bash
+ curl -X GET "http://localhost:4000/guardrails/123e4567-e89b-12d3-a456-426614174000/info" \\
+ -H "Authorization: Bearer <your_api_key>"
+ ```
+
+ Example Response:
+ ```json
+ {
+ "guardrail_id": "123e4567-e89b-12d3-a456-426614174000",
+ "guardrail_name": "my-bedrock-guard",
+ "litellm_params": {
+ "guardrail": "bedrock",
+ "mode": "pre_call",
+ "guardrailIdentifier": "ff6ujrregl1q",
+ "guardrailVersion": "DRAFT",
+ "default_on": true
+ },
+ "guardrail_info": {
+ "description": "Bedrock content moderation guardrail"
+ },
+ "created_at": "2023-11-09T12:34:56.789Z",
+ "updated_at": "2023-11-09T12:34:56.789Z"
+ }
+ ```
+ """
+ from litellm.proxy.proxy_server import prisma_client
+
+ if prisma_client is None:
+ raise HTTPException(status_code=500, detail="Prisma client not initialized")
+
+ try:
+ result = await GUARDRAIL_REGISTRY.get_guardrail_by_id_from_db(
+ guardrail_id=guardrail_id, prisma_client=prisma_client
+ )
+ if result is None:
+ raise HTTPException(
+ status_code=404, detail=f"Guardrail with ID {guardrail_id} not found"
+ )
+
+ return GuardrailInfoResponse(
+ guardrail_id=result.get("guardrail_id"),
+ guardrail_name=result.get("guardrail_name"),
+ litellm_params=result.get("litellm_params"),
+ guardrail_info=result.get("guardrail_info"),
+ created_at=result.get("created_at"),
+ updated_at=result.get("updated_at"),
+ )
+ except HTTPException as e:
+ raise e
+ except Exception as e:
+ raise HTTPException(status_code=500, detail=str(e))
+
+
@router.get(
"/guardrails/ui/add_guardrail_settings",
tags=["Guardrails"],
diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx
index 17503281292..eb8a7a8df69 100644
--- a/ui/litellm-dashboard/src/app/page.tsx
+++ b/ui/litellm-dashboard/src/app/page.tsx
@@ -359,7 +359,7 @@ export default function CreateKeyPage() {
) : page == "budgets" ? (
<BudgetPanel accessToken={accessToken} />
) : page == "guardrails" ? (
- <GuardrailsPanel accessToken={accessToken} />
+ <GuardrailsPanel accessToken={accessToken} userRole={userRole} />
): page == "transform-request" ? (
<TransformRequestPanel accessToken={accessToken} />
): page == "general-settings" ? (
diff --git a/ui/litellm-dashboard/src/components/guardrails.tsx b/ui/litellm-dashboard/src/components/guardrails.tsx
index 354ad43f0e1..d82da325c78 100644
--- a/ui/litellm-dashboard/src/components/guardrails.tsx
+++ b/ui/litellm-dashboard/src/components/guardrails.tsx
@@ -13,9 +13,11 @@ import { Modal, message } from "antd";
import { getGuardrailsList, deleteGuardrailCall } from "./networking";
import AddGuardrailForm from "./guardrails/add_guardrail_form";
import GuardrailTable from "./guardrails/guardrail_table";
+import { isAdminRole } from "@/utils/roles";
interface GuardrailsPanelProps {
accessToken: string | null;
+ userRole?: string;
}
interface GuardrailItem {
@@ -35,12 +37,15 @@ interface GuardrailsResponse {
guardrails: GuardrailItem[];
}
-const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken }) => {
+const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken, userRole }) => {
const [guardrailsList, setGuardrailsList] = useState<GuardrailItem[]>([]);
const [isAddModalVisible, setIsAddModalVisible] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
const [guardrailToDelete, setGuardrailToDelete] = useState<{id: string, name: string} | null>(null);
+ const [isViewingGuardrailInfo, setIsViewingGuardrailInfo] = useState(false);
+
+ const isAdmin = userRole ? isAdminRole(userRole) : false;
const fetchGuardrails = async () => {
if (!accessToken) {
@@ -103,15 +108,17 @@ const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken }) => {
return (
<div className="w-full mx-auto flex-auto overflow-y-auto m-8 p-2">
- <div className="flex justify-between items-center mb-4">
- <Button
- icon={PlusIcon}
- onClick={handleAddGuardrail}
- disabled={!accessToken}
- >
- Add Guardrail
- </Button>
- </div>
+ {!isViewingGuardrailInfo && (
+ <div className="flex justify-between items-center mb-4">
+ <Button
+ icon={PlusIcon}
+ onClick={handleAddGuardrail}
+ disabled={!accessToken}
+ >
+ Add Guardrail
+ </Button>
+ </div>
+ )}
<GuardrailTable
guardrailsList={guardrailsList}
@@ -119,6 +126,8 @@ const GuardrailsPanel: React.FC<GuardrailsPanelProps> = ({ accessToken }) => {
onDeleteClick={handleDeleteClick}
accessToken={accessToken}
onGuardrailUpdated={fetchGuardrails}
+ isAdmin={isAdmin}
+ onShowGuardrailInfo={setIsViewingGuardrailInfo}
/>
<AddGuardrailForm
diff --git a/ui/litellm-dashboard/src/components/guardrails/guardrail_info.tsx b/ui/litellm-dashboard/src/components/guardrails/guardrail_info.tsx
new file mode 100644
index 00000000000..fe07bf30959
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/guardrails/guardrail_info.tsx
@@ -0,0 +1,287 @@
+import React, { useState, useEffect } from "react";
+import {
+ Card,
+ Title,
+ Text,
+ Grid,
+ Badge,
+ Button as TremorButton,
+ Tab,
+ TabGroup,
+ TabList,
+ TabPanel,
+ TabPanels,
+} from "@tremor/react";
+import { Button, Form, Input, Select, message, Tooltip } from "antd";
+import { InfoCircleOutlined } from '@ant-design/icons';
+import { getGuardrailInfo } from "@/components/networking";
+import { getGuardrailLogoAndName } from "./guardrail_info_helpers";
+
+export interface GuardrailInfoProps {
+ guardrailId: string;
+ onClose: () => void;
+ accessToken: string | null;
+ isAdmin: boolean;
+}
+
+const GuardrailInfoView: React.FC<GuardrailInfoProps> = ({
+ guardrailId,
+ onClose,
+ accessToken,
+ isAdmin
+}) => {
+ const [guardrailData, setGuardrailData] = useState<any>(null);
+ const [loading, setLoading] = useState(true);
+ const [isEditing, setIsEditing] = useState(false);
+ const [form] = Form.useForm();
+
+ const fetchGuardrailInfo = async () => {
+ try {
+ setLoading(true);
+ if (!accessToken) return;
+ const response = await getGuardrailInfo(accessToken, guardrailId);
+ setGuardrailData(response);
+ } catch (error) {
+ message.error("Failed to load guardrail information");
+ console.error("Error fetching guardrail info:", error);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ fetchGuardrailInfo();
+ }, [guardrailId, accessToken]);
+
+
+ const handleGuardrailUpdate = async (values: any) => {
+ try {
+ // Not implemented yet - will be added in the future
+ message.info("Guardrail update functionality coming soon");
+ setIsEditing(false);
+ } catch (error) {
+ console.error("Error updating guardrail:", error);
+ }
+ };
+
+ if (loading) {
+ return <div className="p-4">Loading...</div>;
+ }
+
+ if (!guardrailData) {
+ return <div className="p-4">Guardrail not found</div>;
+ }
+
+ // Format date helper function
+ const formatDate = (dateString?: string) => {
+ if (!dateString) return "-";
+ const date = new Date(dateString);
+ return date.toLocaleString();
+ };
+
+ // Format the provider display name and logo
+ const { logo, displayName } = getGuardrailLogoAndName(guardrailData.litellm_params?.guardrail || "");
+
+ return (
+ <div className="p-4">
+ <div className="flex justify-between items-center mb-6">
+ <div>
+ <Button onClick={onClose} className="mb-4">← Back</Button>
+ <Title>{guardrailData.guardrail_name || "Unnamed Guardrail"}</Title>
+ <Text className="text-gray-500 font-mono">{guardrailData.guardrail_id}</Text>
+ </div>
+ </div>
+
+ <TabGroup>
+ <TabList className="mb-4">
+ <Tab key="overview">Overview</Tab>
+ {isAdmin ? <Tab key="settings">Settings</Tab> : <></>}
+ </TabList>
+
+ <TabPanels>
+ {/* Overview Panel */}
+ <TabPanel>
+ <Grid numItems={1} numItemsSm={2} numItemsLg={3} className="gap-6">
+ <Card>
+ <Text>Provider</Text>
+ <div className="mt-2 flex items-center space-x-2">
+ {logo && (
+ <img
+ src={logo}
+ alt={`${displayName} logo`}
+ className="w-6 h-6"
+ onError={(e) => {
+ // Hide broken image
+ (e.target as HTMLImageElement).style.display = 'none';
+ }}
+ />
+ )}
+ <Title>{displayName}</Title>
+ </div>
+ </Card>
+
+ <Card>
+ <Text>Mode</Text>
+ <div className="mt-2">
+ <Title>{guardrailData.litellm_params?.mode || "-"}</Title>
+ <Badge color={guardrailData.litellm_params?.default_on ? "green" : "gray"}>
+ {guardrailData.litellm_params?.default_on ? "Default On" : "Default Off"}
+ </Badge>
+ </div>
+ </Card>
+
+ <Card>
+ <Text>Created At</Text>
+ <div className="mt-2">
+ <Title>{formatDate(guardrailData.created_at)}</Title>
+ <Text>Last Updated: {formatDate(guardrailData.updated_at)}</Text>
+ </div>
+ </Card>
+ </Grid>
+
+ <Card className="mt-6">
+ <Text>Provider Configuration</Text>
+ <div className="mt-2 space-y-2">
+ {Object.entries(guardrailData.litellm_params || {}).map(([key, value]) => {
+ // Skip mode and guardrail as they're displayed above
+ if (key === 'mode' || key === 'guardrail' || key === 'default_on') return null;
+
+ return (
+ <div key={key} className="flex">
+ <Text className="font-medium w-1/3">{key}</Text>
+ <Text className="w-2/3">
+ {typeof value === 'object'
+ ? JSON.stringify(value, null, 2)
+ : String(value)}
+ </Text>
+ </div>
+ );
+ })}
+ </div>
+ </Card>
+
+ {guardrailData.guardrail_info && Object.keys(guardrailData.guardrail_info).length > 0 && (
+ <Card className="mt-6">
+ <Text>Additional Information</Text>
+ <div className="mt-2 space-y-2">
+ {Object.entries(guardrailData.guardrail_info).map(([key, value]) => (
+ <div key={key} className="flex">
+ <Text className="font-medium w-1/3">{key}</Text>
+ <Text className="w-2/3">
+ {typeof value === 'object'
+ ? JSON.stringify(value, null, 2)
+ : String(value)}
+ </Text>
+ </div>
+ ))}
+ </div>
+ </Card>
+ )}
+ </TabPanel>
+
+ {/* Settings Panel (only for admins) */}
+ {isAdmin && (
+ <TabPanel>
+ <Card>
+ <div className="flex justify-between items-center mb-4">
+ <Title>Guardrail Settings</Title>
+ {!isEditing && (
+ <TremorButton
+ onClick={() => setIsEditing(true)}
+ >
+ Edit Settings
+ </TremorButton>
+ )}
+ </div>
+
+ {isEditing ? (
+ <Form
+ form={form}
+ onFinish={handleGuardrailUpdate}
+ initialValues={{
+ guardrail_name: guardrailData.guardrail_name,
+ ...guardrailData.litellm_params,
+ guardrail_info: guardrailData.guardrail_info
+ ? JSON.stringify(guardrailData.guardrail_info, null, 2)
+ : "",
+ }}
+ layout="vertical"
+ >
+ <Form.Item
+ label="Guardrail Name"
+ name="guardrail_name"
+ rules={[{ required: true, message: "Please input a guardrail name" }]}
+ >
+ <Input />
+ </Form.Item>
+
+ <Form.Item
+ label="Default On"
+ name="default_on"
+ >
+ <Select>
+ <Select.Option value={true}>Yes</Select.Option>
+ <Select.Option value={false}>No</Select.Option>
+ </Select>
+ </Form.Item>
+
+ <Form.Item
+ label="Additional Information"
+ name="guardrail_info"
+ >
+ <Input.TextArea rows={5} />
+ </Form.Item>
+
+ <div className="flex justify-end gap-2 mt-6">
+ <Button onClick={() => setIsEditing(false)}>
+ Cancel
+ </Button>
+ <TremorButton>
+ Save Changes
+ </TremorButton>
+ </div>
+ </Form>
+ ) : (
+ <div className="space-y-4">
+ <div>
+ <Text className="font-medium">Guardrail ID</Text>
+ <div className="font-mono">{guardrailData.guardrail_id}</div>
+ </div>
+ <div>
+ <Text className="font-medium">Guardrail Name</Text>
+ <div>{guardrailData.guardrail_name || "Unnamed Guardrail"}</div>
+ </div>
+ <div>
+ <Text className="font-medium">Provider</Text>
+ <div>{displayName}</div>
+ </div>
+ <div>
+ <Text className="font-medium">Mode</Text>
+ <div>{guardrailData.litellm_params?.mode || "-"}</div>
+ </div>
+ <div>
+ <Text className="font-medium">Default On</Text>
+ <Badge color={guardrailData.litellm_params?.default_on ? "green" : "gray"}>
+ {guardrailData.litellm_params?.default_on ? "Yes" : "No"}
+ </Badge>
+ </div>
+ <div>
+ <Text className="font-medium">Created At</Text>
+ <div>{formatDate(guardrailData.created_at)}</div>
+ </div>
+ <div>
+ <Text className="font-medium">Last Updated</Text>
+ <div>{formatDate(guardrailData.updated_at)}</div>
+ </div>
+ </div>
+ )}
+ </Card>
+ </TabPanel>
+ )}
+ </TabPanels>
+ </TabGroup>
+ </div>
+ );
+};
+
+export default GuardrailInfoView;
\ No newline at end of file
diff --git a/ui/litellm-dashboard/src/components/guardrails/guardrail_table.tsx b/ui/litellm-dashboard/src/components/guardrails/guardrail_table.tsx
index 754bd8d1acb..00a1c91e0ad 100644
--- a/ui/litellm-dashboard/src/components/guardrails/guardrail_table.tsx
+++ b/ui/litellm-dashboard/src/components/guardrails/guardrail_table.tsx
@@ -7,6 +7,7 @@ import {
TableHeaderCell,
TableRow,
Icon,
+ Button,
} from "@tremor/react";
import {
TrashIcon,
@@ -26,6 +27,7 @@ import {
} from "@tanstack/react-table";
import { getGuardrailLogoAndName, guardrail_provider_map } from "./guardrail_info_helpers";
import EditGuardrailForm from "./edit_guardrail_form";
+import GuardrailInfoView from "./guardrail_info";
interface GuardrailItem {
guardrail_id?: string;
@@ -48,6 +50,8 @@ interface GuardrailTableProps {
onDeleteClick: (guardrailId: string, guardrailName: string) => void;
accessToken: string | null;
onGuardrailUpdated: () => void;
+ isAdmin?: boolean;
+ onShowGuardrailInfo?: (isVisible: boolean) => void;
}
const GuardrailTable: React.FC<GuardrailTableProps> = ({
@@ -56,12 +60,16 @@ const GuardrailTable: React.FC<GuardrailTableProps> = ({
onDeleteClick,
accessToken,
onGuardrailUpdated,
+ isAdmin = false,
+ onShowGuardrailInfo,
}) => {
const [sorting, setSorting] = useState<SortingState>([
{ id: "created_at", desc: true }
]);
const [editModalVisible, setEditModalVisible] = useState(false);
const [selectedGuardrail, setSelectedGuardrail] = useState<GuardrailItem | null>(null);
+ const [showGuardrailInfo, setShowGuardrailInfo] = useState(false);
+ const [selectedGuardrailId, setSelectedGuardrailId] = useState<string | null>(null);
// Format date helper function
const formatDate = (dateString?: string) => {
@@ -81,15 +89,39 @@ const GuardrailTable: React.FC<GuardrailTableProps> = ({
onGuardrailUpdated();
};
+ const handleGuardrailIdClick = (guardrailId: string) => {
+ setSelectedGuardrailId(guardrailId);
+ setShowGuardrailInfo(true);
+ onShowGuardrailInfo?.(true);
+ };
+
+ const handleGuardrailInfoClose = () => {
+ setShowGuardrailInfo(false);
+ setSelectedGuardrailId(null);
+ onShowGuardrailInfo?.(false);
+ };
+
+ const handleGuardrailDeleted = () => {
+ setShowGuardrailInfo(false);
+ setSelectedGuardrailId(null);
+ onShowGuardrailInfo?.(false);
+ onGuardrailUpdated();
+ };
+
const columns: ColumnDef<GuardrailItem>[] = [
{
header: "Guardrail ID",
accessorKey: "guardrail_id",
cell: (info: any) => (
<Tooltip title={String(info.getValue() || "")}>
- <span className="font-mono text-xs max-w-[15ch] truncate block">
- {String(info.getValue() || "")}
- </span>
+ <Button
+ size="xs"
+ variant="light"
+ className="font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]"
+ onClick={() => info.getValue() && handleGuardrailIdClick(info.getValue())}
+ >
+ {info.getValue() ? `${String(info.getValue()).slice(0, 7)}...` : ""}
+ </Button>
</Tooltip>
),
},
@@ -210,6 +242,18 @@ const GuardrailTable: React.FC<GuardrailTableProps> = ({
enableSorting: true,
});
+ // If showing guardrail info, render the GuardrailInfoView
+ if (showGuardrailInfo && selectedGuardrailId) {
+ return (
+ <GuardrailInfoView
+ guardrailId={selectedGuardrailId}
+ onClose={handleGuardrailInfoClose}
+ accessToken={accessToken}
+ isAdmin={isAdmin}
+ />
+ );
+ }
+
return (
<div className="rounded-lg custom-border relative">
<div className="overflow-x-auto">
diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx
index 56029f51be2..beaaf3efdfc 100644
--- a/ui/litellm-dashboard/src/components/networking.tsx
+++ b/ui/litellm-dashboard/src/components/networking.tsx
@@ -5124,3 +5124,28 @@ export const getGuardrailProviderSpecificParams = async (accessToken: string) =>
throw error;
}
};
+
+export const getGuardrailInfo = async (accessToken: string, guardrailId: string) => {
+ const url = proxyBaseUrl ? `${proxyBaseUrl}/guardrails/${guardrailId}/info` : `/guardrails/${guardrailId}/info`;
+
+ try {
+ const response = await fetch(url, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ ...(accessToken ? { "Authorization": `Bearer ${accessToken}` } : {})
+ }
+ });
+
+ if (!response.ok) {
+ const errorData = await response.text();
+ throw new Error(errorData);
+ }
+
+ const data = await response.json();
+ return data;
+ } catch (error) {
+ console.error("Error fetching guardrail info:", error);
+ throw error;
+ }
+};