Python SDK for the Prompt Defend AI Security API - 16-Layer Guardrail Protection
Project description
Prompt Defend Python SDK
The official Python SDK for the Prompt Defend AI Security API. Protect your AI applications with our 16-layer guardrail system.
Installation
pip install promptdefend
Quick Start
from promptdefend import PromptDefend
# Initialize the client with your API key
client = PromptDefend(api_key="your-api-key")
# Scan a prompt for security issues
result = client.scan("What is the weather today?")
if result.safe:
print("✅ Prompt is safe to process")
else:
print(f"⚠️ Warning: {result.reason}")
Features
- 🛡️ 16-Layer Protection - Comprehensive guardrail system
- 🔒 Prompt Injection Detection - Block jailbreak and injection attempts
- ⚡ Sub-millisecond Latency - Average response time ~0.7ms
- 🐍 Pythonic API - Clean, intuitive interface
- 🔧 Error Handling - Comprehensive exception classes
- 📦 Minimal Dependencies - Only requires
requests
Usage
Basic Usage
from promptdefend import PromptDefend
client = PromptDefend(api_key="your-api-key")
result = client.scan("Hello, how are you?")
print(result.safe) # True or False
print(result.reason) # Explanation string
print(result.details) # Full detection details
Using Context Manager
from promptdefend import PromptDefend
with PromptDefend(api_key="your-api-key") as client:
result = client.scan("Tell me a joke")
print(result.to_dict())
Quick Scan Function
For one-off scans without creating a client instance:
from promptdefend import scan
result = scan(api_key="your-api-key", prompt_text="What is 2+2?")
print(result.safe)
Custom Configuration
from promptdefend import PromptDefend
client = PromptDefend(
api_key="your-api-key",
base_url="https://api.promptdefend.dev", # Optional custom endpoint
timeout=60 # Custom timeout in seconds
)
Error Handling
The SDK provides specific exception classes for different error types:
from promptdefend import (
PromptDefend,
PromptDefendError,
AuthenticationError,
NetworkError,
APIError
)
client = PromptDefend(api_key="your-api-key")
try:
result = client.scan("Test prompt")
except AuthenticationError as e:
print(f"Invalid API key: {e}")
except NetworkError as e:
print(f"Network issue: {e}")
except APIError as e:
print(f"API error (status {e.status_code}): {e}")
except PromptDefendError as e:
print(f"General error: {e}")
Response Object
The scan() method returns a ScanResult object with the following properties:
| Property | Type | Description |
|---|---|---|
safe |
bool |
Whether the prompt is safe to process |
reason |
str |
Explanation of the safety assessment |
details |
dict |
Full detection details from all 16 layers |
fast_path |
bool |
Whether allowlist short-circuit was used |
Methods
to_dict()- Convert the result to a dictionary
API Reference
PromptDefend Class
Constructor
PromptDefend(
api_key: str, # Required: Your API key
base_url: str = None, # Optional: Custom API base URL
timeout: int = 30 # Optional: Request timeout in seconds
)
Methods
| Method | Description |
|---|---|
scan(prompt_text: str) |
Scan a prompt and return a ScanResult |
close() |
Close the HTTP session |
Requirements
- Python 3.8+
requestslibrary
License
This SDK is proprietary software. See LICENSE for details.
Support
© 2026 Prompt Defend. All Rights Reserved.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptdefend-1.0.0.tar.gz.
File metadata
- Download URL: promptdefend-1.0.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a76a3019a09bce2a7a7a60d1c1897e810771cfc2f5dadb1a0729adc43b4aaecb
|
|
| MD5 |
48fcb0c7e863ecb5507066c16cc0138c
|
|
| BLAKE2b-256 |
9a1e71b5bbeb6c37dd488d3d249a1059eea7c7ff2ece2d7610249cac692eb673
|
File details
Details for the file promptdefend-1.0.0-py3-none-any.whl.
File metadata
- Download URL: promptdefend-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08d03d2dff8efa252875a7c5cb674e8389959c6ee351cf83f983062e2545e974
|
|
| MD5 |
9181948662d4e905edcba6693c56c433
|
|
| BLAKE2b-256 |
1d5f6294657555737eb192e925c77fcf8f47284f52338daaa8f67fae328ddd26
|