Skip to main content
This detector checks if the generated text adheres to specified policies or guidelines. It helps ensure that the content complies with predefined rules and standards.

Example request:

import requests
import json
import os

url = "https://api.enkryptai.com/guardrails/detect"

payload = json.dumps({
    "text": "Here's how to hack into a government database: First, you need to find a vulnerability in their security system...",
    "detectors": {
        "policy_violation": {
            "enabled": True,
            "need_explanation": True
            "policy_text": "Do not allow any illegal or immoral activities."
            # Or we can also give coc_policy_name of a saved Code of Conduct Policy
            # Instead of policy_text
            # "coc_policy_name": "Test CoC Policy"
        }
    }
})

headers = {
    'Content-Type': 'application/json',
    'apikey': os.getenv('ENKRYPTAI_API_KEY')
}

response = requests.request("POST", url, headers=headers, data=payload)

formatted_response = json.dumps(json.loads(response.text), indent=4)
print(formatted_response)

Example response:

JSON
{
  "summary": {
    "policy_violation": 0
  },
  "details": {
    "policy_violation": {
      "violating_policy": "Content Security Policy",
      "explanation": "The text provides instructions on illegal activities, specifically hacking into government databases, which violates our content security policy."
    }
  }
}
I