Skip to main content

Smart Rules

The Smart Rules Engine enables AI-assisted creation of governance rules using natural language, with built-in A/B testing and analytics.

Overview

Create governance rules quickly using natural language descriptions, or build them manually with full control over conditions and actions.

Source: owkai-pilot-frontend/src/components/SmartRuleGen.jsx

Dashboard Tabs

TabDescription
RulesView and manage existing rules
AnalyticsRule performance metrics
A/B TestingTest rule variations
SuggestionsAI-generated rule recommendations

Creating Rules

Method 1: Natural Language

  1. Navigate to Smart Rules
  2. Select Natural Language creation method
  3. Describe your rule in plain English:
"Block all database write operations from autonomous agents
during non-business hours and alert the security team"
  1. Click Generate Rule
  2. Review the generated rule structure
  3. Click Accept to create or Modify to adjust

Method 2: Manual Creation

Create rules with full control:

FieldDescriptionExample
nameRule nameBlock After-Hours PII Access
conditionRule conditionaction_type == 'pii_access' AND time NOT IN business_hours
actionWhat to doalert, block, require_approval
risk_levelSeveritylow, medium, high, critical
descriptionPurposePrevents PII access outside office hours
justificationBusiness reasonGDPR compliance requirement

Rule Actions

ActionDescription
alertGenerate alert, allow action
blockDeny action immediately
require_approvalSend to approval queue
logLog only, no intervention
escalateSend to security team

Rule Conditions

Condition Syntax

field operator value [AND|OR condition]

Available Fields

FieldDescriptionType
action_typeType of actionstring
risk_scoreCalculated risknumber (0-100)
agent_idAgent identifierstring
resourceTarget resourcestring
timeCurrent timetime
dayDay of weeknumber (0-6)
environmentDeployment envstring
user_roleActor rolestring

Operators

OperatorDescriptionExample
==Equalsaction_type == 'database_write'
!=Not equalsenvironment != 'production'
>, >=Greater thanrisk_score >= 70
<, <=Less thanrisk_score < 30
INIn listaction_type IN ['read', 'query']
NOT INNot in listagent_id NOT IN ['trusted-agent']
MATCHESRegex matchresource MATCHES '*.pii.*'

Example Rules

Block High-Risk Deletes:

name: "Block Critical Deletes"
condition: action_type == 'database_delete' AND risk_score >= 80
action: block
risk_level: critical

Require Approval for PII:

name: "PII Approval Required"
condition: resource MATCHES '*.pii.*' OR action_type == 'pii_access'
action: require_approval
risk_level: high

Alert on Autonomous Agent Actions:

name: "Monitor Autonomous Agents"
condition: agent_id MATCHES 'autonomous-*' AND risk_score >= 50
action: alert
risk_level: medium

A/B Testing

Test rule variations to optimize governance:

Creating an A/B Test

  1. Navigate to A/B Testing tab
  2. Click Create Test
  3. Configure test:
{
"name": "Risk Threshold Test",
"description": "Test optimal auto-approve threshold",
"variant_a": {
"condition": "risk_score < 25",
"action": "auto_approve"
},
"variant_b": {
"condition": "risk_score < 35",
"action": "auto_approve"
},
"traffic_split": 50, // 50% each variant
"duration_days": 14,
"success_metric": "false_positive_rate"
}

Test Metrics

MetricDescription
Trigger RateHow often each variant triggers
False Positive RateIncorrectly blocked actions
False Negative RateIncorrectly allowed actions
User Override RateManual corrections needed
Mean Time to DecisionAverage approval time

Rule Analytics

Track rule performance:

Key Metrics (SEC-057)

MetricDescriptionSource
pattern_recognition_accuracyML model accuracyBackend API
events_analyzedTotal events processedBackend API
threat_patterns_identifiedDetected patternsBackend API

Rule Dashboard

┌─────────────────────────────────────────────────────────────┐
│ Rule: Block After-Hours Access │
├─────────────────────────────────────────────────────────────┤
│ Triggers (24h): 47 Blocks: 12 │
│ Alerts: 35 Approvals: 0 │
├─────────────────────────────────────────────────────────────┤
│ Trend: ↗ 15% increase from last week │
└─────────────────────────────────────────────────────────────┘

AI Suggestions

The system generates rule suggestions based on:

  1. Pattern Analysis: Detects recurring action patterns
  2. Risk Trends: Identifies emerging risk areas
  3. Policy Gaps: Finds unprotected resource types
  4. Best Practices: Industry-standard recommendations

Reviewing Suggestions

  1. Navigate to Suggestions tab
  2. Review suggested rules
  3. Click Accept to create rule
  4. Click Dismiss to ignore
  5. Click Modify to customize before creating

Managing Rules

Rule States

StateDescription
ActiveRule is evaluating actions
InactiveRule is disabled
TestingRule in A/B test mode
DraftRule not yet activated

Rule Operations

ActionDescription
EditModify rule conditions
DisableTemporarily deactivate
DeleteRemove rule permanently
CloneCreate copy for modification
ExportDownload rule as JSON

API Reference

EndpointMethodDescription
/api/smart-rulesGETList all rules
/api/smart-rulesPOSTCreate new rule
/api/smart-rules/{id}PUTUpdate rule
/api/smart-rules/{id}DELETEDelete rule
/api/smart-rules/analyticsGETRule analytics
/api/smart-rules/ab-testsGETA/B tests
/api/smart-rules/suggestionsGETAI suggestions

Source: ow-ai-backend/routes/smart_rules_routes.py

Best Practices

  1. Start broad, refine narrow: Begin with general rules, add specificity
  2. Use A/B testing: Validate rule effectiveness before full deployment
  3. Review suggestions weekly: AI catches patterns humans miss
  4. Document justifications: Future auditors need context
  5. Monitor false positives: High rates indicate overly strict rules

Source: SmartRuleGen.jsx, smart_rules_routes.py