Rules
The Rules Library holds hard constraints and preferences that govern agent behavior. Use this resource to define rules, check evidence against them, record violations, and manage versions and sharing.
Access it as client.rules on a Strongly client, or the same path on AsyncStrongly with await. All methods exist on both with identical signatures.
Quick start
from strongly import Strongly
client = Strongly()
# List (auto-paginates as you iterate) # filters: category, severity, hierarchy_scope, enabled, tags, search, agent_id, app_id, workflow_id
for rule in client.rules.list():
print(rule.id)
# Create
created = client.rules.create(
description="...",
content="...",
category="...",
)
print(created.id)
# Read it back
fetched = client.rules.retrieve(created.id)
# Delete (returns None; raises on failure)
client.rules.delete(created.id)
Methods
Core
list
list(*, category: Optional[str] = None, severity: Optional[str] = None, hierarchy_scope: Optional[str] = None, enabled: Optional[bool] = None, tags: Optional[List[str]] = None, search: Optional[str] = None, agent_id: Optional[str] = None, app_id: Optional[str] = None, workflow_id: Optional[str] = None, limit: Optional[int] = None) -> SyncPaginator[Rule]
List rules with pagination and filters.
Args:
category: must | must-not | should.
severity: critical | high | medium | low.
hierarchy_scope: system | org | user | agent.
enabled: Restrict to enabled (True) or disabled (False) rules.
tags: Filter by tags.
search: Full-text search over description and content.
agent_id: Restrict to rules scoped to this agent.
app_id: Restrict to rules scoped to this app instance.
workflow_id: Restrict to rules scoped to this workflow.
limit: Maximum number of items to return (default: all matching items).
Returns:
A paginator yielding Rule objects.
create
create(*, description: str, content: str, category: str, severity: Optional[str] = None, hierarchy_scope: Optional[str] = None, enforcement_mode: Optional[str] = None, triggers: Optional[Mapping[str, Any]] = None, tags: Optional[Sequence[str]] = None, enabled: Optional[bool] = None, source: Optional[str] = None, scope: Optional[Mapping[str, Any]] = None) -> Rule
Create a rule.
Args:
description: Trigger predicate / one-line summary (required).
content: Rule body, loaded into context on match (required).
category: must | must-not | should (required).
severity: critical | high | medium | low.
hierarchy_scope: system | org | user | agent.
enforcement_mode: inject | gate | both.
triggers: Free-form trigger tree
({keywords?, toolName?, embedding?, always?}).
tags: Discoverability tags.
enabled: Whether the rule starts enabled.
source: Provenance label.
scope: Isolation scope ({agentId?, appId?, workflowId?}).
Returns:
The created Rule.
retrieve
retrieve(rule_id: str) -> Rule
Retrieve a single rule by id.
update
update(rule_id: str, *, description: Optional[str] = None, content: Optional[str] = None, category: Optional[str] = None, severity: Optional[str] = None, hierarchy_scope: Optional[str] = None, enforcement_mode: Optional[str] = None, triggers: Optional[Mapping[str, Any]] = None, tags: Optional[Sequence[str]] = None, enabled: Optional[bool] = None, change_note: Optional[str] = None) -> Rule
Update a rule and return the updated record.
delete
delete(rule_id: str) -> None
Delete a rule. Raises on failure; returns nothing.
Sharing & scope
share
share(rule_id: str, *, user_id: str) -> Dict[str, Any]
Share a rule with another user.
unshare
unshare(rule_id: str, *, user_id: str) -> Dict[str, Any]
Revoke a user's share on a rule.
toggle_public
toggle_public(rule_id: str) -> Dict[str, Any]
Toggle the public visibility flag on a rule.
toggle_enabled
toggle_enabled(rule_id: str) -> Dict[str, Any]
Toggle whether a rule is enabled.
update_scope
update_scope(rule_id: str, *, scope: Optional[Dict[str, Any]] = None) -> Dict[str, Any]
Re-scope a rule (owner-only). An empty scope moves it to user-global.
Args:
rule_id: Target rule id.
scope: {agentId?, appId?, workflowId?}.
Returns:
{success, scope} with the resolved scope.
Other
applicable
applicable(*, user_turn: Optional[str] = None, tool_name: Optional[str] = None, scope: Optional[Mapping[str, Any]] = None) -> Dict[str, Any]
Return the enabled rules whose triggers match the given turn/tool/scope.
Also returns the canonical markdown contextBlock for system-prompt
injection.
Args:
user_turn: The user's current turn (matched against trigger keywords).
tool_name: The tool about to be called (matched against trigger toolName).
scope: Isolation scope ({agentId?, appId?, workflowId?}).
assess
assess(rule_id: str) -> Dict[str, Any]
Run a relevance/quality assessment for a rule.
check
check(*, tool_name: Optional[str] = None, description: Optional[str] = None, args: Optional[Mapping[str, Any]] = None, user_turn: Optional[str] = None, scope: Optional[Mapping[str, Any]] = None) -> Dict[str, Any]
Run rules against a proposed action; returns {allowed, blockedBy, reason}.
Args:
tool_name: Tool the agent is about to invoke.
description: Human description of what the action will do.
args: Free-form tool input arguments.
user_turn: Current user turn (for keyword-only rules).
scope: Isolation scope ({agentId?, appId?, workflowId?}).
export
export(**params) -> Dict[str, Any]
Export the Rules Library (optionally filtered) as a portable bundle.
import_from_github
import_from_github(*, github_url: str) -> Dict[str, Any]
Import rules from a GitHub repository reference.
import_rules
import_rules(*, rules: Sequence[Mapping[str, Any]], scope: Optional[Mapping[str, Any]] = None) -> Dict[str, Any]
Bulk-import rules from an export payload.
Args:
rules: Rule rows (the free-form shape /rules/export emits).
scope: Isolation scope to assign imported rows.
list_violations
list_violations(rule_id: str, **params) -> List[RuleViolation]
List recorded violations for a rule.
record_violation
record_violation(rule_id: str, *, attempted_action: str, detected_by: Optional[str] = None, thread_id: Optional[str] = None, run_id: Optional[str] = None, scope: Optional[Mapping[str, Any]] = None, evidence: Optional[Mapping[str, Any]] = None) -> RuleViolation
Record a violation against a rule and return the created record.
Args:
rule_id: Target rule id.
attempted_action: The action that violated the rule (required).
detected_by: What detected the violation.
thread_id: Originating thread id.
run_id: Originating run id.
scope: Isolation scope ({agentId?, appId?, workflowId?}).
evidence: Free-form supporting evidence.
restore_version
restore_version(rule_id: str, version: int) -> Rule
Restore a rule to an earlier version and return the restored record.
retrieve_version
retrieve_version(rule_id: str, version: int) -> RuleVersion
Retrieve a specific version snapshot of a rule.
versions
versions(rule_id: str) -> List[RuleVersion]
List the version history of a rule (most recent first).
violations_aggregate
violations_aggregate(**params) -> Dict[str, Any]
Return aggregate violation counts across rules.