Skip to content

Policy Generation

Generate Preloop policy YAML using AI from natural-language descriptions or historical audit-log patterns.


Overview

Instead of writing policy YAML by hand, you can describe what you want in plain English and let an AI model generate a valid policy for you. You can also generate policies based on your actual tool usage patterns from audit logs.

Requirements

At least one AI model must be configured in your Preloop account (Settings → AI Models).


CLI Usage

Generate from a Prompt

preloop policy generate "require approval for any payment over $500"

Or read the prompt from a file:

preloop policy generate --file prompt.txt

Generate from Audit Logs

Analyse your historical tool-call patterns:

preloop policy generate --from-audit-logs

With a date range:

preloop policy generate --from-audit-logs \
  --start-date 2026-01-01 --end-date 2026-02-01

Write to File

preloop policy generate "deny all destructive tools" -o policy.yaml

Then apply it:

preloop policy apply policy.yaml

Flags

Flag Description
-o, --output Write output to a file instead of stdout
-f, --file Read prompt from a file
--from-audit-logs Generate from audit-log patterns
--start-date Filter audit logs after this date (ISO format)
--end-date Filter audit logs before this date
--no-context Don't include current account config as LLM context

Web UI Usage

  1. Navigate to Tools → click Generate Policy button
  2. Choose From Description or From Audit Logs tab
  3. Enter your prompt or select date range
  4. Click Generate
  5. Review the generated YAML
  6. Click Apply Policy to activate it

API Endpoints

Generate from Prompt

POST /api/v1/policies/generate
{
  "prompt": "require approval for any payment over $500",
  "include_current_config": true
}

Generate from Audit Logs

POST /api/v1/policies/generate-from-audit
{
  "start_date": "2026-01-01",
  "end_date": "2026-02-01"
}

Response

{
  "yaml": "version: \"1.0\"\nmetadata:\n  name: ...",
  "warnings": ["Some optional warnings"]
}

How It Works

  1. Context gathering — The system collects your account's MCP servers, registered tools, and current policy (optional)
  2. LLM generation — Your default AI model generates valid policy YAML matching the Preloop schema
  3. Validation — The output is validated against the PolicyDocument schema
  4. Preview — You review and optionally edit the YAML before applying

For audit-log generation: 1. Pattern analysis — Historical tool calls are summarised (frequency, users, outcomes) 2. LLM generation — The summary is sent to the LLM with instructions to create appropriate rules 3. Same validation and preview flow