ToolBoundary
Runtime boundary enforcement for AI agents — as a library, not a service.
ToolBoundary answers one question, fast and locally, every time your agent tries to call a tool: "is this exact call allowed, right now?"
No separate web app. No database to stand up. No dashboard to log into. No subscription. Your policy is plain Python, version-controlled with the rest of your code.
pip install toolboundary
Why this exists
Enterprise AI-governance platforms (agent registries, policy engines, approval dashboards) make sense when a large organization has dozens of AI agents built by different teams and needs a compliance layer to track all of them. That's real infrastructure for a real problem — but it's disproportionate for the much more common case: one developer or a small team building one to a handful of agents, who just need to make sure a tool-calling agent can't do something catastrophic.
ToolBoundary is built for that second case. It costs nothing, requires no infrastructure, and takes minutes to add to an existing agent.
Quickstart
from toolboundary import Boundary, ToolPermission, AutonomyLevel, AccessMode
boundary = Boundary(
agent_name="support-agent",
autonomy=AutonomyLevel.LIMITED_AUTONOMOUS,
permissions=[
ToolPermission("read_ticket_db", access_mode=AccessMode.READ_ONLY),
ToolPermission(
"send_reply_email",
access_mode=AccessMode.EXECUTE,
max_calls_per_hour=30,
),
],
blocked_operations=frozenset({"delete_ticket"}),
max_actions_per_hour=100,
kill_switch_env="TOOLBOUNDARY_KILL_SWITCH",
)
# Somewhere in your agent's tool-calling code:
boundary.check("read_ticket_db", access_mode=AccessMode.READ_ONLY) # passes silently
boundary.check("delete_ticket", operation="delete_ticket") # raises BoundaryViolation
If a call is denied, boundary.check(...) raises BoundaryViolation (or a more
specific subclass like KillSwitchActive or RateLimitExceeded). If a call needs a
human before it can proceed, it raises ApprovalRequired. Every decision — allow,
deny, or approval-required — is written to a structured audit log automatically.
Emergency stop
export TOOLBOUNDARY_KILL_SWITCH=1
Set the environment variable your Boundary was configured with, and every future
call for that agent is denied immediately — no restart required, no code change,
no separate dashboard to log into.
Two ways to enforce the boundary
1. Decorator (plain Python functions)
from toolboundary import guarded_tool, AccessMode
@guarded_tool(boundary, access_mode=AccessMode.EXECUTE, value_arg="amount")
def wire_transfer(account_id: str, amount: float) -> str:
return f"transferred {amount} to {account_id}"
wire_transfer(account_id="acct_1", amount=250_000)
# raises BoundaryViolation if 250_000 exceeds the permission's max_value —
# the function body never executes.
Once a function is decorated, calling it is calling through ToolBoundary. There is no code path to the real implementation that skips the check.
2. LangChain tools
from toolboundary.integrations.langchain import guard_tools
from toolboundary import AccessMode
guarded_tools = guard_tools(
[read_db_tool, send_email_tool, wire_transfer_tool],
boundary,
default_access_mode=AccessMode.READ_ONLY,
overrides={
"send_email_tool": {"access_mode": AccessMode.EXECUTE},
"wire_transfer_tool": {"access_mode": AccessMode.EXECUTE, "value_arg": "amount"},
},
)
agent_executor = AgentExecutor(agent=agent, tools=guarded_tools)
This wraps the LangChain BaseTool objects themselves — the objects your
AgentExecutor actually invokes when the LLM decides to call a tool — so the boundary
check runs inside LangChain's own tool-execution path, not as a step the agent's
reasoning loop has to remember to call.
Install with the LangChain extra: pip install toolboundary[langchain]
What a Boundary can enforce
| Control | Example |
|---|---|
| Which tools an agent may use at all | permissions=[ToolPermission("read_db", ...)] |
| Operation-level allow/block lists | blocked_operations=frozenset({"delete_customer"}) |
| Access mode (READ_ONLY / WRITE / EXECUTE / ADMIN) | access_mode=AccessMode.EXECUTE |
| Transaction value ceilings | ToolPermission(..., max_value=500_000) |
| Record-count ceilings | ToolPermission(..., max_records=100) |
| Rate limits (global or per-tool) | max_actions_per_hour=60 |
| Autonomy level | AutonomyLevel.RECOMMEND_ONLY / HUMAN_APPROVAL_REQUIRED / LIMITED_AUTONOMOUS / AUTONOMOUS / QUARANTINED |
| Time-bounded validity | valid_from=, valid_to= |
| Environment restriction | allowed_environments=frozenset({"DEV", "TEST"}) |
| Emergency kill switch | in-process flag or environment variable |
| Custom policy logic | policy_hooks=[my_custom_check] |
Full field reference: see docs/API.md.
Audit trail
Every decision produces a structured event. By default it goes to Python's standard
logging module under the logger name toolboundary.audit, so it flows into whatever
logging pipeline you already have (stdout, a file, CloudWatch, Datadog, etc.) with zero
extra code.
from toolboundary.audit import AuditTrail, JSONLFileSink
boundary = Boundary(
agent_name="support-agent",
...,
audit=AuditTrail(sinks=[JSONLFileSink("toolboundary-audit.jsonl")]),
)
A WebhookSink is also included if you want to forward events to a self-hosted
dashboard or a centralized governance platform. Audit delivery is always best-effort —
a network hiccup in your audit pipeline can never block or crash your agent, because
the ALLOW/DENY decision has already been enforced locally before the sink is invoked.
Design philosophy
- Fail closed. Anything ambiguous, misconfigured, or erroring is treated as denied
by default. See
fail_closed_on_hook_errorfor the one place this is configurable. - No infrastructure required. No database, no server, no login. The whole thing is a Python object you construct alongside your agent code.
- Version-controlled policy. Your boundary is code, reviewed in the same pull requests as everything else — not a setting buried in a web UI that drifts silently out of sync with what the agent actually does.
- Loud by default. Denials raise exceptions, not silent
Falsereturns that are easy to accidentally ignore. - Framework-agnostic core, framework-specific adapters. The core
Boundaryhas zero dependencies. Framework integrations (LangChain today; more welcome via PR) are optional extras.
Known limitations — please read this
ToolBoundary is an in-process, application-layer library. Being explicit about what it does not do is more important than what it does:
- It cannot stop an agent that bypasses it entirely. If your agent's code has any
path that calls a tool's real implementation directly — instead of through a
@guarded_tool-wrapped function or aguard_tool-wrapped LangChain tool — that call is not evaluated. ToolBoundary governs the doors you route through it; it is not a network firewall. - It is not a substitute for credential scoping. If the underlying API key or database credential your tool uses has broader permissions than ToolBoundary's policy allows, a determined attacker who obtains that credential directly bypasses ToolBoundary entirely. Scope your actual credentials as tightly as you can — ToolBoundary is a second layer, not a replacement for the first.
- It is not a compliance/audit system of record for large organizations. If you have dozens of agents across multiple teams and need human governance workflows, cross-team registries, and formal approval routing, look at enterprise AI governance platforms — ToolBoundary is intentionally not trying to be that.
- The in-memory rate limiter is per-process. If you run multiple replicas of your
agent, each process has its own rate-limit counters unless you supply a shared
backing store (see
Boundary's internals / open an issue if you need this — a Redis-backed limiter is a natural community contribution).
If your threat model requires guaranteeing that a compromised agent physically cannot reach a tool's network endpoint except through an approved path, you need a network-layer control (a sidecar proxy, egress firewall rule, or service mesh policy) in addition to ToolBoundary, not instead of it.
Installation
pip install toolboundary # core, zero dependencies
pip install toolboundary[langchain] # + LangChain integration
Contributing
Issues and PRs are welcome. See CONTRIBUTING.md.
Ideas that would make great first contributions:
- Redis-backed rate limiter for multi-process deployments
- CrewAI / AutoGen / LangGraph integrations (mirroring
integrations/langchain.py) - A minimal read-only local dashboard that tails a
JSONLFileSinklog
License
MIT — see LICENSE.
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 toolboundary-0.1.0.tar.gz.
File metadata
- Download URL: toolboundary-0.1.0.tar.gz
- Upload date:
- Size: 38.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4ab498b81b0dd6cac608a3377f7475b3257adea2cd172a1dc94f824f93b72b3
|
|
| MD5 |
152bb34c2a0c23f4280eaeb0f14a888b
|
|
| BLAKE2b-256 |
b2b4970167ff1b20ed2f2f795978819855e7e58f7339cc530b3ae068adcecbc1
|
Provenance
The following attestation bundles were made for toolboundary-0.1.0.tar.gz:
Publisher:
publish.yml on Jaycubic/toolboundary
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
toolboundary-0.1.0.tar.gz -
Subject digest:
e4ab498b81b0dd6cac608a3377f7475b3257adea2cd172a1dc94f824f93b72b3 - Sigstore transparency entry: 2615971064
- Sigstore integration time:
-
Permalink:
Jaycubic/toolboundary@5cd9152dca5258a1af4bdfd05bc5613349969a92 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Jaycubic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5cd9152dca5258a1af4bdfd05bc5613349969a92 -
Trigger Event:
release
-
Statement type:
File details
Details for the file toolboundary-0.1.0-py3-none-any.whl.
File metadata
- Download URL: toolboundary-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca68e408d5337280fa4d1145fc592c074da22636435490ca127c8092b97fdf04
|
|
| MD5 |
05c26cc88fc0e618f18343fcd7eff39f
|
|
| BLAKE2b-256 |
cea530d3cbfeecd85d9e0348f2e67d27d56eaa5aa95fdc87062aaea897e4ed97
|
Provenance
The following attestation bundles were made for toolboundary-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Jaycubic/toolboundary
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
toolboundary-0.1.0-py3-none-any.whl -
Subject digest:
ca68e408d5337280fa4d1145fc592c074da22636435490ca127c8092b97fdf04 - Sigstore transparency entry: 2615971090
- Sigstore integration time:
-
Permalink:
Jaycubic/toolboundary@5cd9152dca5258a1af4bdfd05bc5613349969a92 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Jaycubic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5cd9152dca5258a1af4bdfd05bc5613349969a92 -
Trigger Event:
release
-
Statement type: