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:

ts

Preset Reference

blockTools

Block specific tools from being called. The most common policy.

ts

allowOnlyTools

Inverse of blockTools — only listed tools are permitted. Everything else is blocked.

ts

requireApproval

Flag specific action types for human review. Returns a "requires_approval" outcome instead of blocking.

ts

tokenBudget

Limit token usage per session. Blocks actions when budget is exceeded.

ts

rateLimit

Declarative threshold check. The SDK checks a caller-supplied count against the threshold — it does not track counts itself.

ts

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.

ts

requireSequence

Require prerequisite tools to run before a target tool. Useful for CI/CD-style pipelines.

ts

timeWindow

Restrict actions to specific time windows. Block deployments outside business hours.

ts

Boolean Combinators

Compose complex policies by combining conditions with any_of (OR), all_of (AND), and not (NEGATE). Nest infinitely.

ts

Priority Ordering

Rules are evaluated in priority order — higher numbers win. The kill switch uses priority 999 and overrides everything.

PriorityRuleNote
999Kill switchOverrides all rules
100blockTools(['shell_exec'])Highest preset
95requireLevel(2)High priority
80requireApproval(['payment'])Medium priority

Policy Composition

Merge policy sets from different teams with conflict resolution. Import from governance-sdk/policy-compose.

ts

Note: When teams disagree, strict picks the stricter rule. Use priority to let higher-priority rules win regardless.