Skip to main content

Policy adherence code generation for guarding AI agent tools

Project description

📦 AI Agents Policy Adherence

This tool analyzes policy documents and generates deterministic Python code to enforce operational policies when invoking AI agent tools.

🚀 Features

The workflow consists of two main steps:

Step 1:
Takes a policy document in Markdown format and an OpenAPI specification describing the available tools. For each tool, it generates a JSON file containing associated policies and examples of both compliance and violations.
These files can be reviewed and edited manually before proceeding to Step 2.
The OpenAPI document should describe agent tools and optionally include read-only tools that might be used to enforce policies. It’s important that each tool has:

  • A proper operation_id matching the tool name
  • A detailed description
  • Clearly defined input parameters and return types
  • Well-documented data models

Step 2:
Uses the output from Step 1 and the OpenAPI spec to generate Python code that enforces each tool’s policies.


🐍 Requirements

  • Python 3.12+
  • pip

🛠 Installation

  1. Clone the repository:

    git clone https://github.ibm.com/MLT/gen_policy_validator.git
    cd gen_policy_validator
    
  2. (Optional) Create and activate a virtual environment:

    python3.12 -m venv venv
    source venv/bin/activate  # On Windows use: venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    

.env.example 4. Create a .env file:

Copy the .env.example to src/.env and fill in your environment variables. Replace AZURE_OPENAI_API_KEY with your actual API key. and add in TOOLGUARD_GENPY_ARGS your API_KEY.

▶️ Usage

PYTHONPATH=src python -m policy_adherence --policy-path <path_to_policy> --oas <path_to_oas> --out-dir <output_directory> [options]

Arguments

Argument Type Description
--policy-path str Path to the policy file. Currently in markdown syntax. Example: /Users/me/airline/wiki.md
--oas str Path to an OpenAPI specification file (JSON/YAML) describing the available tools. The operation_ids should match tool names. Example: /Users/me/airline/openapi.json
--out-dir str Path to an output folder where the generated artifacts will be written. Example: /Users/me/airline/outdir2
--force-step1 flag Force execution of step 1 even if artifacts already exist. Default: False
--run-step2 flag Whether to execute step 2. Use --run-step2 to skip. Default: True
--step1-dir-name str Folder name under the output folder for step 1. Default: Step1
--step2-dir-name str Folder name under the output folder for step 2. Default: Step2
--tools list Optional list of tool names to include. These should be a subset of the OpenAPI operation_ids. Example: --tools create_user delete_user

Example

PYTHONPATH=src python -m policy_adherence \
  --policy-path ./policy/wiki.md \
  --oas ./spec/openapi.json \
  --out-dir ./output \
  --force-step1 \
  --tools create_user delete_user

Project details


Download files

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

Source Distribution

toolguard-0.1.0.tar.gz (53.5 kB view details)

Uploaded Source

Built Distribution

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

toolguard-0.1.0-py3-none-any.whl (77.5 kB view details)

Uploaded Python 3

File details

Details for the file toolguard-0.1.0.tar.gz.

File metadata

  • Download URL: toolguard-0.1.0.tar.gz
  • Upload date:
  • Size: 53.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for toolguard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6e514a5f95f6afc7168e070653d4fc0994fb0198661c141e715595fc4c3053d4
MD5 67b91b7d1470da0e306d8715b678ff88
BLAKE2b-256 bfa2c1082fd3e4311ca944b7858025644ca178b17fe58b1d5628c2ac7e217263

See more details on using hashes here.

File details

Details for the file toolguard-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: toolguard-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 77.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for toolguard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f78f539148ff658727e14b38837a2cae5c6c1a51e656b3f4e1c597e6e732ff09
MD5 4d5a700d26e77d08c66ee8bc38c0242f
BLAKE2b-256 cb14726d8f8534be0768f1759790658c7f2202bfd6e931ee38ac13baff66e88f

See more details on using hashes here.

Supported by

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