Skip to main content

Rule Chaining

The depends_on field lets you skip rules when a prerequisite rule has not passed.

Basic usage

rules:
- name: has-migration-file
type: regex
pattern: 'migrations/'
match: true
on_fail: warn

- name: migration-has-rollback
type: llm
prompt: |
Does this database migration include a rollback/down migration?
Answer YES or NO.
depends_on: has-migration-file
on_fail: warn

In this example, migration-has-rollback only runs if has-migration-file passed. If the diff contains no migration files, the second rule is skipped entirely.

Why use depends_on?

Without chaining, rules run unconditionally. This can cause false positives when a rule's check is only meaningful in certain contexts.

Common patterns:

  • Skip semantic checks when the relevant file type isn't present
  • Skip style checks when the change is a deletion-only diff
  • Skip test coverage checks when only documentation changed

Skip behavior

When a rule is skipped due to depends_on, it appears in output as:

SKIP  migration-has-rollback     Skipped: depends_on has-migration-file (not passed)

Skipped rules do not affect the exit code.

Chaining multiple rules

A rule can only reference one depends_on target. For multi-condition gating, chain rules sequentially:

rules:
- name: is-python-change
type: regex
pattern: '\.py'
match: true

- name: has-type-hints
type: ast
check: missing_docstring
depends_on: is-python-change

- name: type-hints-reviewed
type: llm
prompt: "Are the type hints in this diff consistent and correct? YES or NO."
depends_on: has-type-hints

depends_on reference resolution

The depends_on value must match the name field of another rule exactly. Rules are resolved in declaration order — you can only depend on rules declared earlier in the file.

Next steps

MCP Server overview to use Comply inside Claude Desktop and Cursor.