Skip to main content
This guide covers patterns and best practices for writing intuition policies that make your agents safer and more predictable.

When to use policies

Use policies when you need to:
  • Block dangerous operations before they execute
  • Modify inputs to add safety bounds or fix common issues
  • Provide guidance without blocking execution
  • Audit decisions for compliance and debugging

Policy structure

Every policy extends DirectedIntuition and implements the advise method:

Three types of actions

Hints (advisory)

Use hints to provide guidance without blocking:
Hints appear in the event timeline but don’t modify execution.

Interventions (modify)

Use interventions to fix inputs or add safety bounds:
Interventions modify the state and continue execution.

Vetoes (block)

Use vetoes to completely block dangerous operations:
Veto signals are recorded in the timeline. Runtime blocking is enforced by Governance when governance_mode="enforce".

Common patterns

Pattern: Regex-based detection

Pattern: Risk scoring

Pattern: Context-aware policies

Testing policies

Test policies in isolation without running full episodes:
Run tests with:

Wiring policies

CLI

Python

Multiple policies

Chain multiple policies by creating a composite:

Policy identity in artifacts

DirectedIntuition.hint()/intervene()/veto() return IntuitionEvent with default policy metadata (policy_id="unspecified", policy_version="0.0.0"). To keep artifacts auditable, set identity fields before returning:

Best practices

Keep policies focused. One policy should address one concern. Compose multiple policies for complex scenarios.
Never mutate state directly. Return patches through intervene() and let the core runner apply them.
Test edge cases thoroughly. Policies are security-critical—test empty inputs, unicode, and boundary conditions.

Troubleshooting

Policy not being called

  • Verify intuition=True or intuition=MyPolicy() is passed to ns.run()

Veto not blocking

  • Ensure you’re returning the result: return self.veto(...) not just self.veto(...)
  • Check that the condition actually matches your input
  • Ensure governance is enforcing: ns.set(governance_mode="enforce")

Intervention not applied

  • Verify your patch dictionary has the correct keys
  • Check the event timeline to see if the intervention was recorded

Next steps

Governed Side Effects

Step-by-step tutorial for enforcing side-effect governance.

Governance guide

Configure planner modes for different governance levels.