Skip to content
Back to skills

Guard Form Invariance Test

ASecurity

Use when you write, change or review a guard that decides on an action from its text (a PreToolUse hook, a command matcher, a permission rule, a classifier in front of a tool call), and when a guard has fired on a permitted action or passed a forbidden one. A guard tested on tidy cases can decide the same action differently when only its surface form changes. State the effect the guard exists for, re-render each labelled case in other forms that keep the effect, run the guard on every renderi...

  • 72 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentspythongoshellbashgitsecurity

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add Tibsfox/gsd-skill-creator --skill guard-form-invariance-test --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Guard Form Invariance Test?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Guard Form Invariance Test
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tibsfox-guard-form-invariance-test/badge)](https://www.skillsdirectory.com/skills/tibsfox-guard-form-invariance-test)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: guard-form-invariance-test
description: >
  Use when you write, change or review a guard that decides on an action from
  its text (a PreToolUse hook, a command matcher, a permission rule, a
  classifier in front of a tool call), and when a guard has fired on a
  permitted action or passed a forbidden one. A guard tested on tidy cases can
  decide the same action differently when only its surface form changes. State
  the effect the guard exists for, re-render each labelled case in other forms
  that keep the effect, run the guard on every rendering by piping the payload
  to it, and treat a decision that moves with the form as a defect. Repair by
  restoring one canonical form in front of the matcher, not by adding a
  pattern per form. A gap found this way is reported to the operator and never
  used. Distinct from guard-refusal-protocol (what to do when a guard refuses
  you) and security-hygiene (general hygiene for self-modification). Backed by
  ToolRosetta (arxiv 2610.24055). Triggers on authoring or reviewing a hook
  and on a guard false positive.
description-frequency: on-demand
user-invocable: true
version: 1.0.0
format: 2025-10-02
triggers:
  - "add a hook that blocks staging files under this directory"
  - "the commit hook fired on a harmless command, fix the matcher"
  - "review this PreToolUse guard before we rely on it"
updated: 2026-11-29
status: ACTIVE
source: arxiv 2610.24055 (ToolRosetta, surface-form invariance of tool-call guards)
---

# Guard Form Invariance Test

A test for anything that reads the text of an action and decides whether it
may run. The decision should follow the effect of the action. This test checks
that it does not follow the spelling.

## Why

Step-level guards for tool-using agents are evaluated on tidy JSON tool calls,
but deployed coding agents act through shell and code tools whose payloads are
strings. ToolRosetta (arxiv 2610.24055) re-renders every candidate action of
two benchmark splits as a Python call, as a shell command, and without the
agent's rationale. The renderings are produced by code and verified by
round-trip parsing, so the request, the history, the label and the action's
effect stay fixed while only the surface form changes. Across eleven guards
with two placebo controls, frontier and strong open-weight guards are stable:
no frontier error rate moves by more than 3.4 points. Four of five specialized
agent guards are not: under the shell form their false-positive rates rise by
21 to 47 points on AgentDojo, and one guard's by 38 points on its own home
benchmark, blocking between a third and nine in ten benign actions. Removing
the agent's rationale moves most guards whose input carries it. A parser that
restores the canonical call in front of the guard removes the effect for these
renderings, by construction. Benchmark accuracy on JSON calls does not predict
a guard's operating point behind a code-acting agent.

The guards on this system are mostly pattern matchers over a command string,
which is the string-payload case with no model in front.
`project-claude/settings-hooks.json` registers PreToolUse guards on Bash and
on Write and Edit; `git-add-blocker.js` and `self-mod-guard.js` have
self-tests under `project-claude/hooks/__tests__/`. A probe of
`git-add-blocker.js` (hook version 1.49.653, as shipped in v1.49.1132) with
eleven payloads, seven that stage a protected path and four that stage a
permitted one, each written a different way, returned the decision the effect
calls for on nine. On the other two the decision moved with the arrangement of
the line, once in each direction. The rewrite that judges each simple command
on the line (commit `dc6c7afc2`, 2026-11-29) decides all eleven by their
effect. `guard-refusal-protocol` treats a guard's fire on form as a defect in
its matcher to report (its step 6), and working around a guard as never an
answer.

## Data classes touched

Reads hook and guard sources and their tests (project-internal). Test payloads
are synthetic. Boundary rules: (1) a guard is exercised by handing a payload
to its script or function, never by attempting the protected action through
the live harness; (2) the deployed copies under `.claude/hooks/` and the hook
registrations in settings are not edited by this skill; (3) a payload uses
placeholder paths and never a real credential.

## How

1. **State the effect.** Write one sentence saying what the guard exists to
   prevent or permit, in terms of outcome: what gets staged, written, deleted,
   sent or executed. Not in terms of text.
2. **Collect labelled cases.** From the guard's own tests, its decision log
   and real commands from the session, build a list of actions, each labelled
   by effect: should block, or should allow. Include permitted actions that
   resemble forbidden ones.
3. **Re-render each case without changing its effect.** Forms worth covering
   for a command guard:

   | Dimension | Variants |
   |---|---|
   | tool | the same write through Bash, Write or Edit; a shell string against a structured call |
   | position | alone; after `cd`; after another command joined by `&&`, `;` or a pipe; before one |
   | path spelling | relative, `./`-prefixed, absolute, with `..`, quoted, unquoted, with a trailing slash |
   | wrapping | an environment prefix, `sh -c`, a subshell, a heredoc, a script file |
   | neighbours | harmless words elsewhere on the line that contain a guarded name (a message, an echo) |
   | rationale | with and without the description or comment the agent attaches |

   Generate the renderings with a small script where you can, and confirm that
   each has the same effect by parsing it. Do not run any rendering as a
   live command, even in a scratch repository: the live guard would judge a
   should-block one, which is an attempt at the protected action, and a
   should-allow one writes or stages real files. Every rendering is tested as
   a piped payload (step 4). A rendering whose effect you have not confirmed is
   not a test case.
4. **Run the guard on every rendering.** Pipe the payload the harness would
   send (for a PreToolUse hook, JSON with `tool_name` and `tool_input` on
   stdin) to the hook script and record the decision. Use a clean environment
   (`env -i PATH=...`), as the shipped self-tests do, so that no override
   variable is inherited. Check where the hook writes its decision log before
   you run it, and keep that out of the repository: `git-add-blocker.js`
   writes under the working directory, so run it from a scratch directory;
   `self-mod-guard.js` writes beside its own script, so run a copy placed in a
   scratch directory.
5. **Read the table by case, across forms.** A case whose decision changes
   with the form is a finding, in either direction: a permitted action blocked
   (the direction of the largest shifts the paper reports) or a forbidden one
   passed. A case decided wrongly in every form is an ordinary rule defect,
   not a form defect.
6. **Repair in front of the matcher.** On a review, stop after step 5 and go
   to step 8; do this step and step 7 only when the operator asked for the fix
   or the task is to write this guard. Restore one canonical form first (split
   a compound line into commands, resolve each path against the working
   directory, strip wrappers, read arguments only from the command they belong
   to), then match on that. Do not add one more pattern per rendering: the
   next rendering is not on the list. What the parser cannot canonicalize, the
   guard treats as its fail-closed case.
7. **Keep the renderings as tests.** Add the cases and forms to the guard's
   test file, so that the invariance is checked on every later edit.
8. **Report; do not use, and do not install.** Give the operator the table and
   the proposed change. A form that passes a forbidden action is reported as a
   defect and never used as a route (`guard-refusal-protocol`). Deploying a
   change, registering a hook or changing a setting stays the operator's
   decision.

### Robustness rule

Judge the guard by whether its decision follows the effect across forms, not
by its pass rate on the cases its author wrote. Those cases share the author's
spelling.

## Confidence / failure model

Labelling a case by effect, and confirming that a rendering preserves it, are
partly **LLM judgments**; steps 4 and 5 are deterministic once the payloads
exist. The paper studies learned guards on two benchmark splits. Applying the
same test to pattern-matching hooks is this skill's extension, supported here
by the probe above and not by the paper, and the paper's figures are for its
guards and renderings. A clean table shows invariance over the forms tried and
says nothing about forms not tried. A canonicalizing parser removes the effect
only for the renderings it handles, and a parser can itself be wrong.
Fail-closed defaults: (a) a rendering whose effect is unconfirmed is dropped,
not counted as a pass; (b) a guard whose decision moves with the form is not
relied on for that effect until it is repaired, and the operator is told; its
refusals still stand (`guard-refusal-protocol`); (c) a repair to an existing
guard that the operator did not ask for is proposed with the table and waits,
and any repair that would make a guard pass a form it blocks today says so
explicitly.

## When to skip

- The guard is a structured allow-list over typed fields with no free text to
  match (an enum, an exact tool name).
- A wording-only change to a guard's message that leaves its matcher
  untouched.
- A guard refused you and you want to proceed: that is
  `guard-refusal-protocol`, not a test session.

## Integration

- **guard-refusal-protocol** — what to do at the moment of refusal; its report
  that a guard "matched the form of a permitted action" is an input case for
  this test.
- **security-hygiene** — hooks are part of the self-modifying surface; work on
  the tracked source and leave deployment to the operator.
- **test-oracle-independence** — label cases by the guard's stated purpose,
  not by what the guard currently returns.
- **cue-anchored-memory** — when it proposes an enforcing check, test that
  check with this before relying on it.
- **llm-call-site-contract** — when the guard is a model call, its reply also
  needs a contract enforced in code.

Files in this skill

  • SKILL.md10.1 KB
  • triggering.test.md2.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.