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]

fix(guardrails): add azure content safety guardrails to the UI (#12309)

Krish Dholakia3362503927b7
diff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.py
index 42792b9be4c..cb79fc0871c 100644
--- a/litellm/proxy/guardrails/guardrail_endpoints.py
+++ b/litellm/proxy/guardrails/guardrail_endpoints.py
@@ -12,6 +12,8 @@ from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
from litellm.proxy.guardrails.guardrail_registry import GuardrailRegistry
from litellm.types.guardrails import (
PII_ENTITY_CATEGORIES_MAP,
+ AzureContentSafetyPromptShieldConfigModel,
+ AzureContentSafetyTextModerationConfigModel,
BedrockGuardrailConfigModel,
Guardrail,
GuardrailEventHooks,
@@ -767,12 +769,20 @@ async def get_provider_specific_params():
bedrock_fields = _get_fields_from_model(BedrockGuardrailConfigModel)
presidio_fields = _get_fields_from_model(PresidioPresidioConfigModelUserInterface)
lakera_v2_fields = _get_fields_from_model(LakeraV2GuardrailConfigModel)
+ azure_content_safety_prompt_shield_fields = _get_fields_from_model(
+ AzureContentSafetyPromptShieldConfigModel
+ )
+ azure_content_safety_text_moderation_fields = _get_fields_from_model(
+ AzureContentSafetyTextModerationConfigModel
+ )
# Return the provider-specific parameters
provider_params = {
SupportedGuardrailIntegrations.BEDROCK.value: bedrock_fields,
SupportedGuardrailIntegrations.PRESIDIO.value: presidio_fields,
SupportedGuardrailIntegrations.LAKERA_V2.value: lakera_v2_fields,
+ SupportedGuardrailIntegrations.AZURE_PROMPT_SHIELD.value: azure_content_safety_prompt_shield_fields,
+ SupportedGuardrailIntegrations.AZURE_TEXT_MODERATIONS.value: azure_content_safety_text_moderation_fields,
}
return provider_params
diff --git a/litellm/types/guardrails.py b/litellm/types/guardrails.py
index 742dcf82b5a..96dc572ac32 100644
--- a/litellm/types/guardrails.py
+++ b/litellm/types/guardrails.py
@@ -339,6 +339,59 @@ class LassoGuardrailConfigModel(BaseModel):
)
+class AzureContentSafetyConfigModel(BaseModel):
+ """Configuration parameters for the Azure Content Safety Prompt Shield guardrail"""
+
+ api_key: Optional[str] = Field(
+ default=None,
+ description="API key for the Azure Content Safety Prompt Shield guardrail",
+ )
+
+ api_base: Optional[str] = Field(
+ default=None,
+ description="Base URL for the Azure Content Safety Prompt Shield guardrail",
+ )
+ api_version: Optional[str] = Field(
+ default=None,
+ description="API version for the Azure Content Safety Prompt Shield guardrail",
+ )
+
+
+class AzureContentSafetyPromptShieldConfigModel(AzureContentSafetyConfigModel):
+ """Configuration parameters for the Azure Content Safety Prompt Shield guardrail"""
+
+ pass
+
+
+class AzureContentSafetyTextModerationConfigModel(AzureContentSafetyConfigModel):
+
+ severity_threshold: Optional[int] = Field(
+ default=None,
+ description="Severity threshold for the Azure Content Safety Text Moderation guardrail across all categories",
+ )
+ severity_threshold_by_category: Optional[Dict[str, int]] = Field(
+ default=None,
+ description="Severity threshold by category for the Azure Content Safety Text Moderation guardrail. See list of categories - https://learn.microsoft.com/en-us/azure/ai-services/content-safety/concepts/harm-categories?tabs=warning",
+ )
+
+ categories: Optional[List[str]] = Field(
+ default=None,
+ description="Categories to scan for the Azure Content Safety Text Moderation guardrail. See list of categories - https://learn.microsoft.com/en-us/azure/ai-services/content-safety/concepts/harm-categories?tabs=warning",
+ )
+ blocklistNames: Optional[List[str]] = Field(
+ default=None,
+ description="Blocklist names to scan for the Azure Content Safety Text Moderation guardrail. Learn more - https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-text",
+ )
+ haltOnBlocklistHit: Optional[bool] = Field(
+ default=None,
+ description="Whether to halt the request if a blocklist hit is detected",
+ )
+ outputType: Optional[Literal["FourSeverityLevels", "EightSeverityLevels"]] = Field(
+ default=None,
+ description="Output type for the Azure Content Safety Text Moderation guardrail. Learn more - https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-text",
+ )
+
+
class LitellmParams(
PresidioConfigModel,
BedrockGuardrailConfigModel,
diff --git a/ui/litellm-dashboard/src/components/guardrails/guardrail_info_helpers.tsx b/ui/litellm-dashboard/src/components/guardrails/guardrail_info_helpers.tsx
index a7121758b71..1f9669813eb 100644
--- a/ui/litellm-dashboard/src/components/guardrails/guardrail_info_helpers.tsx
+++ b/ui/litellm-dashboard/src/components/guardrails/guardrail_info_helpers.tsx
@@ -1,13 +1,17 @@
export enum GuardrailProviders {
PresidioPII = "Presidio PII",
Bedrock = "Bedrock Guardrail",
- Lakera = "Lakera"
+ Lakera = "Lakera",
+ AzureContentSafetyPromptShield = "Azure Content Safety Prompt Shield",
+ AzureContentSafetyTextModeration = "Azure Content Safety Text Moderation"
}
export const guardrail_provider_map: Record<string, string> = {
PresidioPII: "presidio",
Bedrock: "bedrock",
- Lakera: "lakera_v2"
+ Lakera: "lakera_v2",
+ AzureContentSafetyPromptShield: "azure/prompt_shield",
+ AzureContentSafetyTextModeration: "azure/text_moderations"
};
@@ -27,7 +31,9 @@ const asset_logos_folder = '../ui/assets/logos/';
export const guardrailLogoMap: Record<string, string> = {
[GuardrailProviders.PresidioPII]: `${asset_logos_folder}presidio.png`,
[GuardrailProviders.Bedrock]: `${asset_logos_folder}bedrock.svg`,
- [GuardrailProviders.Lakera]: `${asset_logos_folder}lakeraai.jpeg`
+ [GuardrailProviders.Lakera]: `${asset_logos_folder}lakeraai.jpeg`,
+ [GuardrailProviders.AzureContentSafetyPromptShield]: `${asset_logos_folder}presidio.png`,
+ [GuardrailProviders.AzureContentSafetyTextModeration]: `${asset_logos_folder}presidio.png`,
};
export const getGuardrailLogoAndName = (guardrailValue: string): { logo: string, displayName: string } => {