--- id: toolguard version: "0.2.21" license: Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) license_treatment: permissive maintenance: active --- # toolguard — Policy adherence code generation for guarding AI agent tools License: permissive · Maintenance: active · Downloads: 171.8K/mo ## What it is and what it does Toolguard is a two-phase system for enforcing business policies on AI agent tool calls. It bridges the gap between traditional hard-coded policy enforcement and the non-deterministic best-effort approach of appending policies to agent prompts. The package generates deterministic Python guard code that validates tool invocations against policy constraints before execution, preventing unauthorized calls or unsafe parameter values. The workflow is split into buildtime (policy analysis and code generation) and runtime (guard execution). At buildtime, you provide a policy document and a set of tools (as Python functions or OpenAPI specs), and the package uses an LLM to extract policy requirements, generate test cases, and produce executable guard code. At runtime, you load the generated guards and invoke tools through a guard wrapper that checks preconditions before allowing execution. The package depends on langchain-core, litellm, pydantic, and testing utilities to orchestrate LLM calls, manage tool schemas, and validate generated code. Use it for: - Enforce financial transaction limits or approval workflows in agent-driven banking systems before tools execute. - Prevent unauthorized data access by validating agent tool calls against role-based policies before database queries run. - Block division-by-zero or invalid parameter combinations in computational tools by checking preconditions deterministically. - Ensure compliance with data residency or privacy policies by guarding tool invocations that access sensitive data. - Generate audit trails of policy checks by logging guard evaluations before tool execution. - Validate multi-step agent workflows against operational constraints (e.g., 'do not multiply if operand KDI value equals X'). ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Generates deterministic Python code that enforces business policy constraints on AI agent tool invocations before they execute, preventing policy violations at the tool level. Yes, if you need deterministic policy enforcement on AI agent tools and can invest in the buildtime setup (policy document, LLM configuration, tool specs). The package is actively maintained, has low install friction, and solves a real problem in agentic systems. Not suitable if you need runtime-only policy injection without code generation, or if you lack access to an LLM provider for the buildtime phase. ## Install pip install toolguard uv add toolguard poetry add toolguard ## Installing toolguard Before you install: Low install friction with a pure Python wheel. Active maintenance (45 days since latest release). Depends on 12 runtime packages including langchain-core, litellm, pydantic, and pytest utilities—a substantial but standard AI/LLM stack. License in practice: Apache License 2.0 (permissive). You may use, modify, and distribute this package freely in commercial and private projects, provided you include the license and document any changes. Quickstart: pip install toolguard from toolguard.buildtime import generate_guard_specs, LitellmModel from toolguard.runtime import load_toolguards, ToolFunctionsInvoker # Step 1: Generate specs from policy document and tools specs = await generate_guard_specs(policy_text, tools, llm=llm_model) # Step 2: Generate guard code guards = await generate_guards_code(tool_specs=specs, tools=tools, llm=llm_model) # Step 3: Load and use at runtime with load_toolguards("output") as toolguard: invoker = ToolFunctionsInvoker(tools) await toolguard.guard_toolcall("tool_name", {"param": value}, invoker) Requires Python 3.10+. Buildtime API requires an LLM provider (e.g., Azure OpenAI) configured via litellm. Policy documents and tool OpenAPI specs must be provided. Verify before relying: - Whether the generated guard code is guaranteed to be deterministic or only intended to be so in practice. - Performance overhead of guard evaluation at runtime for large numbers of tools or complex policies. - How well the tool handles edge cases in policy interpretation or ambiguous policy language. - Support for dynamic policy updates without regenerating all guard code. ## Package facts - License: Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 171.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags ai agent policy enforcement, tool guard constraints, policy compliance code generation, agent tool preconditions, business policy guardrails, deterministic policy validation, agent tool policy checks, agent-guardrails, policy-as-code, llm-codegen [View on SkillFed](https://skillfed.io/packages/toolguard) · [View on PyPI](https://pypi.org/project/toolguard/)