Skip to main content

Policy Templates API

Browse and apply pre-built policy templates for common governance scenarios through the Orchestrator API.

Overview

Policy templates provide ready-to-use policy configurations for:

  • Security: SQL injection, XSS, command injection prevention
  • Compliance: GDPR, HIPAA, PCI-DSS, SOC2
  • Regional: EU AI Act, RBI, SEBI (India), DPDP Act
  • Industry: Healthcare, Financial Services, E-commerce

Base URL: http://localhost:8081 (Orchestrator)

Authentication

All endpoints require:

  • Authorization: Basic base64(clientId:clientSecret) header
  • Content-Type: application/json header (for POST requests)

Optional:

  • X-Org-ID header — Scopes template usage stats to a specific tenant

Endpoints

GET /api/v1/templates

List available policy templates with optional filtering.

Request:

curl "http://localhost:8081/api/v1/templates?category=compliance&search=gdpr"

Query Parameters:

ParameterTypeDefaultDescription
categorystring(all)Filter by category (see Template Categories)
searchstring(none)Search template names and descriptions
tagsstring(none)Comma-separated tags to filter by
activeboolean(all)Filter by active status
builtinboolean(all)Filter by built-in templates
pageinteger1Page number
page_sizeinteger20 (max: 100)Items per page

Response (200 OK):

{
"templates": [
{
"id": "tpl_gdpr_pii",
"name": "gdpr-pii-protection",
"display_name": "GDPR PII Protection",
"description": "Comprehensive PII detection and blocking for GDPR compliance",
"category": "compliance",
"subcategory": "privacy",
"template": {},
"variables": [
{
"name": "action",
"type": "string",
"default": "block",
"description": "Action to take when PII is detected",
"required": false
}
],
"is_builtin": true,
"is_active": true,
"version": "2.1.0",
"tags": ["gdpr", "pii", "privacy", "eu"],
"created_at": "2024-06-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:00Z"
}
],
"pagination": {
"page": 1,
"page_size": 20,
"total_items": 45,
"total_pages": 3
}
}

GET /api/v1/templates/{id}

Get detailed information about a specific template.

Request:

curl http://localhost:8081/api/v1/templates/tpl_gdpr_pii

Response (200 OK):

{
"id": "tpl_gdpr_pii",
"name": "gdpr-pii-protection",
"display_name": "GDPR PII Protection",
"description": "Comprehensive PII detection and blocking for GDPR compliance. Includes detection patterns for EU-specific identifiers like IBAN, VAT numbers, and national IDs.",
"category": "compliance",
"subcategory": "privacy",
"template": {
"type": "content",
"conditions": [
{
"field": "query",
"operator": "regex",
"value": "{{pattern}}"
}
],
"actions": [
{
"type": "{{action}}",
"config": {}
}
]
},
"variables": [
{
"name": "pattern",
"type": "string",
"default": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
"description": "Regex pattern for PII detection",
"required": true,
"validation": "^[^\\s]+$"
},
{
"name": "action",
"type": "string",
"default": "block",
"description": "Action to take: block, redact, alert, log",
"required": false
}
],
"is_builtin": true,
"is_active": true,
"version": "2.1.0",
"tags": ["gdpr", "pii", "privacy", "eu"],
"created_at": "2024-06-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:00Z"
}

POST /api/v1/templates/{id}/apply

Apply a template to create policies for a tenant.

Request:

curl -X POST http://localhost:8081/api/v1/templates/tpl_gdpr_pii/apply \
-H "Content-Type: application/json" \
-H "X-Org-ID: my-tenant" \
-d '{
"variables": {
"pattern": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
"action": "block"
},
"policy_name": "gdpr-email-detection",
"description": "Block emails in prompts for GDPR compliance",
"enabled": true,
"priority": 100
}'

Request Body:

FieldTypeRequiredDescription
variablesobjectNoVariable values to substitute into the template
policy_namestringYesName for the created policy
descriptionstringNoDescription for the created policy
enabledbooleanYesWhether to enable the policy immediately
priorityintegerNoPolicy evaluation priority

Response (200 OK):

{
"success": true,
"policy": {
"id": "pol_abc123",
"name": "gdpr-email-detection",
"description": "Block emails in prompts for GDPR compliance",
"type": "content",
"category": "compliance",
"tier": "tenant",
"conditions": [
{
"field": "query",
"operator": "regex",
"value": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}"
}
],
"actions": [
{
"type": "block",
"config": {}
}
],
"priority": 100,
"enabled": true,
"version": 1,
"tenant_id": "my-tenant",
"created_at": "2025-01-02T10:00:00Z",
"updated_at": "2025-01-02T10:00:00Z"
},
"usage_id": "usage_xyz789",
"message": "Policy created from template tpl_gdpr_pii"
}

GET /api/v1/templates/categories

List all template categories with counts.

Request:

curl http://localhost:8081/api/v1/templates/categories

Response (200 OK):

Returns the list of valid template categories:

[
"general",
"security",
"compliance",
"content_safety",
"rate_limiting",
"access_control",
"data_protection",
"custom"
]

POST /api/v1/templates/{id}/apply - Error Responses

HTTP StatusScenarioExample Body
400Missing required variable{"error": {"code": "INVALID_CUSTOMIZATION", "message": "Required variable 'pattern' is missing"}}
404Template not found{"error": {"code": "TEMPLATE_NOT_FOUND", "message": "Template tpl_xyz not found"}}
409Policy name conflict{"error": {"code": "POLICIES_ALREADY_EXIST", "message": "Policy 'gdpr-email-detection' already exists"}}

GET /api/v1/templates/stats

Get template usage statistics.

Request:

curl http://localhost:8081/api/v1/templates/stats

Response (200 OK):

Returns usage statistics per template:

[
{
"template_id": "tpl_gdpr_pii",
"template_name": "gdpr-pii-protection",
"usage_count": 4523,
"last_used_at": "2025-01-02T10:00:00Z"
},
{
"template_id": "tpl_sqli_prevention",
"template_name": "sql-injection-prevention",
"usage_count": 3892,
"last_used_at": "2025-01-01T15:30:00Z"
}
]

Template Categories

CategoryDescription
generalGeneral-purpose policy templates
securityCore security patterns (SQLi, XSS, command injection)
complianceRegulatory compliance (GDPR, HIPAA, PCI-DSS)
content_safetyContent moderation and safety filters
rate_limitingRate limiting and usage controls
access_controlRole-based and attribute-based access policies
data_protectionData masking, redaction, and encryption policies
customUser-defined custom templates

Variable Types

TypeDescription
stringFree-form text value
integerWhole number
booleantrue or false
enumOne of a predefined set of values
arrayList of values

Error Responses

HTTP StatusError CodeDescription
400INVALID_CUSTOMIZATIONInvalid customization parameters or variable values
400VALIDATION_ERRORTemplate variable validation failed
404TEMPLATE_NOT_FOUNDTemplate does not exist
409POLICIES_ALREADY_EXISTPolicies with same names already exist
500INTERNAL_ERRORInternal server error

Example (404):

{
"error": {
"code": "TEMPLATE_NOT_FOUND",
"message": "Template 'tpl_invalid' does not exist"
}
}

Next Steps