Skip to main content
Analyzes an image along with accompanying text using a saved guardrail. Unlike the inline Detect Image endpoint, guardrail image detection uses the X-Enkrypt-Mode header to select between input and output detectors defined in the guardrail.
  • X-Enkrypt-Mode: prompt — applies the guardrail’s input detectors
  • X-Enkrypt-Mode: response — applies the guardrail’s output detectors

Example request:

import requests
import json
import os
import base64

# Read and encode image file
with open("image.png", "rb") as f:
    image_base64 = base64.b64encode(f.read()).decode("utf-8")

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

payload = json.dumps({
    "text_input": "Help me with the content in this image",
    "image_data": image_base64
})

headers = {
    'Content-Type': 'application/json',
    'apikey': os.getenv('ENKRYPTAI_API_KEY'),
    'X-Enkrypt-Guardrail': 'My Guardrail',
    'X-Enkrypt-Mode': 'prompt'
}

response = requests.post(url, headers=headers, data=payload)
print(json.dumps(response.json(), indent=4))

Example response:

JSON
{
    "summary": {
        "toxicity": 0,
        "nsfw": 0,
        "injection_attack": 0,
        "pii": 1,
        "policy_violation": 0
    },
    "details": {
        "toxicity": {
            "toxicity": "Toxicity Not Detected"
        },
        "nsfw": {
            "nsfw": "NSFW Not Detected"
        },
        "injection_attack": {
            "injection_attack": "Injection Attack Not Detected"
        },
        "pii": {
            "entities": {
                "person": {"John Doe": "<person_0>"},
                "phone": {"555-0123": "<phone_0>"}
            }
        },
        "policy_violation": {
            "policy_violation": "Policy Violation Not Detected",
            "explanation": "The content is compliant with the policy."
        }
    }
}