Policies & Rules
8 policy presets, 13 condition types, boolean combinators, and priority ordering.
Policies are the core of governance-sdk. Every enforce() call evaluates your policies against the proposed action and returns allow or block.
Policy Presets
8 built-in presets cover 90% of governance needs. Import them directly from the main package:
Preset Reference
blockTools
Block specific tools from being called. The most common policy.
allowOnlyTools
Inverse of blockTools — only listed tools are permitted. Everything else is blocked.
requireApproval
Flag specific action types for human review. Returns a "requires_approval" outcome instead of blocking.
tokenBudget
Limit token usage per session. Blocks actions when budget is exceeded.
rateLimit
Declarative threshold check. The SDK checks a caller-supplied count against the threshold — it does not track counts itself.
Warning: This is a declarative check, not server-side rate limiting. For production rate limiting, use the governance API with Upstash/Redis.
requireLevel
Require agents to reach a minimum governance score level before acting.
requireSequence
Require prerequisite tools to run before a target tool. Useful for CI/CD-style pipelines.
timeWindow
Restrict actions to specific time windows. Block deployments outside business hours.
Boolean Combinators
Compose complex policies by combining conditions with any_of (OR), all_of (AND), and not (NEGATE). Nest infinitely.
Priority Ordering
Rules are evaluated in priority order — higher numbers win. The kill switch uses priority 999 and overrides everything.
| Priority | Rule | Note |
|---|---|---|
| 999 | Kill switch | Overrides all rules |
| 100 | blockTools(['shell_exec']) | Highest preset |
| 95 | requireLevel(2) | High priority |
| 80 | requireApproval(['payment']) | Medium priority |
Policy Composition
Merge policy sets from different teams with conflict resolution. Import from governance-sdk/policy-compose.
Note: When teams disagree,
strictpicks the stricter rule. Usepriorityto let higher-priority rules win regardless.