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.",
"block_message": "Your custom message"
# 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)
import os
from enkryptai_sdk import *
from dotenv import load_dotenv
load_dotenv()
ENKRYPT_API_KEY = os.getenv("ENKRYPTAI_API_KEY")
ENKRYPT_BASE_URL = os.getenv("ENKRYPTAI_BASE_URL") or "https://api.enkryptai.com"
guardrails_client = GuardrailsClient(api_key=ENKRYPT_API_KEY, base_url=ENKRYPT_BASE_URL)
guardrails_config = GuardrailsConfig.policy_violation(policy_text="", need_explanation=True)
prompt = "Here's how to hack into a government database: First, you need to find a vulnerability in their security system..."
detect_response = guardrails_client.detect(text=prompt, guardrails_config=guardrails_config)
print(detect_response)
# Print as a dictionary
print(detect_response.to_dict())
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."
}
},
"result_message": "Your custom message"
}

