Skip to main content

F.A.I.L. Kit - Forensic Audit of Intelligent Logic - FastAPI middleware

Project description

F.A.I.L. Kit - FastAPI Middleware

PyPI version

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 actions
  • action_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fail_kit-1.5.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fail_kit-1.5.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file fail_kit-1.5.1.tar.gz.

File metadata

  • Download URL: fail_kit-1.5.1.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

Hashes for fail_kit-1.5.1.tar.gz
Algorithm Hash digest
SHA256 fc57227f5d8c5d55ead1440be1f7b0125ad083286c472a7082049edc0afb3bc3
MD5 5322e5fd97324d63408de0ff6c79a13b
BLAKE2b-256 d4c6935552c3d9f418398728794256b4d609c4fc26ed0a09634fe8306ebed6e8

See more details on using hashes here.

File details

Details for the file fail_kit-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: fail_kit-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for fail_kit-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c18a9b2a543f5aa5f10fd09ee5554010549522579f5ba44c04cd7a3786ef180e
MD5 50849b0e4cde49668977680a1ce9f1b8
BLAKE2b-256 43234cb5dab69f838f0309d552bd94eda80b53be54069dd6598a633ab80f6753

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page