A portable rule pack
Seven rules, across five files, that exercise most of Open Agent Rules 1.0 and are portable in the sense [OAR-DOC-23] records and section 8 defines: every anchor is a core anchor, and every fact comes from the core tier or from a standard profile the rule names in requires_facts. They run unchanged on any engine providing those facts.
Three of the files carry more than one rule, separated by a YAML ---. That is a rule set, and a member's position in one has no effect on its identity, ordering, or precedence.
They are written in YAML because that is the comfortable authoring form. JSON is the interchange form, and the mapping is lossless ([OAR-DOC-1]).
| File | What it demonstrates |
|---|---|
read-outside-scope.yaml | The basic shape: anchor, selector, condition, effect, fail-closed. |
content-safety.yaml | The content-safety surface: a registered detector publishes observations, the rule owns every threshold. Two rules over one detector. |
mcp-server-disabled.yaml | Facts a host may not provide, declared through requires_facts. |
repeat-call.yaml | Escalation over time: the engine counts replayed calls, the rule owns the threshold. |
destructive-tool.yaml | Deterministic order and short-circuit: the specific refusal subsumes the general flag. |
profile.yaml | The anchor profile map of the host these rules assume. |
fixtures/ | Replays against the reference implementation, one per behaviour. |
The two things worth reading closely#
The threshold is in the rule. content-safety.yaml says jailbreak_score > 0.8 and repeat-call.yaml says same_call_run >= 2. A detector produced the score and the engine maintains the count; neither decided what was too much. That is the whole argument of the format — move either number into the host and the policy becomes unreviewable ([OAR-FACT-5]).
Ordering is the composition. destructive-tool.yaml needs two rules where it looks like it needs one, and the guaranteed order makes the pair behave: both rules are policy kind, so ascending id order evaluates DELETE_REFUSED first, and its block short-circuits the occurrence — a delete is refused outright, and the flag rule is never reached ([OAR-EVAL-1], [OAR-EVAL-3]). repeat-call.yaml leans on the same guarantee from the other side: after one replay the block rule passes and the warn decides.
Running them#
Against the reference implementation:
node packages/oar-ref/bin/lint-pack.mjs examples/portable-pack
That loads every YAML document in the pack, validates it against the published schemas, checks that the fixtures replay exactly those documents, and replays every fixture in fixtures/ against the reference runner. A rule here that fails to load is a bug in the pack or the engine, not in the specification — report it either way.
The other worked examples: The hint channel.
content-safety.yaml#
# The content-safety surface ([OAR-OPS-10], [OAR-OPS-11]): a registered detector
# publishes observations — scores, spans — and the rule owns every threshold.
# Two rules over the same detector, separated by a YAML `---`: that is a *rule
# set*, and a member's position in one has no effect on its identity, ordering,
# or precedence.
#
# Both rules name the facts they need in `requires_facts` ([OAR-DOC-22]), so a
# host that does not run a content detector is refused this rule at load with
# both names in the error, rather than meeting a default value at run time.
spec_version: "1.0"
id: INJECTION_FLAGGED
namespace: example.security
kind: detector
on: model.output
selector: {}
requires_facts: [prompt_injection_score]
detector:
ref: detector://fixture
when: 'prompt_injection_score > 0.5'
effect: warn
profile: portable
what: The content scored as a probable injection attempt.
fix: Treat the surrounding content as untrusted before acting on it.
---
spec_version: "1.0"
id: JAILBREAK_REFUSED
namespace: example.security
kind: detector
on: model.output
selector: {}
requires_facts: [jailbreak_score]
detector:
ref: detector://fixture
when: 'jailbreak_score > 0.8'
effect: block
profile: portable
what: The content scored as a jailbreak attempt, so it is not delivered.
fix: Re-source the content; do not replay it with the guardrail relaxed.
destructive-tool.yaml#
# The specific refusal and the general flag.
#
# The specific rule silences the general one it refines without any override
# mechanism: rules evaluate in a deterministic order ([OAR-EVAL-1]) and the
# first block short-circuits the occurrence ([OAR-EVAL-3]). Both rules are `policy` kind, so
# ascending id order puts DELETE_REFUSED first: a delete is refused outright and
# the occurrence ends there, while the state changes that are still allowed are
# flagged by the rule below.
spec_version: "1.0"
id: DELETE_REFUSED
namespace: example.security
kind: policy
on: tool.pre_invoke
selector:
tools: [delete]
effect: block
profile: portable
what: This tool destroys state the session cannot restore.
fix: Move the files to a holding path instead of deleting them.
---
spec_version: "1.0"
id: DESTRUCTIVE_TOOL_WARN
namespace: example.security
kind: policy
on: tool.pre_invoke
selector:
tools: [delete, move, chmod]
effect: warn
profile: portable
what: This tool changes state that is awkward to restore.
mcp-server-disabled.yaml#
# Uses a profile many hosts will not provide. `requires_facts` is what makes
# that a clean load-time refusal instead of a mystery at run time ([OAR-DOC-22]):
# a host without the `mcp` profile does not declare these facts, and the rule is
# rejected with both names in the error.
spec_version: "1.0"
id: MCP_SERVER_DISABLED
namespace: example.security
kind: policy
on: tool.pre_invoke
selector: {}
requires_facts: [mcp_server_id, mcp_server_enabled]
when: 'mcp_server_id != "" && !mcp_server_enabled'
effect: block
profile: portable
what: The call targets a bridged server that is configured but not enabled.
fix: Enable the server in the catalogue, or route the call elsewhere.
profile.yaml#
# The host these rules assume, as an anchor profile map ([OAR-PROF-2],
# [OAR-PROF-3]): which core anchors this host implements, and which it does not.
# A rule targeting an unsupported anchor is refused at load.
#
# The facts a rule may name are declared by the engine's fact environment
# (section 5), and a rule that needs a fact the host lacks names it in
# `requires_facts` ([OAR-DOC-22]).
oar_profile_version: "1.0"
core:
tool.pre_invoke: tool.pre_invoke
tool.handler: tool.handler
tool.post_invoke: tool.post_invoke
model.input: model.input
model.output: model.output
model.tool_result: model.tool_result
unsupported:
- agent.post_turn
- agent.finalize
read-outside-scope.yaml#
# The basic shape: an anchor, a selector, a condition, an effect, and copy that
# explains the refusal. path_outside_scope belongs to the filesystem profile, so
# the rule lists it in requires_facts ([OAR-DOC-22]).
spec_version: "1.0"
id: READ_OUTSIDE_SCOPE
namespace: example.security
kind: policy
on: tool.pre_invoke
selector:
tools: [read, grep]
requires_facts: [path_outside_scope]
when: 'path_outside_scope'
effect: block
on_error: fail_closed # if the scope check itself fails, refuse
profile: portable
title: Read outside the declared scope
what: The call reads a path outside the scope in force for this tool.
fix: Read inside the scope, or widen the scope deliberately.
repeat-call.yaml#
# Escalation over time: notice a replayed call, flag it, then refuse.
#
# same_call_run is maintained by the engine ([OAR-FIRE-9]): how many of the
# latest earlier calls in the session were this same call, with the same
# arguments. The thresholds are in the rules ([OAR-FIRE-3]), so the escalation
# travels with the pack.
#
# Both rules are `invariant` kind and evaluate in ascending id order
# ([OAR-EVAL-1]): REPEAT_CALL_BLOCK first. After two identical earlier calls it
# fires and its block ends the occurrence ([OAR-EVAL-3]); after one it passes
# and REPEAT_CALL_WARN decides.
spec_version: "1.0"
id: REPEAT_CALL_BLOCK
namespace: example.hygiene
kind: invariant
on: tool.pre_invoke
selector: {}
when: 'same_call_run >= 2'
effect: block
on_fire: [publish_event]
profile: portable
what: The same call has been made three times in a row, so it is refused.
fix: Inspect the environment or change the call rather than replaying it.
---
spec_version: "1.0"
id: REPEAT_CALL_WARN
namespace: example.hygiene
kind: invariant
on: tool.pre_invoke
selector: {}
when: 'same_call_run >= 1'
effect: warn
profile: portable
what: The same call has been made twice in a row.
fix: Change the approach instead of replaying the call.