Implementation:BerriAI Litellm Policy Templates Backup
Template:Implementation metadata
Overview
Description
The litellm/policy_templates_backup.json file is a local backup copy of the primary policy templates file (policy_templates.json at the repository root). It is bundled within the LiteLLM Python package and used as a fallback by the proxy server's policy management endpoints when the remote GitHub-hosted version cannot be fetched.
Policy templates are pre-configured combinations of guardrails designed to address common security and compliance requirements. Each template bundles multiple guardrail definitions (PII protection, NSFW content filtering, credential blocking, etc.) into a single deployable policy. The templates are displayed in the LiteLLM Proxy UI to enable one-click policy deployment.
Usage
This file is loaded by the _load_policy_templates_from_local_backup() function in litellm/proxy/management_endpoints/policy_endpoints.py. It is used in two scenarios:
- When the environment variable
LITELLM_LOCAL_POLICY_TEMPLATES=trueis set - When fetching from GitHub fails (network error, non-200 response, etc.)
# Loading path:
# litellm/proxy/management_endpoints/policy_endpoints.py
backup_path = os.path.join(
os.path.dirname(__file__), "..", "..", "policy_templates_backup.json"
)
with open(path, "r") as f:
return json.load(f)
Data Schema
Top-Level Structure
The file is a JSON array of policy template objects.
[
{
"id": "advanced-au-pii-protection",
"title": "Advanced PII Protection (Australia)",
"description": "...",
"icon": "ShieldCheckIcon",
"iconColor": "text-purple-500",
"iconBg": "bg-purple-50",
"guardrails": ["au-pii-tax-identifiers", ...],
"complexity": "High",
"guardrailDefinitions": [ ... ],
"templateData": { ... }
},
...
]
Schema Fields
Policy Template Object
| Field | Type | Required | Description |
|---|---|---|---|
id |
String | Yes | Unique identifier for the template (e.g., "advanced-au-pii-protection")
|
title |
String | Yes | Human-readable display title for the UI |
description |
String | Yes | Detailed description of what the template protects against |
icon |
String | Yes | Icon component name for UI rendering (e.g., "ShieldCheckIcon", "ShieldExclamationIcon")
|
iconColor |
String | Yes | Tailwind CSS color class for the icon (e.g., "text-purple-500")
|
iconBg |
String | Yes | Tailwind CSS background class for the icon container (e.g., "bg-purple-50")
|
guardrails |
Array[String] | Yes | List of guardrail names included in this template |
complexity |
String | Yes | Complexity level: "Low", "Medium", or "High"
|
guardrailDefinitions |
Array[Object] | Yes | Full guardrail configuration objects for each guardrail |
templateData |
Object | Yes | Data used to create the policy when the template is applied |
Guardrail Definition Object
Each entry in guardrailDefinitions defines a single guardrail:
| Field | Type | Description |
|---|---|---|
guardrail_name |
String | Unique name of the guardrail (e.g., "au-pii-tax-identifiers")
|
litellm_params |
Object | LiteLLM configuration parameters for the guardrail |
guardrail_info |
Object | Metadata about the guardrail |
litellm_params Object
| Field | Type | Description |
|---|---|---|
guardrail |
String | Guardrail engine (always "litellm_content_filter" in templates)
|
mode |
String | When the guardrail runs: "pre_call" (before LLM call) or "post_call"
|
patterns |
Array[Object] | Pattern matching rules (for PII-type guardrails) |
categories |
Array[Object] | Category matching rules (for content filter-type guardrails) |
pattern_redaction_format |
String | Format string for redacted content (e.g., "[{pattern_name}_REDACTED]")
|
Pattern Object
| Field | Type | Description |
|---|---|---|
pattern_type |
String | Type of pattern: "prebuilt" (built-in recognizer) or "custom"
|
pattern_name |
String | Name of the pattern (e.g., "us_ssn", "email", "visa", "aws_access_key")
|
action |
String | Action to take on match: "MASK" (redact the data) or "BLOCK" (reject the request)
|
templateData Object
| Field | Type | Description |
|---|---|---|
policy_name |
String | Name for the created policy |
description |
String | Description for the created policy |
guardrails_add |
Array[String] | Guardrails to add when applying the template |
guardrails_remove |
Array[String] | Guardrails to remove (typically empty) |
Known Templates
| Template ID | Complexity | Description |
|---|---|---|
advanced-au-pii-protection |
High | Australian PII, international identifiers, financial data, credentials, protected class information |
baseline-pii-protection |
Low | Minimal protection focused on credentials and high-risk identifiers only |
nsfw-content-filter-australia |
Medium | Profanity, sexual content, self-harm, child safety violations with Australian-specific patterns |
Prebuilt Pattern Types
The templates reference numerous prebuilt patterns:
PII Identifiers: us_ssn, us_ssn_no_dash, au_tfn, au_abn, au_medicare, br_cpf, br_rg, br_cnpj, nl_bsn_contextual
Passports: passport_us, passport_uk, passport_germany, passport_france, passport_netherlands, passport_china, passport_india, passport_japan, passport_canada, passport_australia
Contact Information: email, us_phone, br_phone_landline, br_phone_mobile, street_address, br_cep
Financial: visa, mastercard, amex, discover, credit_card, iban
Credentials: aws_access_key, aws_secret_key, github_token, slack_token, generic_api_key
Infrastructure: ipv4, ipv6
Protected Classes: gender_sexual_orientation, race_ethnicity_national_origin, religion, age_discrimination, disability, marital_family_status, military_status, public_assistance
Usage Examples
How Templates are Served via the API
# From litellm/proxy/management_endpoints/policy_endpoints.py:
POLICY_TEMPLATES_GITHUB_URL = (
"https://raw.githubusercontent.com/BerriAI/litellm/main/policy_templates.json"
)
@router.get("/policy/templates", tags=["policy management"])
async def get_policy_templates(request: Request, ...):
"""
Fetches from GitHub with automatic fallback to local backup on failure.
Set LITELLM_LOCAL_POLICY_TEMPLATES=true to skip GitHub and use local backup only.
"""
use_local = os.getenv("LITELLM_LOCAL_POLICY_TEMPLATES", "").strip().lower() in (
"true", "1", "yes"
)
if use_local:
return _load_policy_templates_from_local_backup()
try:
response = await async_client.get(POLICY_TEMPLATES_GITHUB_URL)
if response.status_code == 200:
return response.json()
except Exception:
pass
return _load_policy_templates_from_local_backup()
Related Pages
- Policy Templates - The primary root-level version of this file
- Callback Configs - Related configuration for callback integrations