Sub-2ms, zero-dependency-bloat runtime guardrails and governance SDK for Enterprise AI Agents (LangChain, CrewAI, ADK, FastAPI, MCP)
Overview
agent-gov-sdk sits directly inside your Python execution path (@enforce_guardrail, guard_tools, guard_mcp_server, AgentGuard, and the agent-gov CLI hook) to prevent AI agents () and Agentic IDEs () from executing unauthorized tools, overspending budgets, entering infinite tool loops, leaking PII/cloud credentials, or falling victim to prompt & SQL/command injection— We analyzed the across Open-Source Guardrails (NeMo Guardrails, Guardrails AI, Meta LlamaFirewall, LLM Guard, Microsoft Presidio, Invariant Labs MCP-Scan), Cloud AI Firewalls (Lakera Guard, Palo Alto Prisma AIRS, Cisco Robust Intelligence, CalypsoAI, Arthur Shield, AWS Bedrock Guardrails, Azure Prompt Shield, Google Model Armor), Framework Callbacks (LangGraph Interrupts, Google ADK Callbacks, CrewAI Hooks, OpenAI Agents Guardrails), and AI Gateways (Galileo Protect, Portkey)—along with developer community feedback on what is missing: Wrap an entire list of existing tools in —preserving .name, .description, .
README
🛡️ Agent Governance SDK (agent-gov-sdk v0.2.0)
Sub-2ms, zero-dependency-bloat runtime guardrails, tool circuit-breakers, and Agentic IDE hooks for Enterprise AI Agents.
agent-gov-sdk sits directly inside your Python execution path (@enforce_guardrail, guard_tools, guard_mcp_server, AgentGuard, and the agent-gov CLI hook) to prevent AI agents (LangChain / LangGraph, Google ADK, CrewAI, OpenAI Agents SDK, AutoGen, FastMCP) and Agentic IDEs (Google Antigravity, Claude Code, OpenAI Codex, Cursor, VS Code) from executing unauthorized tools, overspending budgets, entering infinite tool loops, leaking PII/cloud credentials, or falling victim to prompt & SQL/command injection—all in < 2ms p95 without requiring external GPU models or cloud proxy round-trips.
✨ Benchmarked Against the Top 20 Guardrail & Agent Security Solutions
We analyzed the Top 20 solutions across Open-Source Guardrails (NeMo Guardrails, Guardrails AI, Meta LlamaFirewall, LLM Guard, Microsoft Presidio, Invariant Labs MCP-Scan), Cloud AI Firewalls (Lakera Guard, Palo Alto Prisma AIRS, Cisco Robust Intelligence, CalypsoAI, Arthur Shield, AWS Bedrock Guardrails, Azure Prompt Shield, Google Model Armor), Framework Callbacks (LangGraph Interrupts, Google ADK Callbacks, CrewAI Hooks, OpenAI Agents Guardrails), and AI Gateways (Galileo Protect, Portkey)—along with developer community feedback on what is missing:
| Developer / Enterprise Pain Point | Top 20 Existing Solutions | agent-gov-sdk (v0.2.0) |
|---|---|---|
| Dependency Footprint & Latency | 500MB–2GB+ ML weights or 50–250ms cloud RTT |
=2.0), < 2ms p95 in-process |
| Tool-Boundary Spend & Loop Circuit Breakers | Prompt-only; no cumulative spend or loop state | ✅ Per-call, per_tool_max_spend, max_session_spend & Loop Breaker |
| Autonomous Agent Self-Correction | Unhandled exceptions crash the agent loop | ✅ OnFailAction.FEEDBACK returns corrective instructions to LLM |
| 1-Line Bulk Framework Wrapping | Strips .name / .args_schema on BaseTool |
✅ guard_tools([...]), adk_before_tool_callback, guard_mcp_server |
| Agentic IDE Support (Antigravity, Claude Code, Codex, VS Code) | Python-only APIs; no IDE hook CLI | ✅ agent-gov check & agent-gov hook CLI + IDE templates |
| Deep Recursive Scanners + Luhn Check | Flat string scanning | ✅ Recursive dict/list PII (w/ Luhn), Secrets, Prompt Inj, SQLi, CmdInj, Path Traversal |
🚀 Installation
# Core SDK + `agent-gov` CLI (only requires pydantic>=2.0)
pip install agent-gov-sdk
# With FastAPI & OpenTelemetry integrations
pip install "agent-gov-sdk[fastapi,otel]"
🔌 Zero-Friction Integration with Agent Frameworks (1 Line)
1. LangChain / LangGraph, CrewAI & OpenAI Agents SDK (guard_tools)
Wrap an entire list of existing tools in one line—preserving .name, .description, .args_schema, and both sync/async entrypoints:
from agent_gov_sdk import OnFailAction, PolicyConfig, guard_tools
policy = PolicyConfig(
restricted_tools=["drop_database"],
block_financial_transactions_over=500.0,
per_tool_max_spend={"issue_refund": 100.0},
enable_pii_scanner=True,
enable_secrets_scanner=True,
enable_payload_security_scanner=True,
on_fail=OnFailAction.FEEDBACK, # Returns self-correction prompt to LLM instead of crashing!
)
# Works with LangChain BaseTool/@tool, CrewAI Tool, or plain functions:
safe_tools = guard_tools([search_tool, issue_refund, sql_tool], config=policy)
2. Google ADK — Agent Development Kit (guard_adk_agent & Tool Callbacks)
In Google ADK, Agent exposes before_tool_callback and after_tool_callback. You can attach both pre-call and post-call guardrails in one line using guard_adk_agent (or pass create_before_tool_callback / create_after_tool_callback explicitly):
from google.adk.agents import Agent
from agent_gov_sdk import PolicyConfig, guard_adk_agent
policy = PolicyConfig.from_file("examples/policies/enterprise_strict_policy.json")
# 1-Line ADK Agent Instrumentation (attaches both before_tool_callback & after_tool_callback):
root_agent = guard_adk_agent(
Agent(
name="enterprise_assistant",
model="gemini-2.5-flash",
tools=[...],
),
config=policy,
)
See the full runnable ADK sample agent in examples/adk_agent/ (python3 examples/adk_agent/run_adk_sample.py) and the Developer How-To Guide & Cookbook (docs/how-to-guides.md).
3. FastMCP / Model Context Protocol Servers (guard_mcp_server)
Protect every @mcp.tool() registered on an MCP server used by Antigravity, Claude Desktop, or Cursor:
from mcp.server.fastmcp import FastMCP
from agent_gov_sdk import PolicyConfig, guard_mcp_server
mcp = FastMCP("EnterpriseMCP")
guard_mcp_server(mcp, config=PolicyConfig.from_file("examples/policies/enterprise_strict_policy.json"))
@mcp.tool()
def query_db(sql: str) -> str:
return f"Result: {sql}"
💻 Native Integration with Agentic IDEs (Antigravity, Claude Code, Codex, VS Code)
agent-gov-sdk installs the agent-gov CLI binary for zero-code PreToolUse hook enforcement across Agentic IDEs. Ready-to-copy templates are in examples/ide_integrations/:
- Claude Code (
.claude/settings.jsonPreToolUseHook) — seeclaude_code_settings.json:{ "hooks": { "PreToolUse": [ { "matcher": "Bash|Edit|Write", "hooks": [{ "type": "command", "command": "agent-gov hook --policy examples/policies/enterprise_strict_policy.json" }] } ] } } - Google Antigravity (AGY) & MCP Servers — see
antigravity_rule.md. - VS Code / Cursor / OpenAI Codex CLI — see
vscode_cursor_tasks.json:agent-gov check --tool bash --params '{"command": "pytest tests/"}'
🏢 Enterprise Reference Gateway & 12-Scenario Verification Suite
All declarative policies (enterprise_strict_policy.json, customer_support_redact_policy.json, shadow_audit_policy.json) and enterprise workflows live in examples/:
# 1. Run the 12-scenario FinOps, SecOps, Support Redaction, HITL & SOC2 verification suite
PYTHONPATH=src:. python examples/run_enterprise_scenarios.py
# 2. Run the 1-line multi-framework quickstart demo
PYTHONPATH=src:. python examples/framework_quickstart.py
# 3. Launch the interactive FastAPI Enterprise Gateway (Swagger UI at http://127.0.0.1:8000/docs)
PYTHONPATH=src:. uvicorn examples.enterprise_app:app --reload --port 8000
🧪 Testing, Static Analysis & Load Benchmarks
# Run all 42 unit, contract, E2E, enterprise scenario, CLI hook, and 500-concurrency load tests
PYTHONPATH=src:. pytest --cov=agent_gov_sdk --cov-report=term-missing tests/ -v
# Strict linting and static type verification
ruff check src tests examples
mypy --strict src/agent_gov_sdk examples
- Test Suite: 42 / 42 tests passing (
92%coverage acrosssrc/agent_gov_sdk). - Concurrency & Latency SLA: 500 concurrent governed agent sessions verified at
p95 < 2.0msoverhead with 0 cross-session state leaks. - 12-Phase SDLC Documentation: Complete specification, Top-20 benchmark, HLD, LLD, LLDSpec, TDD-Red/Green, and deployment artifacts in
specs/001-runtime-guardrail-sdk/.
📄 License
MIT License — see LICENSE for details.
Install
This server does not publish a one-line install command.
Open the repository installation guide