Guardrail

Packs and rules

Choose a guardrail rule pack, add your own pinned by digest, validate it, and change single rules, suppressions and sensitive tools with guardrail.rules.

Three settings decide which rules the guardrail enforces. Use the lightest one that does the job:

You want toUseKey
Run a different shipped packChoose a packguardrail.rule_pack
Add your own rules, or replace a shipped categoryAdd your own pack, pinned by digestguardrail.custom_packs and guardrail.rule_pack
Turn a rule off, change its severity, add a suppression or turn on a protection packChange the pack you useguardrail.rules

All three work at four scopes (global, one connector, one profile, one connector inside a profile). The running gateway applies them on its next reload, with no restart. The levels that go with a pack are on Block and alert levels.

The demo follows one tool call from the hook event to its action: a rule match, the suppression check, the optional judge, then severity and the action the pack gives it.

Guided example · Synthetic runtime event

Trace a runtime verdict from event to action

Follow normalization, a bundled rule match, suppressions, severity, and the default pack mapping.

Deterministic
# ~/.defenseclaw/config.yaml (excerpt)guardrail:  mode: action           # observe mode never blocks  judge:    enabled: false       # the optional LLM judge is off by default  # No block_at is set, so the default pack decides:  # CRITICAL blocks, HIGH and MEDIUM alert, LOW allows.# ~/.defenseclaw/config.yaml (excerpt)guardrail:  mode: action           # observe mode never blocks  judge:    enabled: false       # the optional LLM judge is off by default  # No block_at is set, so the default pack decides:  # CRITICAL blocks, HIGH and MEDIUM alert, LOW allows.
DecisionAlert and allow the call
Reason

HIGH maps to alert under the default pack

Action

Emit decision record

06

Resolve actionUnder the default pack, HIGH resolves to alert.

Step 6 / 6
What DefenseClaw did — and did not do

What it did

  • Show the ordered stages that assemble a runtime verdict
  • Distinguish the optional judge from deterministic rules

What it did not do

  • Evaluate Rego or scanner output in the browser
  • Reuse runtime actions as skill or MCP admission actions

Choose a rule pack

guardrail.rule_pack is a shipped pack (default, strict, permissive) or a key of guardrail.custom_packs.

defenseclaw guardrail use-pack strict                    # every connector
defenseclaw guardrail use-pack strict --connector codex  # one connector
defenseclaw guardrail use-pack --clear --connector codex # back to the global pack
defenseclaw guardrail list-packs                         # who enforces which
  • use-pack validates the pack first and writes nothing if it is invalid.
  • A global use-pack removes per-connector rule_pack entries, and drops enable, disable and severity_overrides IDs the new pack does not have. It names each one. This is also the way out when a pack folder was deleted: defenseclaw guardrail use-pack default.
  • Profiles have no use-pack option: defenseclaw config set guardrail.profiles.contractors.rule_pack strict.
  • Pack names are lower case letters, digits, - and _, at most 64 characters. A folder name with other characters is normalized to this form.

Known limit. An upgrade does not refresh a shipped pack (default, strict or permissive) whose files you edited: the whole edited pack stays, with its older rules. To get the new rules, move the edited folder aside and run defenseclaw init, which seeds the pack again.

The admission preset for skills, MCP servers and plugins is separate: defenseclaw policy activate strict (Presets and packs).

Add your own pack

A custom pack is a folder of rule files you review and pin. config.yaml records its path and content digest, and the gateway refuses to load the pack if the folder no longer hashes to that digest. A rule change reaches enforcement only through a deliberate config change. How to write a rule: Custom rules with CEL.

Copy a pack and edit it

cp -r ~/.defenseclaw/policies/guardrail/default ~/.defenseclaw/policies/guardrail/acme-rules

Add a rules file with its own category, or edit one.

Validate it

defenseclaw guardrail validate-pack ~/.defenseclaw/policies/guardrail/acme-rules
Rule pack valid: "/home/alice/.defenseclaw/policies/guardrail/acme-rules"
  rules: 283/287 enabled across 7 files
  components: judges=4 judge_categories=23 local_patterns=11 suppressions=9 sensitive_tools=6
  digest: 3c6157f8ce099f79ebfa475c3631f8e9334ce929a310630ed2ce66a0fbaa3759
  files digest: 8e97ebd6c9627892aa238c7fabc1e7b31f2ae7ab7ceaace892d051efc4fb7bf7 (the guardrail.custom_packs pin)

