ui/litellm-dashboard/src/components/guardrails/README.md
This directory contains reusable React components for configuring various guardrail types in the LiteLLM dashboard.
The Azure Text Moderation configuration component allows users to configure Azure Content Safety settings for text moderation. It provides an intuitive interface for:
AzureTextModerationConfigurationThe main configuration component that renders the complete UI for Azure text moderation settings.
Props:
interface AzureTextModerationConfigurationProps {
categories: string[]; // Available categories
selectedCategories: string[]; // Currently selected categories
globalSeverityThreshold: number; // Global threshold (0, 2, 4, 6)
categorySpecificThresholds: { [key: string]: number }; // Per-category overrides
onCategorySelect: (category: string) => void; // Category selection handler
onGlobalSeverityChange: (threshold: number) => void; // Global threshold handler
onCategorySeverityChange: (category: string, threshold: number) => void; // Per-category handler
}
AzureTextModerationExampleA complete example showing how to integrate the configuration component with state management.
import React, { useState } from "react";
import { AzureTextModerationConfiguration, AZURE_TEXT_MODERATION_CATEGORIES } from "./guardrails";
const MyComponent = () => {
const [selectedCategories, setSelectedCategories] = useState<string[]>(["Hate", "Violence"]);
const [globalSeverityThreshold, setGlobalSeverityThreshold] = useState<number>(2);
const [categorySpecificThresholds, setCategorySpecificThresholds] = useState<{ [key: string]: number }>({});
const handleCategorySelect = (category: string) => {
setSelectedCategories((prev) =>
prev.includes(category) ? prev.filter((c) => c !== category) : [...prev, category],
);
};
const handleSave = () => {
const config = {
categories: selectedCategories,
severity_threshold: globalSeverityThreshold,
severity_threshold_by_category: categorySpecificThresholds,
};
// Save to backend...
};
return (
<AzureTextModerationConfiguration
categories={AZURE_TEXT_MODERATION_CATEGORIES.map((c) => c.name)}
selectedCategories={selectedCategories}
globalSeverityThreshold={globalSeverityThreshold}
categorySpecificThresholds={categorySpecificThresholds}
onCategorySelect={handleCategorySelect}
onGlobalSeverityChange={setGlobalSeverityThreshold}
onCategorySeverityChange={(category, threshold) =>
setCategorySpecificThresholds((prev) => ({ ...prev, [category]: threshold }))
}
/>
);
};
The component supports Azure's severity levels:
Four predefined categories are supported:
The component generates configuration objects compatible with the Azure Text Moderation guardrail:
{
"categories": ["Hate", "Violence"],
"severity_threshold": 2,
"severity_threshold_by_category": {
"Hate": 4,
"Violence": 2
}
}
The existing PII configuration component provides similar functionality for configuring PII entity detection and actions (MASK/BLOCK).
azure_text_moderation_types.ts - TypeScript interfaces and constantsazure_text_moderation_configuration.tsx - Main configuration componentazure_text_moderation_example.tsx - Usage examplepii_configuration.tsx - PII configuration componentpii_components.tsx - PII UI componentstypes.ts - PII TypeScript interfaces