toolguard
ToolGuard acts as a safety net for AI systems that use external tools, like APIs or databases. It prevents unexpected errors and crashes that can happen when an AI agent tries to use these tools, ensuring the system runs reliably. Businesses that rely on AI to automate tasks or provide services, such as customer support or data analysis, would find ToolGuard valuable. It’s unique because it focuses on the stability of how the AI interacts with external tools, rather than the AI’s intelligence itself. This allows companies to confidently deploy AI agents knowing they are protected from common failure points, leading to more dependable and predictable performance.
README
<div align="center">
# 🛡️ ToolGuard
**The "Cloudflare for AI Agents".** 6-layer security interceptor, real-time observability dashboard, and automated reliability testing for MCP and AI tool chains.

[](https://python.org)
[](LICENSE)
[](#)
[](#native-framework-integrations)
[](#)
</div>
---
### Operations vs. Engineering
📻 **Use the Dashboard (`toolguard dashboard`) when:**
* **Live Monitoring**: You are running an agent and want to watch it work in real-time.
* **Visualizing Crashes**: You see a `BLOCKED` event and want to inspect the **JSON Payload** or the **DAG Timeline** to see exactly why the semantic layer fired.
* **Demos & Presentations**: It’s the best way to show someone (or a client) how the security mesh actually protects the system.
* **Post-Mortem**: Reviewing the history of traces to identify "hallucination drifts" over time. 🦇
⌨️ **Use the Terminal (`toolguard run` / `test`) when:**
* **CI/CD Pipelines**: You want the build to fail automatically if the reliability score drops below 95%.
* **Rapid Iteration**: You just changed one line of code and want a 1-second "Fuzz Check" without leaving your IDE.
* **Headless Servers**: You’re deploying to a Docker container or AWS/GCP where you don't have a web browser.
* **Local Replay**: Using `toolguard replay` to step through a specific failure payload you found earlier. ⚡
Catch cascading failures before production. Make agent tool calling as predictable as unit tests made software reliable.
---
## 🧠 What ToolGuard Actually Solves
Right now, developers don't deploy AI agents because they are fundamentally unstable. They crash.
There are two layers to AI:
1. **Layer 1: Intelligence** (evals, reasoning, accurate answers)
2. **Layer 2: Execution** (tool calls, chaining, JSON payloads, APIs)
**ToolGuard does not test Layer 1.** We do not care if your AI is "smart" or makes good decisions. That is what eval frameworks are for.
**ToolGuard mathematically proves Layer 2.** We solve the problem of agents crashing at 3 AM because the LLM hallucinated a JSON key, passed a string instead of an int, or an external API timed out.
> *"We don't make AI smarter. We make AI systems not break."*
---
## 🚀 Zero Config — Try It in 60 Seconds
```bash
pip install py-toolguard
toolguard run my_agent.py
```
That's it. ToolGuard auto-discovers your tools, fuzzes them with hallucination attacks (nulls, type mismatches, missing fields), and prints a reliability report. Zero config needed.
```
🚀 Auto-discovered 3 tools from my_agent.py
• fetch_price (2 params)
• calculate_position (3 params)
• generate_alert (2 params)
🧪 Running 42 fuzz tests...
╔══════════════════════════════════════════════════════════════╗
║ Reliability Score: my_agent ║
╠══════════════════════════════════════════════════════════════╣
║ Score: 64.3% ║
║ Risk Level: 🟠 HIGH ║
║ Deploy: 🚫 BLOCK ║
╠══════════════════════════════════════════════════════════════╣
║ ⚠️ Top Risk: Null values propagating through chain ║
║ ⚠️ Bottleneck Tools: ║
║ → fetch_price (50% success) ║
║ → generate_alert (42% success) ║
╚══════════════════════════════════════════════════════════════╝
💡 fetch_price: Add null check for 'ticker' — LLM hallucinated None
💡 generate_alert: Field 'severity' expects int, got str from upstream tool
```
Or with Python:
```python
from toolguard import create_tool, test_chain, score_chain
@create_tool(schema="auto")
def parse_csv(raw_csv: str) -> dict:
lines = raw_csv.strip().split("\n")
headers = lines[0].split(",")
records = [dict(zip(headers, line.split(","))) for line in lines[1:]]
return {"headers": headers, "records": records, "row_count": len(records)}
report = test_chain(
[parse_csv],
base_input={"raw_csv": "name,age\nAlice,30\nBob,35"},
test_cases=["happy_path", "null_handling", "malformed_data", "type_mismatch", "missing_fields"],
)
score = score_chain(report)
print(score.summary())
```
---
## 🤖 How ToolGuard is Different
Most testing tools (LangSmith, Promptfoo) test your agent by sending prompts to a live LLM. It is slow, expensive, and non-deterministic.
**ToolGuard does NOT use an LLM to run its tests.**
When you decorate a function with `@create_tool(schema="auto")`, ToolGuard reads your Python type hints and automatically generates a Pydantic schema. It then uses that schema to know exactly which fields to break, which types to swap, and which values to null — no manual configuration needed.
It acts like a deterministic fuzzer for AI tool execution, programmatically injecting the exact types of bad data that an LLM would accidentally generate in production:
1. Missing dictionary keys
2. Null values propagating down the chain
3. `str` instead of `int`
4. Massive 10MB payloads to stress your server
5. Extra/unexpected fields in JSON
ToolGuard doesn't test if your AI is smart. It tests if your Python code is bulletproof enough to *survive* when your AI does something stupid — running in 1 second and costing $0 in API fees.
---
## Features
### 🛡️ Layer-2 Security Firewall (V3.0)
ToolGuard features an impenetrable execution-layer security framework protecting production servers from critical LLM exploits.
- **Human-in-the-Loop Risk Tiers:** Mark destructive tools with `@create_tool(risk_tier=2)`. ToolGuard mathematically intercepts these calls and natively streams terminal approval prompts before execution, gracefully protecting `asyncio` event loops and headless daemon environments.
- **Recursive Prompt Injection Fuzzing:** The `test_chain` fuzzer automatically injects `[SYSTEM OVERRIDE]` execution payloads into your pipelines. A bespoke recursive depth-first memory parser scans internal custom object serialization, byte arrays, and `.casefold()` string mutations to eliminate zero-day blind spots.
- **Golden Traces (DAG Instrumentation):** With two lines of code (`with TraceTracker() as trace:`), ToolGuard natively intercepts Python `contextvars` to construct a chronologically perfect Directed Acyclic Graph of all tools orchestrated by LangChain, CrewAI, Swarm, and AutoGen.
- **Non-Deterministic Verification:** Punishing an AI for self-correcting is an anti-pattern. Developers use `trace.assert_sequence(["auth", "refund"])` to mathematically enforce mandatory compliance checkpoints while permitting the LLM complete freedom to autonomously select supplementary network tools.
### 🛡️ 6-Layer Security Interceptor Waterfall (v5.1.2)
With the v5.1.2 Update, we are moving beyond simple validation. We are introducing a 6-Layer Security Interceptor Waterfall for the Model Context Protocol (MCP):
1. **L1 — Policy**: An immutable “Allow/Deny” list. Stop dangerous tools from ever being contacted.
2. **L2 — Risk-Tier (Human-in-the-Loop Safe)**: Marks destructive tools (like `shutdown_server` or `delete_all`). These calls are frozen until a human approves via a zero-latency terminal prompt, running in an isolated worker so the main event loop stays alive.
3. **L3 — Deep-Memory Injection Defense**: Our most advanced scanner yet. A recursive DFS parser that natively decodes binary streams (`bytes`/`bytearray`) to detect hidden prompt injec
[truncated…]PUBLIC HISTORY
IDENTITY
Identity inferred from code signals. No PROVENANCE.yml found.
Is this yours? Claim it →METADATA
README BADGE
Add to your README:
