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
Metadata
Release files for promptsentry-sdk 1.4.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 | Actions |
|---|---|---|---|---|
| promptsentry_sdk-1.4.0.tar.gz | 18.9 kB | Without provenance | Details for promptsentry_sdk-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promptsentry_sdk-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for promptsentry_sdk-1.4.0-py3-none-any.whl |
Total release size: 36.3 kB
Release files / promptsentry_sdk-1.4.0.tar.gz
| Download URL | promptsentry_sdk-1.4.0.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05ba4b7e437f94af716b73a57b54c3e7940096f6da231139ae26120ae8bcc3ba
|
|
BLAKE2b-256 checksum How to use checksums |
eff61ee887a80f476fa1aa540e36a1c79a675e025ce41bf539b72cd389e95b37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.4
|
Release files / promptsentry_sdk-1.4.0-py3-none-any.whl
| Download URL | promptsentry_sdk-1.4.0-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ebbcdd5f3804ed5f4fb549d47ce5af74b393459b2571a9a8c6dc86b850560fa1
|
|
BLAKE2b-256 checksum How to use checksums |
df58a408ef311dadd058c35414f39afce3529f6ed11e9c4fcb96df098d6e869f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.4
|
Security for promptsentry-sdk 1.4.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.