F.A.I.L. Kit - Forensic Audit of Intelligent Logic - FastAPI middleware
Project description
F.A.I.L. Kit - FastAPI Middleware
Zero-config FastAPI middleware for AI agent auditing.
Installation
pip install fail-kit
Quick Start
from fastapi import FastAPI
from fail_kit import fail_audit
app = FastAPI()
@app.post("/eval/run")
@fail_audit(auto_receipts=True)
async def evaluate(prompt: str, context: dict):
# Your agent logic here
result = await your_agent(prompt)
return {
"response": result["text"],
"actions": result["actions"],
"receipts": result["receipts"]
}
Then run the audit:
pip install fail-kit-cli # Or: npm install -g @fail-kit/cli
fail-audit scan
fail-audit run --format html
Usage
With Actions and Receipts
from fail_kit import fail_audit, FailAuditAction
from datetime import datetime
@app.post("/eval/run")
@fail_audit(auto_receipts=True)
async def evaluate(prompt: str, context: dict):
# Create an action
action = FailAuditAction(
tool="database_query",
input=prompt,
output="Query result",
status="success",
latency_ms=45
)
return {
"response": "Here's what I found...",
"actions": [action.to_dict()],
}
# Receipts are auto-generated!
Simple Text Response
from fail_kit import fail_audit_simple
@app.post("/eval/run")
@fail_audit_simple
async def evaluate(prompt: str, context: dict):
return f"Answer to: {prompt}"
With Escalation
from fail_kit import fail_audit
@app.post("/eval/run")
@fail_audit(auto_receipts=True)
async def evaluate(prompt: str, context: dict):
if "delete" in prompt.lower():
return {
"response": "This requires human approval.",
"actions": [],
"policy": {
"escalate": True,
"reasons": ["high-stakes operation"]
}
}
return {"response": "Done!", "actions": []}
API Reference
@fail_audit(auto_receipts=True, action_logger=None)
Decorator for agent endpoints.
auto_receipts: Automatically generate receipts from actionsaction_logger: Optional async function to log actions
@fail_audit_simple
Simple decorator for text-only agents.
FailAuditAction
Helper class for creating actions:
action = FailAuditAction(
tool="tool_name",
input="input data",
output="output data",
status="success", # or "failed"
latency_ms=100
)
FailAuditReceipt
Helper class for creating receipts:
receipt = FailAuditReceipt(
tool="tool_name",
status="success",
proof="Proof of execution"
)
Links
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 fail_kit_fastapi-2.0.0.tar.gz.
File metadata
- Download URL: fail_kit_fastapi-2.0.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2bed4e1207c7ac4c396779c55828d9eed170637cebff8fb8cec898ec19c67ce
|
|
| MD5 |
88372beb74c32f47ab0978e19f707cef
|
|
| BLAKE2b-256 |
92d2ba97bd6c4d9d9c6319160dec7efd431dd5fa57aa940ce8b121de26003e6c
|
File details
Details for the file fail_kit_fastapi-2.0.0-py3-none-any.whl.
File metadata
- Download URL: fail_kit_fastapi-2.0.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e03606822e46ba5df850d1df3cfd66bbc70879cc48df74c4bdae6cfe487bb22
|
|
| MD5 |
6c4e67e4015e8be2ed2d3bfac5e44049
|
|
| BLAKE2b-256 |
f37025b489f740dab14e746d26cf67be9e3b2b44bd4dac19bcca3444a0f1cbaf
|