Skip to main content

Enkrypt AI Python SDK

A Python SDK with Guardrails, Code of Conduct Policies, Endpoints (Models), Deployments, AI Proxy, Datasets, Red Team, etc. functionality for API interactions. See https://pypi.org/project/enkryptai-sdk Also see the API documentation at https://docs.enkryptai.com

Table of Contents

Installation

Environment Variables

Set the following environment variables:
  • OPENAI_API_KEY: Your OpenAI API key
  • ENKRYPTAI_API_KEY: Your EnkryptAI API key
  • ENKRYPTAI_BASE_URL: The base URL for the EnkryptAI API

Helper functions for all response classes

to_dict

We can use the to_dict method to convert the response objects to dictionaries.
Python

Setup

Python

Sample Variables

Python

Sample Configurations

Sample Guardrails Detector Config

Python

Sample Model Config

Python

Sample Deployment Config

Python

Sample Dataset Config

Python

Sample Redteam Model Health Config (V3)

Python

Sample Redteam Target Config (V3)

Python

Sample Redteam Model Config (V3)

Python

Sample Redteam Risk Mitigation Guardrails Policy Config

Python

Sample Redteam Risk Mitigation System Prompt Config

Python

Health Checks

Guardrails Health

Python

Guardrails Status

Python

Guardrails Models Loaded

Python

Redteam Health

Python

Model Health (V3)

Python

Guardrails Quickstart

Python

Guardrails Response Objects

The SDK provides wrapper classes for API responses that provides additional functionality.

GuardrailsDetectResponse

The GuardrailsDetectResponse class wraps detect and policy_detect responses:
Python

GuardrailsBatchDetectResponse

The GuardrailsBatchDetectResponse class wraps batch_detect response:
Python

Available Guardrails Detectors

  • injection_attack: Detect prompt injection attempts
  • bias: Detect biased content
  • policy_violation: Check against custom policy rules
  • topic_detection: Detect specific topics
  • nsfw: Filter inappropriate content
  • toxicity: Detect toxic language
  • pii: Detect personal information
  • copyright_ip: Check for copyright/IP violations (Coming soon)
  • system_prompt: Detect system prompt leaks (Coming soon)
  • keyword_detector: Check for specific keywords
  • sponge_attack: Detect infinite loops
Each detector can be enabled/disabled and configured with specific options as documented in the API docs.

Guardrails Configs

Instead of using a dictionary to configure detectors directly, you can also use GuardrailsConfig to create configurations for each detector.

Injection Attack

Python

Policy Violation

Python

Toxicity

Python

NSFW

Python

Bias

Python

PII

Python

Topic Detection

Python

Keyword Detector

Python
  • (Coming soon)
Python

System Prompt

  • (Coming soon)
Python

Sponge Attack

Python

Detect with config

Python

Batch Detect

Batch detect threats in multiple texts.

Guardrail Management

Guardrails allow you to save and reuse detection configurations with separate input (prompt) and output (response) detector settings.

Create a Guardrail

Python

Get a Guardrail

Python

Modify a Guardrail

Python

Delete a Guardrail

Python

List Guardrails

Python

Detect Using a Guardrail

Use mode="prompt" for input detectors or mode="response" for output detectors.
Python

Batch Detect Using a Guardrail

Python

Detect Image Using a Guardrail

Use mode="prompt" for input detectors or mode="response" for output detectors.
Python

Detect Audio Using a Guardrail

Use mode="prompt" for input detectors or mode="response" for output detectors.
Python

Guardrails Policy Management (Legacy)

Legacy: The Policy Management API is legacy. Use the Guardrail Management section above for new integrations, which supports separate input/output detector configurations.
Policies allow you to save and reuse guardrails configurations.

Create a Policy

Python

Modify a Policy

Python

Get Policy Details

Python

List Policies

Python

Delete a Policy

Python

Use a Policy to Detect

Python

Batch Policy Detect

Batch detect threats in multiple texts using a specific policy.

Scan a URL with a Policy

Scan a URL using a specific saved policy.

Scan a PDF with a Policy

Scan a PDF file using a specific saved policy.

Detect Image with a Policy

Detect unsafe content in an image using a specific saved policy.

Detect Audio with a Policy

Detect unsafe content in audio using a specific saved policy.

Guardrails Evals

The Guardrails Client also provides functionality to evaluate LLM responses for scanning URLs, adherence to context, relevancy to questions and deetecting hallucinations.

Scan a URL for Threats

Scan a URL for security threats such as injection attacks and policy violations.

Scan a PDF for Threats

Scan a PDF file for security threats such as injection attacks and policy violations.

Check Context Adherence

Evaluate if an LLM’s response adheres to the provided context:
Python

Check Question Relevancy

Evaluate if an LLM’s response is relevant to the asked question:
Python

Check Hallucination

  • (Coming soon)
Detect hallucinations in an LLM’s response:
Python

Guardrails PII anonymization and de-anonymization

The Guardrails Client also provides functionality to redact and unredact PII in text.
Python

Code of Conduct Policies

Code of Conduct policies help enforce organizational guidelines and standards.

Atomize a Policy Document or Text

Python

Add a Code of Conduct Policy

Python

Get Code of Conduct Policy Details

Python

List Code of Conduct Policies

Python

Modify a Code of Conduct Policy

Python

Delete a Code of Conduct Policy

Python

Endpoints (Models)

Add a Model

Python

Saved Model Health

Python

Get Model Details

Python

List Models

Python

Modify a Model

Python

Delete a Model

Python

Deployments

Add a Deployment

Python

Get Deployment Details

Python

List Deployments

Python

Modify a Deployment

Python

Delete a Deployment

Python

AI Proxy with Deployments

We can proxy to the AI model configured in the deployment using the OpenAI SDK.
Python

Datasets

Datasets are used for red teaming evaluations. Instead of using “standard” dataset, you can create custom datasets and use them in red teaming evaluations.

Add a Dataset

Python

Get Dataset Details

Python

List Datasets

Python

Get Dataset Task Status

Python

Get Datacard

Python

Get Dataset Summary

Python

Redteam

Redteam evaluations are used to test models for security vulnerabilities.

Add a Redteam Custom Task with Endpoint Config (V3)

Python

Add a Redteam Custom Task with a saved model (V3)

Python

Get Redteam Task Status

Python

Get Redteam Task

Python

List Redteam Tasks

Python
Python

Get Redteam Task Results Summary

Python

Get Redteam Task Results Summary of Test Type

Python

Get Redteam Task Results Details

Python

Get Redteam Task Results Details of Test Type

Python

Get Redteam Findings

Python

Mitigate Risks with Guardrails Policy

Python

Mitigate Risks with System Prompt

Python
© 2025 Enkrypt AI. All rights reserved. Enkrypt AI software is provided under a proprietary license. Unauthorized use, reproduction, or distribution of this software or any portion of it is strictly prohibited. Terms of Use: https://www.enkryptai.com/terms-and-conditions Enkrypt AI and the Enkrypt AI logo are trademarks of Enkrypt AI, Inc.