Add --json for CI. See Validate a pack.

Pin it and switch to it

defenseclaw guardrail use-pack acme-rules
~/.defenseclaw/config.yaml (written by use-pack)
guardrail:
  rule_pack: acme-rules
  custom_packs:
    acme-rules:
      path: /home/alice/.defenseclaw/policies/guardrail/acme-rules
      digest: sha256:<files digest>

use-pack takes a pack name under ~/.defenseclaw/policies/guardrail/ or a folder path (./NAME for the current folder). Add --connector X for one connector.

Check it worked

defenseclaw guardrail list-packs
defenseclaw doctor

doctor validates the pack each connector uses and shows a Rule pack row per connector.

To undo, defenseclaw guardrail use-pack default; it also removes the pin when no other scope still selects the pack.

A pattern-only rule can block matching prompts and content, but a regex match on a tool call is detection only and never blocks, whatever block_at is. For a tool-call block, write a CEL expression.

On a managed host the Python CLI is not installed. Validate with /opt/defenseclaw/bin/defenseclaw-gateway rulepack validate --dir PACK (/opt/cisco/defenseclaw/bin/defenseclaw-gateway on macOS), which prints the digest to pin, and set rule_pack and custom_packs in the admin config (custom rule packs).

Validate a pack

defenseclaw guardrail validate-pack PATH          # or a pack name
defenseclaw guardrail validate-pack PATH --json

--json prints one line:

