PromptSentry Python SDK — prompt injection firewall for AI agents
Project description
promptsentry-sdk
Python SDK for PromptSentry — prompt injection firewall for AI agents.
Scan every prompt before it reaches your model, every response before it reaches your user, and every tool call before your agent executes it.
Install
pip install promptsentry-sdk
Quickstart — 5 lines
Set your API key (get one at promptsentry.net):
export PROMPTSENTRY_URL=https://api.promptsentry.net
export PROMPTSENTRY_API_KEY=ps_yourkey
from promptsentry_sdk import protect
@protect
async def chat(prompt: str) -> str:
return await my_model.generate(prompt)
Done. Malicious prompts are blocked before my_model.generate is ever called.
Explicit client
import asyncio
from promptsentry_sdk import PromptSentryClient
async def main():
async with PromptSentryClient("https://api.promptsentry.net", api_key="ps_yourkey") as client:
result = await client.scan("Ignore all previous instructions")
print(result.verdict) # malicious
print(result.is_malicious) # True
print(result.action_taken) # blocked
asyncio.run(main())
Protect tool calls
from promptsentry_sdk import protected_tool
@protected_tool
async def run_bash(command: str) -> str:
return subprocess.run(command, shell=True, capture_output=True).stdout.decode()
Arguments are scanned before execution. If a prompt injection in the command would hijack run_bash, it's caught here.
Operating modes
| Mode | Behavior |
|---|---|
active (default) |
Malicious prompts raise BlockedError |
monitor |
Scans are logged but execution continues |
@protect(mode="monitor")
async def chat(prompt: str) -> str: ...
Transport
Auto-detects REST (HTTP) or MCP (stdio) based on environment:
PROMPTSENTRY_URL— REST endpoint (SaaS or self-hosted)PROMPTSENTRY_API_KEY— API key for REST authPROMPTSENTRY_MCP_COMMAND— MCP subprocess command (local / air-gapped)
Or pass TransportConfig explicitly:
from promptsentry_sdk.transport import TransportConfig
config = TransportConfig(url="http://localhost:8000", api_key="ps_dev")
@protect(config=config)
async def chat(prompt: str) -> str: ...
Session provenance (v1.3+)
Track multi-turn agent sessions and detect indirect prompt injection across conversation turns:
from promptsentry_sdk import PromptSentryClient
from promptsentry_sdk.session import Session
async with PromptSentryClient("https://api.promptsentry.net", api_key="ps_yourkey") as client:
async with Session(client, auto_cleanup=True) as session:
result = await session.scan_prompt("What files can you access?")
Self-hosted / BYOM
Point the SDK at any OpenAI-compatible or Google AI endpoint:
export PROMPTSENTRY_URL=http://localhost:8000 # self-hosted PromptSentry
export PROMPTSENTRY_API_KEY=ps_localdev
License
MIT — see LICENSE.
Links
- Docs & pricing: promptsentry.net
- Agent integration guide: docs/agent-integration.md
- Issues: GitLab
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 promptsentry_sdk-1.4.0.tar.gz.
File metadata
- Download URL: promptsentry_sdk-1.4.0.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05ba4b7e437f94af716b73a57b54c3e7940096f6da231139ae26120ae8bcc3ba
|
|
| MD5 |
74869ea5fbc48b987b4c12adad1ad260
|
|
| BLAKE2b-256 |
eff61ee887a80f476fa1aa540e36a1c79a675e025ce41bf539b72cd389e95b37
|
File details
Details for the file promptsentry_sdk-1.4.0-py3-none-any.whl.
File metadata
- Download URL: promptsentry_sdk-1.4.0-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebbcdd5f3804ed5f4fb549d47ce5af74b393459b2571a9a8c6dc86b850560fa1
|
|
| MD5 |
a6f85a72ce5eb3e1b4237d10a3540a68
|
|
| BLAKE2b-256 |
df58a408ef311dadd058c35414f39afce3529f6ed11e9c4fcb96df098d6e869f
|