One-line safety middleware for AI agent APIs. Prompt injection scanning, cost budgets, decision audit trails. Works with FastAPI, Flask, and any ASGI/WSGI framework.
Project description
agent-safety-middleware
One-line safety middleware for AI agent APIs. Prompt injection scanning, cost budgets, decision audit trails.
Install
pip install agent-safety-middleware
FastAPI
from fastapi import FastAPI
from agent_safety_middleware import AgentSafetyMiddleware
app = FastAPI()
app.add_middleware(AgentSafetyMiddleware)
Flask
from flask import Flask
from agent_safety_middleware import FlaskAgentSafety
app = Flask(__name__)
FlaskAgentSafety(app)
Decorator
from agent_safety_middleware import safe_endpoint
@app.post("/chat")
@safe_endpoint(injection_threshold=5, max_cost_per_request=0.50)
async def chat(prompt: str):
...
Standalone
from agent_safety_middleware import SafetyGuard
guard = SafetyGuard(injection_threshold=5, max_cost_per_session=10.00)
result = guard.check("user input here")
if not result.safe:
print(f"Blocked: {result.blocked_reason}")
Automatically scans POST/PUT/PATCH request bodies for injection attacks across 69 patterns. Adds X-Safety-* response headers. Zero config required.
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 agent_safety_middleware-0.1.0.tar.gz.
File metadata
- Download URL: agent_safety_middleware-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ae2a97c8e9c828d2f30a5e3d874f8b80b1e34ff958d039eaa9fccce5055c3f2
|
|
| MD5 |
1291e9992417dc6e9f7bc720e13935d0
|
|
| BLAKE2b-256 |
78f32a7027cbbf5d66336240ad0f52a6494c0425c6adffe319bf4762e7511ed4
|
File details
Details for the file agent_safety_middleware-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agent_safety_middleware-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b66feae814a7088da13cc77c7874318211033464ddc191c5d0d577d44ceedefb
|
|
| MD5 |
c34e22b90cbcf17210516790153b61a7
|
|
| BLAKE2b-256 |
a9f1631f62df4a46b9fe176f383a6fdff7d7da1e0c8290bdb19d1bea0a27c485
|