Skip to main content

Example Policy

Combine your custom rule and action into a complete policy:

Policy Scope

Control which parts of the input are subject to policy enforcement using scope parameters. When not specified, all scopes default to True.

Scope Resolution Priority

Scope flags are resolved with Policy > Task > Agent priority:
  1. If the Policy sets a scope flag (e.g., apply_to_description=False), that value is used
  2. Otherwise, if the Task sets the flag (e.g., policy_apply_to_description=False), that value is used
  3. Otherwise, the Agent default is used (e.g., user_policy_apply_to_description=True)

Advanced Policy Configuration

You can specify different LLM models for different operations:

Using with Agent

Tool Safety Policies

Tool safety policies validate tools at two stages:
  • tool_policy_pre: Validates tools during registration (before task execution)
  • tool_policy_post: Validates tool calls before execution (when LLM calls a tool)

Streaming Support

Custom policies work seamlessly with streaming. For Anonymize actions, de-anonymization happens token-by-token in real-time:

Async Support

All policies automatically support async operations:

Complete Example

Here’s a full working example combining everything: