Runtime authorization middleware for AI agent tool calls: policy checks, injection/taint detectors, and a hash-chained audit log, before any action executes.
pip install guardrail-middleware Copy PIP instructions
Runtime authorization for AI agent tool calls. GuardRail sits between an AI agent and its tools: every proposed action is checked against a policy before it executes, and every decision is written to a tamper-evident audit log.
An agent that can call tools can also be talked into misusing them: by a prompt injection in an email, a poisoned webpage, or its own overconfidence. GuardRail is the checkpoint that asks, deterministically and in under a millisecond: is this role allowed to do this, to this resource, with these parameters, on the say-so of this source?
Tool names work as-is, too. If an action names only a tool, GuardRail classifies it from the name: send_payment, stripe_refund, delete_user and get_order_status are all understood (params is accepted as an alias for parameters, source_type for triggered_by).
from fastapi import FastAPI from guardrail_middleware import Guardrail, AuditLog from guardrail_middleware.fastapi import GuardrailMiddleware app = FastAPI() app.add_middleware( GuardrailMiddleware, guard=Guardrail(audit_log=AuditLog("audit.jsonl")), paths=["/tools/execute"], ) Requests to guarded paths are read as actions. Blocked or escalated actions never reach your handler. The client gets HTTP 403 with the full decision as JSON. Allowed actions pass through with X-Guardrail-Verdict and X-Guardrail-Risk headers set.
from guardrail_middleware.fastapi import guard_tool, GuardrailBlocked @guard_tool(guard, tool="payments", operation="payment", agent_role="support") def send_payment(amount: int, to: str): ... # only runs if GuardRail approves try: send_payment(amount=42_000, to="vendor/acme") except GuardrailBlocked as stopped: print(stopped.decision.explanation) Verdicts Verdict Meaning APPROVE No policy issues. Execute. APPROVE_WITH_CONDITIONS Execute only with the attached conditions (batch it, back up first, dry-run). ESCALATE_TO_HUMAN A person must approve first (over-limit payment, untrusted source, unbounded delete). BLOCK Never execute (injection, unauthorized role, PII exfiltration, hard money ceiling). Priority is fail-safe: any block finding wins, then escalate, then conditions.
No LLM in the decision path: the same action under the same policy always gets the same verdict, reproducibly and fast.
Every threshold lives in one policy dict. Tune it without touching code, or load it from YAML:
from guardrail_middleware import Guardrail, Policy policy = Policy.from_yaml("policy.yaml") # see policy.example.yaml guard = Guardrail(policy=policy) # …or inline guard = Guardrail(policy={"approval_limits": {"payment": {"auto_approve_max": 500}}}) Audit log Pass an AuditLog and every decision is appended as one JSON line, hash-chained with SHA-256: each entry commits to the previous entry's hash, so editing, deleting, or reordering history breaks the chain.
from guardrail_middleware import AuditLog AuditLog("audit.jsonl").verify() # {'ok': True, 'entries': 128, 'broken_at': None} Demo & tests python examples/demo.py # 5 scenarios, all four verdicts, audit verification pytest # 20 tests: engine, detectors, middleware, decorator, audit tampering Where this comes from guardrail-middleware is the reusable enforcement core extracted from GuardRail, a runtime action-authorization and behavioral-safety layer for agentic AI built at Infosys Ignite EngNext 2026 (special recognition), where the full system adds multi-step plan validation, an action-passport execution gateway, and a 42-scenario adversarial red-team benchmark. It packages the single-action checkpoint from that system so any agent stack can adopt it in minutes.
Both files in this release have provenance metadata.
ai-agents guardrails llm-security middleware fastapi authorization
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Both files in this release have been uploaded with provenance metadata.
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.




