Skip to main content

Stop agents importing across a module boundary

Do this when one part of your code must never import another, such as API handlers reaching straight into the database layer. An Import boundary rule checks each change an agent makes. At Gate or Lock, the Architectural Guard blocks a change that adds a forbidden import, and tells the agent what to do instead.

Who can do this: anyone with the permission to edit compliance, in your own pack.

Plan: needs Compliance and Advanced Compliance on your plan, which bring the Architectural Guard. Without them, Check kind offers no Change rule.

The rest of the page, such as Applies to, works as in Add a rule to a compliance pack. These steps cover only what differs.

  1. Open your own pack's Rules tab and select New rule. Enter a Name; Key fills in from it.
  2. Under Rule, pick a Mode. Gate or Lock blocks the change. Both need Fix guidance: what the blocked agent is told to do instead, such as which module to call.
  3. Under Check, set Check kind to Change rule. Pillar and Level go away, since a change rule is not scored. The bar at the foot of the page now reads Enforced on writes and commits at Gate and Lock.
  4. Set Kind to Import boundary.
  5. In Governed files, enter the files whose imports the rule checks, one glob per line, such as app/api/**/*.py.
  6. In Forbidden modules, enter the modules those files must not import, one per line, such as app.db.*.
  7. Pick the Language the files are written in. Optional: in Exclude, list files to skip even when they match, such as tests/**.
  8. Under Oracles, fill in the two sample changes. Keep Expect at Allowed on the first and Blocked on the second. In each, add the files under Before (leave it empty for a new file) and After. The allowed change adds an import the rule permits; the blocked change adds a forbidden one.
  9. Select Save in the bar at the foot of the page. Jaah checks the samples when you save. When they pass, the new rule's page opens.

If a sample gives the wrong result, the rule isn't saved and the sample shows why. Fix its files or the rule's fields, then save again.