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-sdk
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]"
context = memories["formatted_context"]
## Async Support
```python
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
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-1.2.0.tar.gz.
File metadata
- Download URL: promptguard_sdk-1.2.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cdf9bee7fbd776d1fb50c462615f0d40548b09c570f43400c4513309b74e605
|
|
| MD5 |
c8687c262494f9c351b6fee7c5402a68
|
|
| BLAKE2b-256 |
67c5fc4e99df33ff25a6e8992e232331ff3aa0cb437b9766ddc409cd31091b97
|
Provenance
The following attestation bundles were made for promptguard_sdk-1.2.0.tar.gz:
Publisher:
publish-sdks.yml on acebot712/promptguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
promptguard_sdk-1.2.0.tar.gz -
Subject digest:
0cdf9bee7fbd776d1fb50c462615f0d40548b09c570f43400c4513309b74e605 - Sigstore transparency entry: 798251492
- Sigstore integration time:
-
Permalink:
acebot712/promptguard@1657e353b68ecd01a255bed867a5d5a5eabf48aa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/acebot712
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@1657e353b68ecd01a255bed867a5d5a5eabf48aa -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file promptguard_sdk-1.2.0-py3-none-any.whl.
File metadata
- Download URL: promptguard_sdk-1.2.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4efd732a1d88e90c03a38b5c949f8a3e62cdf656e26ffde0fb735ccfa6fd1e17
|
|
| MD5 |
5f981fc2fa7af342b8455d6e525fc10e
|
|
| BLAKE2b-256 |
2b88bdcccc16f56c63dc4d2911ca123ca9ee228f94cb9431a452349e04f42e3e
|
Provenance
The following attestation bundles were made for promptguard_sdk-1.2.0-py3-none-any.whl:
Publisher:
publish-sdks.yml on acebot712/promptguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
promptguard_sdk-1.2.0-py3-none-any.whl -
Subject digest:
4efd732a1d88e90c03a38b5c949f8a3e62cdf656e26ffde0fb735ccfa6fd1e17 - Sigstore transparency entry: 798251497
- Sigstore integration time:
-
Permalink:
acebot712/promptguard@1657e353b68ecd01a255bed867a5d5a5eabf48aa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/acebot712
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@1657e353b68ecd01a255bed867a5d5a5eabf48aa -
Trigger Event:
workflow_dispatch
-
Statement type: