Skip to main content

trustloop

Python SDK for TrustLoop — governance, audit trail, and kill-switch for AI agents.

Intercept every tool call your agent makes. Log it. Block dangerous actions. Require human approval. Works with LangChain, CrewAI, AutoGen, or any custom Python agent.

Install

pip install trustloop

With async support:

pip install trustloop[async]

With LangChain integration:

pip install trustloop[langchain]

With CrewAI integration:

pip install trustloop[crewai]

Everything:

pip install trustloop[all]

Quick start

Get your free API key at trustloop.live/signup.

from trustloop import TrustLoop

tl = TrustLoop(api_key="tl_your_key_here", agent_name="my-agent")

# Check before running any tool
result = tl.intercept("send_email", {"to": "ceo@bank.com", "body": "..."})
if not result["allowed"]:
    raise RuntimeError(result["message"])

# ... run the tool

Or set your key as an env var and let the SDK find it:

export TRUSTLOOP_API_KEY="tl_your_key_here"
export TRUSTLOOP_AGENT_NAME="my-agent"
tl = TrustLoop()  # reads from env

Usage

Manual intercept

result = tl.intercept("delete_database", {"table": "users"})

# result = {
#   "allowed": False,
#   "status": "BLOCKED",
#   "message": "Matched rule: block destructive database operations"
# }

Auto-raise on block

from trustloop import TrustLoop, TrustLoopBlockedError, TrustLoopPendingError

try:
    tl.intercept("transfer_funds", {"amount": 50000}, raise_if_blocked=True)
except TrustLoopBlockedError as e:
    print(f"Blocked: {e}")
except TrustLoopPendingError as e:
    print(f"Waiting for approval: {e.approval_id}")

@tl.guard() decorator

@tl.guard("send_email")
def send_email(to: str, subject: str, body: str):
    # Only runs if TrustLoop allows it
    ...

@tl.guard()  # uses function name as tool name
def delete_user(user_id: str):
    ...

Async

from trustloop import AsyncTrustLoop

async with AsyncTrustLoop(api_key="tl_...") as tl:
    await tl.intercept("post_tweet", {"text": "Hello world"}, raise_if_blocked=True)

    @tl.guard("send_email")
    async def send_email(to, subject, body):
        ...

LangChain

from trustloop import TrustLoop
from trustloop.integrations.langchain import wrap_tools

tl = TrustLoop(api_key="tl_...", agent_name="langchain-agent")

# Wrap all tools — one line, zero boilerplate
tools = wrap_tools([search_tool, email_tool, db_tool], tl)

agent = create_openai_tools_agent(llm, tools, prompt)

CrewAI

from trustloop import TrustLoop
from trustloop.integrations.crewai import governed_tool

tl = TrustLoop(api_key="tl_...", agent_name="crew-agent")

@governed_tool(tl)
class SendEmailTool(BaseTool):
    name = "send_email"
    description = "Send an email"

    def _run(self, to: str, subject: str, body: str) -> str:
        ...  # only runs if TrustLoop allows it

Governance rules

# Create a rule in plain English
tl.create_rule(
    "Any wire transfer over £10,000 requires human approval",
    action="approve",
    approver_email="cfo@mycompany.com",
)

# Block a tool instantly (kill-switch)
tl.block_tool("drop_table", reason="Emergency: DB ops disabled")

# Unblock
tl.unblock_tool("drop_table")

Audit log

# Get recent calls
logs = tl.get_logs(limit=100, status="BLOCKED")

# Export as CSV
csv = tl.export_logs()

# Stats
stats = tl.get_stats()
print(stats["total"], stats["blocked"])

Human approvals

# List pending
pending = tl.get_pending_approvals()

# Approve or deny programmatically
tl.decide(pending[0]["id"], "approved")

Context manager

with TrustLoop(api_key="tl_...") as tl:
    tl.intercept("my_tool", {...})
# connection closed automatically

MCP (Claude Desktop)

url = TrustLoop.mcp_url("tl_your_key")
# → "https://trustloop-production.up.railway.app/sse?api_key=tl_..."

Paste this into your claude_desktop_config.json:

{
  "mcpServers": {
    "trustloop": { "url": "<paste url here>" }
  }
}

Environment variables

Variable Description
TRUSTLOOP_API_KEY Your API key (avoids passing it in code)
TRUSTLOOP_AGENT_NAME Default agent name for all intercepts
TRUSTLOOP_BASE_URL Override API base URL (for on-prem deployments)

Links

License

MIT

Download files

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

Source Distribution

trustloop_sdk-1.0.1.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

trustloop_sdk-1.0.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file trustloop_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: trustloop_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for trustloop_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 064476fce9daa06d488354b5690cb0c3f07227fe955d42f92bd40b4a8d2a2393
MD5 a0f299d51b4c73b02d58eb6101afd638
BLAKE2b-256 a99ad06e295f21574fa39f6442041f3f74ee502a38828d97648f350f9b28a1dc

See more details on using hashes here.

File details

Details for the file trustloop_sdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: trustloop_sdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for trustloop_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01ca1b5e4efe1018a8a164e62cd1c39d1afb9008adcd460cf4bb961eed1acc45
MD5 6ec0ad5316385f8eb9f1fc616f4d8567
BLAKE2b-256 caaa5430ca03ee43a0c2ee6be896abc39cb45cfb005bb9dd86f541959c2105e1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

2 files

Supported by

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