Skip to main content
Define allow/deny rules so agents cannot run dangerous tools — attach a PolicyEngine before the agent starts.
The user requests a risky action; policy rules allow or deny tools before execution.

Quick Start

1

Simple Usage

Block delete tools on a file-management agent:
2

With Configuration

Use strict mode and custom deny lists:
3

Denial in action

Attach a deny policy and watch the tool call get blocked before it runs:
Policy denials return an error to the model before the tool executes — the same pre-dispatch check applies to native and MCP tools alike. Guardrails run at this same hook: GuardrailChain.validate_tool_call / LLMGuardrail.validate_tool_call can veto a tool call before dispatch (see the Guardrails card below).

Read-only preset — what it blocks

create_read_only_policy() returns a Policy at priority 100 with 11 deny rules — 2 file-resource rules and 9 tool-name rules — covering the SDK’s built-in mutating tools.
The preset matches by both prefix (tool:write_*) and suffix (tool:*_write*), so custom-named tools like atomic_write and file_write are caught too. An explicit ALLOW rule at higher priority still wins — a deny does not silently override it. Add ALLOW rules for any specific tool you need to permit.
Upgrade note (PraisonAI PR #3632): earlier releases shipped create_read_only_policy() with glob patterns that never matched the SDK’s real tool names. If you relied on the preset as a safety net before this release, your agent could still call write_file / delete_file / edit_file / etc. Upgrade to the fixed release and re-run your safety tests.

Network egress

Gate outbound requests by destination host using check_network() and the create_network_policy() preset. Attach a network policy, then consult the engine before any outbound call:
Scope: decision seam only. The runtime does not yet automatically call check_network() before every tool, MCP, or LLM request. Callers integrating outbound HTTP must invoke it themselves. See PraisonAI#5333 for the wider egress-enforcement roadmap.

Which policy shape fits

Resource format

check_network(host) normalizes the host and evaluates a net:<host> resource. The destination host is authoritative — a caller-supplied context["host"] cannot override it.

Wildcards

Host patterns support fnmatch wildcards.
When an allow-list is present, create_network_policy adds an implicit net:* default-deny rule at priority 0.

Case / trailing-dot normalization

API.Example.COM., api.example.com, and api.example.com. all match the same rule.

How It Works

Pattern examples: tool:read_file, tool:delete_*, tool:*.

Configuration Options


Policies from Plugins

A plugin declared PluginType.POLICY that returns Policy objects from get_policies() is added to the Agent’s PolicyEngine automatically. If the Agent has no user policy=, one is created; if it has one, plugin rules are added to the existing engine.
On Agent.__init__, _merge_plugin_subsystems() calls PluginManager.get_all_policies() and adds each rule to the engine, guarded by a name-uniqueness check:

Precedence — user-supplied policy always wins

If a policy with the same name already exists on the engine when the plugin’s rule is added, the plugin’s rule is logged and skipped — a plugin can never silently loosen a user-configured restriction. See Typed Plugins (Guardrail / Policy / Skill) for the full plugin-side reference.

Best Practices

Set agent.policy = engine immediately after creating the agent.
create_read_only_policy() blocks the SDK’s built-in mutating tools — write_*, delete_*, edit_*, apply_patch*, copy_*, move_*, append_*, and the *_write* / *_delete* suffix forms. Attach it, then add explicit ALLOW rules at higher priority for any specific tool you need to permit.
Prefer tool:delete_* over tool:* deny rules so read tools keep working.
PolicyConfig(strict_mode=True) blocks unknown tool names by default.

Guardrails

Validate agent output before returning to users

Approval

Require human confirmation for sensitive actions