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.
Metadata
Release files for promptdefend 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| promptdefend-1.0.0.tar.gz | 6.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| promptdefend-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.2 kB
Release files / promptdefend-1.0.0.tar.gz
| Download URL | promptdefend-1.0.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a76a3019a09bce2a7a7a60d1c1897e810771cfc2f5dadb1a0729adc43b4aaecb
|
|
BLAKE2b-256 checksum How to use checksums |
9a1e71b5bbeb6c37dd488d3d249a1059eea7c7ff2ece2d7610249cac692eb673
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / promptdefend-1.0.0-py3-none-any.whl
| Download URL | promptdefend-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
08d03d2dff8efa252875a7c5cb674e8389959c6ee351cf83f983062e2545e974
|
|
BLAKE2b-256 checksum How to use checksums |
1d5f6294657555737eb192e925c77fcf8f47284f52338daaa8f67fae328ddd26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for promptdefend 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.