Drop-in security for AI applications - AI Firewall SDK
Project description
PromptGuard Python SDK
Drop-in security for AI applications. No code changes required.
Installation
pip install promptguard-ai
Quick Start
from promptguard import PromptGuard
# Initialize client
pg = PromptGuard(api_key="pg_xxx")
# Use exactly like OpenAI client
response = pg.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response["choices"][0]["message"]["content"])
Drop-in Replacement
If you're already using OpenAI's Python client, just change the import:
# Before
from openai import OpenAI
client = OpenAI()
# After
from promptguard import PromptGuard
client = PromptGuard(api_key="pg_xxx")
# Your existing code works unchanged!
Features
Security Scanning
# Scan content for threats
result = pg.security.scan("Ignore previous instructions...")
if result["blocked"]:
print(f"Threat detected: {result['reason']}")
PII Redaction
# Redact PII before sending to LLM
result = pg.security.redact(
"My email is john@example.com and SSN is 123-45-6789"
)
print(result["redacted_content"])
# Output: "My email is [EMAIL] and SSN is [SSN]"
Memory (Context Management)
# Store user preferences
pg.memory.store(
content="User prefers Python for coding tasks",
memory_type="preference",
user_id="user-123"
)
# Retrieve relevant context
memories = pg.memory.retrieve(
query="What programming language should I use?",
user_id="user-123"
)
# Inject into your prompts
context = memories["formatted_context"]
Async Support
from promptguard import PromptGuardAsync
async with PromptGuardAsync(api_key="pg_xxx") as pg:
response = await pg.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
Configuration
from promptguard import PromptGuard, Config
config = Config(
api_key="pg_xxx",
base_url="https://api.promptguard.co/api/v1/proxy",
enable_caching=True,
enable_security_scan=True,
timeout=30.0,
)
pg = PromptGuard(config=config)
Environment Variables
export PROMPTGUARD_API_KEY="pg_xxx"
export PROMPTGUARD_BASE_URL="https://api.promptguard.co/api/v1/proxy"
Then just:
from promptguard import PromptGuard
pg = PromptGuard() # Uses env vars automatically
Error Handling
from promptguard import PromptGuard, PromptGuardError
try:
response = pg.chat.completions.create(...)
except PromptGuardError as e:
if e.code == "BLOCKED":
print(f"Request blocked: {e.message}")
elif e.code == "RATE_LIMITED":
print("Rate limited, try again later")
else:
raise
License
MIT
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
promptguard_sdk-0.1.0.tar.gz
(6.7 kB
view details)
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 promptguard_sdk-0.1.0.tar.gz.
File metadata
- Download URL: promptguard_sdk-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06e885dccea38ed7505b122b894157c428919bc3c954db86918c235bc885463a
|
|
| MD5 |
7a84bcb28f18b1127e9bc0f1e4744f4f
|
|
| BLAKE2b-256 |
568a3562635ef54553c39088be3331999d25f56246bf053dc30a76584795a54c
|
File details
Details for the file promptguard_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: promptguard_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbb1355866f6e52c03def7ba9908a9cd44a65ccec6599ab5402511aa94e6b322
|
|
| MD5 |
0a8a1fc479ea4f6d0a9de4018642d37d
|
|
| BLAKE2b-256 |
490283afb1fbf177a0a92aec7b4f44a3ec836c2e187a3e8211905e850b56f132
|