{"kind":"validation","summary":{"alert_only_rule_count":0,"digest":"3c6157f8…","enabled_rule_count":283,"files_digest":"8e97ebd6…","judge_category_count":23,"judge_count":4,"local_pattern_count":11,"rule_count":287,"rule_file_count":7,"sensitive_tool_count":6,"stale_rule_count":0,"suppression_count":9},"valid":true,"wire_version":1}
ExitMeaning
0The pack is valid.
1The pack is invalid. The output names the file, error code and reason.
2Validation is unavailable (gateway binary missing, untrusted, timed out or incompatible). This does not say whether the pack is valid.
  • All or nothing. If a recognized file is present, the whole file must parse: a malformed rule, an invalid Go regular expression or an unsupported schema version fails the pack. DefenseClaw does not silently discard the bad file or keep only the entries that parsed.
  • Unknown files fail. A file the loader does not recognize fails the pack; the reason names it (or the folder, for a copy of another pack inside this one) and says to move it out.
  • CEL. Every expression is compiled, disabled rules included (CEL engine).
  • Partial packs. A pack folder is an overlay on the built-in baseline. A missing suppressions.yaml, sensitive-tools.yaml, judge file or rules/local-patterns.yaml keeps the baseline. Any other rules/*.yaml adds or replaces one category.
  • judges=4 counts the built-in exfiltration judge and the three judge files.
A failure
Rule pack invalid: "/home/alice/.defenseclaw/policies/guardrail/bad"
  inventory_unexpected at correlation-patterns.yaml: unexpected YAML component: move correlation-patterns.yaml out of the rule-pack folder or remove it, then run the command or installer again

The digest pin

LineWhat it is
digest:The loaded pack after compilation, including built-in defaults. It can change between builds.
files digest:The pin in guardrail.custom_packs.NAME.digest: a byte-for-byte hash of the pack files. Comments, key order, line endings and a BOM change it. Write it as sha256: and the 64 hex characters.

The pinned digest also covers the optional defenseclaw-pack.json posture file. Adding or editing that file changes the digest, so validate the pack again and pin the new digest, as for a rule file (pack posture).

A guardrail.custom_packs entry is a config error when its path is empty, unreadable or holds no valid pack, or when its digest is missing or does not match. A relative path is read against the folder of config.yaml; ~ is not expanded. While an entry has an error, a setting that selects it runs the built-in pack of that name (default for any other name), status and doctor name the error, and the hook outage mode follows the strict tier. config set guardrail.custom_packs.NAME saves such an entry but prints is registered but will not load.

Change a pinned pack

If you edit a pinned pack in place, the digest no longer matches and the gateway rejects the change. The previous policy keeps running, so nothing weakens:

  • defenseclaw doctor fails the Config validation and Rule pack rows (with the config set command that pins the new digest) and skips Policy: live state was not checked while config.yaml is invalid.
  • /health shows the same text in policy.last_reload_error, and defenseclaw config validate fails with it.

Apply an edit on purpose in one of two ways:

# A: a new copy, switched to when ready
cp -r ~/.defenseclaw/policies/guardrail/acme-rules ~/.defenseclaw/policies/guardrail/acme-rules-2
defenseclaw guardrail validate-pack ~/.defenseclaw/policies/guardrail/acme-rules-2
defenseclaw guardrail use-pack acme-rules-2

# B: re-pin the edited folder in place
defenseclaw guardrail use-pack acme-rules --repin

--repin validates the folder, shows the old and new digest, names every other scope that selects the same pin (they get the edited pack too), and asks before it writes. If config.yaml changed meanwhile it saves nothing and says config changed, run again. Scripts pass --yes; --json without --yes refuses.

Customise a pack with guardrail.rules

guardrail.rules changes the pack you already use, in memory, without copying it.

~/.defenseclaw/config.yaml
guardrail:
  rules:
    protections: [database-destruction-protection]
    disable: [CMD-REVSHELL-NC]
    enable: [ENT-PASSPORT-US]
    severity_overrides:
      ACME-INTERNAL-DUMP: CRITICAL
    suppressions:
      - id: ACME-SUPP-BUILD-EMAIL
        finding_pattern: JUDGE-PII-EMAIL
        entity_pattern: '@build[.]acme[.]example$'
        reason: Build bot addresses are not personal data
    sensitive_tools:
      - name: acme_crm_lookup
        result_inspection: true
        min_entities_for_alert: 3
KeyWhat it doesCommand
protectionsTurns on opt-in protection packs. Their rules replace base rules with the same ID and add the rest.guardrail protection enable NAME / disable NAME
enableTurns on rules the pack ships off.guardrail rule enable ID
disableTurns off rules.guardrail rule disable ID
severity_overridesSets a rule's severity.guardrail rule severity ID high (default removes it)
suppressionsDrops LLM judge findings (Suppressions).guardrail suppress add / remove
sensitive_toolsAdds or changes a sensitive tool. With result_inspection: true, a result with at least min_entities_for_alert distinct sensitive values (default 1) raises a tool-result-pii-alert. judge_result also sends the result to the PII judge.config set or config.yaml

Some self-protection rules, such as tamper.detector_state_write, cannot be turned off or lowered: rule disable and rule severity do not change them.

Every command takes --connector X and --profile P (both together for a profile connector). rule disable also removes the ID from enable in the same scope, and the reverse, so a disable followed by an enable leaves the config as it was.

defenseclaw guardrail rule disable CMD-REVSHELL-NC
defenseclaw guardrail rule severity CMD-REVSHELL-BASH high --connector codex
defenseclaw guardrail protection enable kubernetes-production-protection --profile contractors --connector codex

The writers and the gateway refuse a layer that names a rule ID the pack does not have, lists a rule under both enable and disable, repeats a suppression ID, or names an unknown protection pack. protection enable also refuses a combination the gateway could not load, such as one over the CEL cost limit. The protection packs are listed on Deterministic detection.

Scopes and layering

Layers apply broadest first, each on the result of the one before, so a narrower scope wins:

  1. Global: guardrail.rules
  2. Connector: guardrail.connectors.<connector>.rules
  3. Profile: guardrail.profiles.<profile>.rules
  4. Profile connector: guardrail.profiles.<profile>.connectors.<connector>.rules

A connector with no profile gets layers 1 and 2. A layer applies to the pack its scope selected, and every rule ID it names must exist in that pack: a global layer that names a rule only acme-rules has makes a connector on strict fail with unknown rule ACME-INTERNAL-DUMP. defenseclaw-gateway policy digest lists one rule_pack: component per scope.

When something is wrong

SituationWhat happens
A pinned pack's digest does not matchThe reload is rejected; the previous policy keeps running (Change a pinned pack).
An unknown rule ID, or a rule under both enable and disableThe writer refuses; a hand edit makes the gateway reject the reload.
rule_pack names an unknown packRefused with config rule pack "nosuchpack" is neither built in (default, strict, permissive) nor a guardrail.custom_packs entry.
A pack file is invalidvalidate-pack exits 1; use-pack changes nothing.
A profile's rules cannot be appliedThe gateway logs the profile and the reason; its subjects get the base rule set.

On a managed device the writers refuse; the pack and rules belong in the admin config.

Suppressions

Suppressions tune the optional LLM judge. They never silence a regex or CEL rule finding (such as SEC-AWS-KEY), and never redact what is sent to the model. To quiet a rule, use guardrail rule disable or rule severity.

ListWhat it doesWhere it lives
pre_judge_stripsRemoves text from the judge's input, for judges in applies_to (all when empty)The pack's suppressions.yaml
finding_suppressionsDrops one judge finding when its ID and the matched text both matchThe pack, or guardrail.rules.suppressions
tool_suppressionsDrops listed PII findings for tools whose name matchesThe pack's suppressions.yaml

Don't blanket-match

Never use .*, .+ or ^.*$ as a suppression pattern. It silences everything the list would report.

Add a finding suppression without copying a pack:

defenseclaw guardrail suppress add ACME-SUPP-BUILD-EMAIL \
  --finding JUDGE-PII-EMAIL --entity '@build[.]acme[.]example$' \
  --reason "Build bot addresses are not personal data"
defenseclaw config get guardrail.rules.suppressions     # check
defenseclaw guardrail suppress remove ACME-SUPP-BUILD-EMAIL   # undo
  • --finding is matched against the whole finding ID, so JUDGE-PII-.* matches every PII finding. --entity is matched against the reported text; left out, it matches every value. --reason is required, and the ID must be new.
  • If --finding is exactly a rule ID in the active pack, the entry is still saved, with a warning that names the commands that change the rule.
  • The command takes no condition; use a pack-level suppression for is_epoch or is_platform_id.

Pack entries the default pack ships, for reference:

policies/guardrail/default/suppressions.yaml (excerpt)
pre_judge_strips:
  - id: STRIP-SYSTEM-SENDER
    pattern: '\b(cli|system|bot|admin)\b'
    context: "System sender metadata injected by agent framework"
    applies_to: [pii]
tool_suppressions:
  - tool_pattern: '^(graph_auth_status|session_status|get_status)$'
    suppress_findings: [JUDGE-PII-USER]
    reason: "Status check tools return expected system metadata"

A strip does not hide a secret: the SEC-* rules still match it. Scope tool_pattern to exact tool names. The recipe catalog lists more shipped entries.

Tier table (Preview)

Preview. A custom pack may carry a tiers.yaml next to defenseclaw-pack.json. It names the pack's tier and sets, for each kind of finding (a row), the least action it gets and how its severity counts, per-user and managed. The shipped packs have none and use the built-in table.

version: 1
tier: strict
rows:
  - id: tiered-strict
    per_user: {floor: block}
    managed: {floor: block}
KeyMeaning
versionAlways 1.
tierdefault, permissive or strict.
rows[].idA row name (list below). A row you leave out keeps its built-in cells; list each row once.
rows[].per_user, rows[].managedThe cell for a per-user install and a managed computer.
cell floorallow, alert, confirm or block: the least action.
cell ceilingalert or record (optional): the most it can raise. record needs floor allow.
cell levelstrue (default) or false. false keeps the finding out of block_at/alert_at; with floor allow it is refused.
cell severityOptional; must equal the built-in row's severity.

Rows: effect-unknown, effect-content-decided, effect-own-key-write, effect-link, effect-read, record, advisory, ask-ticket-request, evaluation-fault, unverified-path, truncated, state-write, shell-protected-file, read-ssh-private-key, read-credential, read-other-home-ssh-private-key, read-other-home-git-credential, read-other-home-credential, tiered-strict, tiered-managed.

The loader refuses the whole pack, naming the row, when a column changes a row's severity, lowers a protected row (evaluation-fault, state-write, truncated, unverified-path, shell-protected-file can only be raised), or turns record-only on or off for a row. validate-pack prints the same message.

See also