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]

UI - Content Filters, help edit/view categories and 1-click add categories + go to next page (#21223)

Krish Dholakia45690db8202a
diff --git a/litellm-proxy-extras/litellm_proxy_extras/migrations/20260214124140_baseline_diff/migration.sql b/litellm-proxy-extras/litellm_proxy_extras/migrations/20260214124140_baseline_diff/migration.sql
new file mode 100644
index 00000000000..2f725d83806
--- /dev/null
+++ b/litellm-proxy-extras/litellm_proxy_extras/migrations/20260214124140_baseline_diff/migration.sql
@@ -0,0 +1,2 @@
+-- This is an empty migration.
+
diff --git a/ui/litellm-dashboard/src/components/guardrails/add_guardrail_form.tsx b/ui/litellm-dashboard/src/components/guardrails/add_guardrail_form.tsx
index 71b61904dd5..0aad42feb08 100644
--- a/ui/litellm-dashboard/src/components/guardrails/add_guardrail_form.tsx
+++ b/ui/litellm-dashboard/src/components/guardrails/add_guardrail_form.tsx
@@ -109,6 +109,7 @@ const AddGuardrailForm: React.FC<AddGuardrailFormProps> = ({ visible, onClose, a
const [selectedPatterns, setSelectedPatterns] = useState<any[]>([]);
const [blockedWords, setBlockedWords] = useState<any[]>([]);
const [selectedContentCategories, setSelectedContentCategories] = useState<any[]>([]);
+ const [pendingCategorySelection, setPendingCategorySelection] = useState<string>("");
const [toolPermissionConfig, setToolPermissionConfig] = useState<ToolPermissionConfig>({
rules: [],
default_action: "deny",
@@ -169,6 +170,12 @@ const AddGuardrailForm: React.FC<AddGuardrailFormProps> = ({ visible, onClose, a
setGlobalSeverityThreshold(2);
setCategorySpecificThresholds({});
+ // Reset Content Filter selections
+ setSelectedPatterns([]);
+ setBlockedWords([]);
+ setSelectedContentCategories([]);
+ setPendingCategorySelection("");
+
setToolPermissionConfig({
rules: [],
default_action: "deny",
@@ -247,6 +254,39 @@ const AddGuardrailForm: React.FC<AddGuardrailFormProps> = ({ visible, onClose, a
setCurrentStep(currentStep - 1);
};
+ const handleAddAndContinue = () => {
+ if (!pendingCategorySelection || !guardrailSettings) return;
+
+ const contentFilterSettings = guardrailSettings.content_filter_settings;
+ if (!contentFilterSettings) return;
+
+ const category = contentFilterSettings.content_categories?.find((c) => c.name === pendingCategorySelection);
+ if (!category) return;
+
+ // Check if already added
+ if (selectedContentCategories.some((c) => c.category === pendingCategorySelection)) {
+ setPendingCategorySelection("");
+ setCurrentStep(currentStep + 1);
+ return;
+ }
+
+ // Add the category
+ setSelectedContentCategories([
+ ...selectedContentCategories,
+ {
+ id: `category-${Date.now()}`,
+ category: category.name,
+ display_name: category.display_name,
+ action: category.default_action as "BLOCK" | "MASK",
+ severity_threshold: "medium",
+ },
+ ]);
+
+ // Clear pending selection and advance to next step
+ setPendingCategorySelection("");
+ setCurrentStep(currentStep + 1);
+ };
+
const resetForm = () => {
form.resetFields();
setSelectedProvider(null);
@@ -258,6 +298,7 @@ const AddGuardrailForm: React.FC<AddGuardrailFormProps> = ({ visible, onClose, a
setSelectedPatterns([]);
setBlockedWords([]);
setSelectedContentCategories([]);
+ setPendingCategorySelection("");
setToolPermissionConfig({
rules: [],
default_action: "deny",
@@ -324,6 +365,15 @@ const AddGuardrailForm: React.FC<AddGuardrailFormProps> = ({ visible, onClose, a
// For Content Filter, add patterns, blocked words, and categories
if (shouldRenderContentFilterConfigSettings(values.provider)) {
+ // Validate that at least one content filter setting is configured
+ if (selectedPatterns.length === 0 && blockedWords.length === 0 && selectedContentCategories.length === 0) {
+ NotificationsManager.fromBackend(
+ "Please configure at least one content filter setting (category, pattern, or keyword)"
+ );
+ setLoading(false);
+ return;
+ }
+
if (selectedPatterns.length > 0) {
guardrailData.litellm_params.patterns = selectedPatterns.map((p) => ({
pattern_type: p.type === "prebuilt" ? "prebuilt" : "regex",
@@ -658,6 +708,8 @@ const AddGuardrailForm: React.FC<AddGuardrailFormProps> = ({ visible, onClose, a
selectedContentCategories.map((c) => (c.id === id ? { ...c, [field]: value } : c))
);
}}
+ pendingCategorySelection={pendingCategorySelection}
+ onPendingCategorySelectionChange={setPendingCategorySelection}
accessToken={accessToken}
showStep={step}
/>
@@ -720,6 +772,8 @@ const AddGuardrailForm: React.FC<AddGuardrailFormProps> = ({ visible, onClose, a
const renderStepButtons = () => {
const totalSteps = shouldRenderContentFilterConfigSettings(selectedProvider) ? 4 : 2;
const isLastStep = currentStep === totalSteps - 1;
+ const isCategoriesStep = shouldRenderContentFilterConfigSettings(selectedProvider) && currentStep === 1;
+ const hasPendingCategory = pendingCategorySelection !== "";
return (
<div className="flex justify-end space-x-2 mt-4">
@@ -728,11 +782,30 @@ const AddGuardrailForm: React.FC<AddGuardrailFormProps> = ({ visible, onClose, a
Previous
</Button>
)}
- {!isLastStep && <Button type="primary" onClick={nextStep}>Next</Button>}
- {isLastStep && (
- <Button type="primary" onClick={handleSubmit} loading={loading}>
- Create Guardrail
- </Button>
+ {isCategoriesStep ? (
+ <>
+ <Button onClick={nextStep}>
+ Skip
+ </Button>
+ <Button
+ type="primary"
+ onClick={handleAddAndContinue}
+ disabled={!hasPendingCategory}
+ >
+ Add & Continue →
+ </Button>
+ </>
+ ) : (
+ <>
+ {!isLastStep && (
+ <Button type="primary" onClick={nextStep}>Next</Button>
+ )}
+ {isLastStep && (
+ <Button type="primary" onClick={handleSubmit} loading={loading}>
+ Create Guardrail
+ </Button>
+ )}
+ </>
)}
<Button onClick={handleClose}>
Cancel
diff --git a/ui/litellm-dashboard/src/components/guardrails/content_filter/CategoryTable.tsx b/ui/litellm-dashboard/src/components/guardrails/content_filter/CategoryTable.tsx
new file mode 100644
index 00000000000..444be689f85
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/guardrails/content_filter/CategoryTable.tsx
@@ -0,0 +1,147 @@
+import React from "react";
+import { Typography, Select, Table, Tag, Button } from "antd";
+import { DeleteOutlined } from "@ant-design/icons";
+
+const { Text } = Typography;
+const { Option } = Select;
+
+interface ContentCategory {
+ id: string;
+ category: string;
+ display_name: string;
+ action: "BLOCK" | "MASK";
+ severity_threshold: "high" | "medium" | "low";
+}
+
+interface CategoryTableProps {
+ categories: ContentCategory[];
+ onActionChange?: (id: string, action: "BLOCK" | "MASK") => void;
+ onSeverityChange?: (id: string, severity: "high" | "medium" | "low") => void;
+ onRemove?: (id: string) => void;
+ readOnly?: boolean;
+}
+
+const CategoryTable: React.FC<CategoryTableProps> = ({
+ categories,
+ onActionChange,
+ onSeverityChange,
+ onRemove,
+ readOnly = false,
+}) => {
+ const columns = [
+ {
+ title: "Category",
+ dataIndex: "display_name",
+ key: "display_name",
+ render: (displayName: string, record: ContentCategory) => (
+ <div>
+ <Text strong>{displayName}</Text>
+ {displayName !== record.category && (
+ <div>
+ <Text type="secondary" style={{ fontSize: 12 }}>
+ {record.category}
+ </Text>
+ </div>
+ )}
+ </div>
+ ),
+ },
+ {
+ title: "Severity Threshold",
+ dataIndex: "severity_threshold",
+ key: "severity_threshold",
+ width: 180,
+ render: (severity: string, record: ContentCategory) => {
+ if (readOnly) {
+ const colorMap = {
+ high: "red",
+ medium: "orange",
+ low: "yellow",
+ } as const;
+ return (
+ <Tag color={colorMap[severity as keyof typeof colorMap]}>
+ {severity.toUpperCase()}
+ </Tag>
+ );
+ }
+ return (
+ <Select
+ value={severity}
+ onChange={(value) => onSeverityChange?.(record.id, value as "high" | "medium" | "low")}
+ style={{ width: 150 }}
+ size="small"
+ >
+ <Option value="high">High</Option>
+ <Option value="medium">Medium</Option>
+ <Option value="low">Low</Option>
+ </Select>
+ );
+ },
+ },
+ {
+ title: "Action",
+ dataIndex: "action",
+ key: "action",
+ width: 150,
+ render: (action: string, record: ContentCategory) => {
+ if (readOnly) {
+ return (
+ <Tag color={action === "BLOCK" ? "red" : "blue"}>
+ {action}
+ </Tag>
+ );
+ }
+ return (
+ <Select
+ value={action}
+ onChange={(value) => onActionChange?.(record.id, value as "BLOCK" | "MASK")}
+ style={{ width: 120 }}
+ size="small"
+ >
+ <Option value="BLOCK">Block</Option>
+ <Option value="MASK">Mask</Option>
+ </Select>
+ );
+ },
+ },
+ ];
+
+ if (!readOnly) {
+ columns.push({
+ title: "",
+ key: "actions",
+ width: 100,
+ render: (_: any, record: ContentCategory) => (
+ <Button
+ type="text"
+ danger
+ size="small"
+ icon={<DeleteOutlined />}
+ onClick={() => onRemove?.(record.id)}
+ >
+ Delete
+ </Button>
+ ),
+ } as any);
+ }
+
+ if (categories.length === 0) {
+ return (
+ <div style={{ textAlign: "center", padding: "40px 0", color: "#999" }}>
+ No categories configured.
+ </div>
+ );
+ }
+
+ return (
+ <Table
+ dataSource={categories}
+ columns={columns}
+ rowKey="id"
+ pagination={false}
+ size="small"
+ />
+ );
+};
+
+export default CategoryTable;
diff --git a/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentCategoryConfiguration.tsx b/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentCategoryConfiguration.tsx
index 0f8a02220b7..5ac5c70cd36 100644
--- a/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentCategoryConfiguration.tsx
+++ b/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentCategoryConfiguration.tsx
@@ -28,6 +28,8 @@ interface ContentCategoryConfigurationProps {
onCategoryRemove: (id: string) => void;
onCategoryUpdate: (id: string, field: string, value: any) => void;
accessToken?: string | null;
+ pendingSelection?: string;
+ onPendingSelectionChange?: (value: string) => void;
}
const ContentCategoryConfiguration: React.FC<ContentCategoryConfigurationProps> = ({
@@ -37,8 +39,13 @@ const ContentCategoryConfiguration: React.FC<ContentCategoryConfigurationProps>
onCategoryRemove,
onCategoryUpdate,
accessToken,
+ pendingSelection,
+ onPendingSelectionChange,
}) => {
- const [selectedCategoryName, setSelectedCategoryName] = React.useState<string>("");
+ // Use controlled state if parent provides it, otherwise use local state
+ const [localSelectedCategoryName, setLocalSelectedCategoryName] = React.useState<string>("");
+ const selectedCategoryName = pendingSelection !== undefined ? pendingSelection : localSelectedCategoryName;
+ const setSelectedCategoryName = onPendingSelectionChange || setLocalSelectedCategoryName;
const [categoryYaml, setCategoryYaml] = React.useState<{ [key: string]: string }>({});
const [categoryFileTypes, setCategoryFileTypes] = React.useState<{ [key: string]: string }>({});
const [loadingYaml, setLoadingYaml] = React.useState<{ [key: string]: boolean }>({});
diff --git a/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterConfiguration.tsx b/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterConfiguration.tsx
index 882abc0b933..5715b3c136b 100644
--- a/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterConfiguration.tsx
+++ b/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterConfiguration.tsx
@@ -69,6 +69,8 @@ interface ContentFilterConfigurationProps {
onContentCategoryAdd?: (category: SelectedContentCategory) => void;
onContentCategoryRemove?: (id: string) => void;
onContentCategoryUpdate?: (id: string, field: string, value: any) => void;
+ pendingCategorySelection?: string;
+ onPendingCategorySelectionChange?: (value: string) => void;
}
const ContentFilterConfiguration: React.FC<ContentFilterConfigurationProps> = ({
@@ -90,6 +92,8 @@ const ContentFilterConfiguration: React.FC<ContentFilterConfigurationProps> = ({
onContentCategoryAdd,
onContentCategoryRemove,
onContentCategoryUpdate,
+ pendingCategorySelection,
+ onPendingCategorySelectionChange,
}) => {
const [patternModalVisible, setPatternModalVisible] = useState(false);
const [keywordModalVisible, setKeywordModalVisible] = useState(false);
@@ -278,6 +282,8 @@ const ContentFilterConfiguration: React.FC<ContentFilterConfigurationProps> = ({
onCategoryRemove={onContentCategoryRemove}
onCategoryUpdate={onContentCategoryUpdate}
accessToken={accessToken}
+ pendingSelection={pendingCategorySelection}
+ onPendingSelectionChange={onPendingCategorySelectionChange}
/>
)}
diff --git a/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterDisplay.tsx b/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterDisplay.tsx
index 0c1e12d8860..db7345fa361 100644
--- a/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterDisplay.tsx
+++ b/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterDisplay.tsx
@@ -2,6 +2,7 @@ import React from "react";
import { Card, Text, Badge } from "@tremor/react";
import PatternTable from "./PatternTable";
import KeywordTable from "./KeywordTable";
+import CategoryTable from "./CategoryTable";
interface Pattern {
id: string;
@@ -19,26 +20,42 @@ interface BlockedWord {
description?: string;
}
+interface ContentCategory {
+ id: string;
+ category: string;
+ display_name: string;
+ action: "BLOCK" | "MASK";
+ severity_threshold: "high" | "medium" | "low";
+}
+
interface ContentFilterDisplayProps {
patterns: Pattern[];
blockedWords: BlockedWord[];
+ categories?: ContentCategory[];
readOnly?: boolean;
onPatternActionChange?: (id: string, action: "BLOCK" | "MASK") => void;
onPatternRemove?: (id: string) => void;
onBlockedWordUpdate?: (id: string, field: string, value: any) => void;
onBlockedWordRemove?: (id: string) => void;
+ onCategoryActionChange?: (id: string, action: "BLOCK" | "MASK") => void;
+ onCategorySeverityChange?: (id: string, severity: "high" | "medium" | "low") => void;
+ onCategoryRemove?: (id: string) => void;
}
const ContentFilterDisplay: React.FC<ContentFilterDisplayProps> = ({
patterns,
blockedWords,
+ categories = [],
readOnly = true,
onPatternActionChange,
onPatternRemove,
onBlockedWordUpdate,
onBlockedWordRemove,
+ onCategoryActionChange,
+ onCategorySeverityChange,
+ onCategoryRemove,
}) => {
- if (patterns.length === 0 && blockedWords.length === 0) {
+ if (patterns.length === 0 && blockedWords.length === 0 && categories.length === 0) {
return null;
}
@@ -47,6 +64,22 @@ const ContentFilterDisplay: React.FC<ContentFilterDisplayProps> = ({
return (
<>
+ {categories.length > 0 && (
+ <Card className="mt-6">
+ <div className="flex justify-between items-center mb-4">
+ <Text className="text-lg font-semibold">Content Categories</Text>
+ <Badge color="blue">{categories.length} categories configured</Badge>
+ </div>
+ <CategoryTable
+ categories={categories}
+ onActionChange={readOnly ? undefined : onCategoryActionChange}
+ onSeverityChange={readOnly ? undefined : onCategorySeverityChange}
+ onRemove={readOnly ? undefined : onCategoryRemove}
+ readOnly={readOnly}
+ />
+ </Card>
+ )}
+
{patterns.length > 0 && (
<Card className="mt-6">
<div className="flex justify-between items-center mb-4">
diff --git a/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterManager.tsx b/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterManager.tsx
index aa23c0e1db0..1070453425b 100644
--- a/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterManager.tsx
+++ b/ui/litellm-dashboard/src/components/guardrails/content_filter/ContentFilterManager.tsx
@@ -158,7 +158,14 @@ const ContentFilterManager: React.FC<ContentFilterManagerProps> = ({
// Read-only display mode
if (!isEditing) {
- return <ContentFilterDisplay patterns={selectedPatterns} blockedWords={blockedWords} readOnly={true} />;
+ return (
+ <ContentFilterDisplay
+ patterns={selectedPatterns}
+ blockedWords={blockedWords}
+ categories={selectedContentCategories}
+ readOnly={true}
+ />
+ );
}
// Edit mode