# Write your first rule

Start from a rule Amiril drafted for an issue, or from a blank rule. Save it, publish it in Shadow, then switch it to Enforce in one environment.

This guide takes one rule from a draft to a rule that blocks calls. It starts in Shadow, which records what the rule would do and lets every call run. [How rules work](/rules#drafts-and-modes) explains the modes.

You need the admin role to save and publish a rule. See [members and roles](/workspace/members).

## Start from an issue [#start-from-an-issue]

1. Open **Issues** and open an issue.
2. Look for a **Suggestion** card on the issue's page. Select **Show rule** to read the rule Amiril drafted. No card means Amiril has no rule for this issue, so [start from a blank rule](#start-from-a-blank-rule) instead.
3. Select **Create rule**.

The rule editor opens with the drafted rule, and a note at the top says it starts in Shadow. Read the rule and change what you need. Then [save the draft](#save-the-draft).

## Start from a blank rule [#start-from-a-blank-rule]

1. Open **Rules** and select **New rule**.
2. Under **Name and description**, enter a **Name**, such as `Payment cap`.
3. Further down the page, the builder shows a blank rule as a form. Below it, select **Edit as text**. Replace the text with this rule:

```amiril
@id("payment-cap")
@sentence("A payment of {amount} is over the 10000 limit")
block (
    agent,
    tool == "issue_payment"
)
when {
    call.args.amount > 10000
};
```

The rule blocks any call to `issue_payment` with an amount over 10000. The editor checks the text as you type and marks any problem on its line. [Learn the rule language](/rules/language) explains each part.

## Save the draft [#save-the-draft]

1. Under **Roll-out**, leave the mode on **Shadow**. It sets the mode for the environment picked at the top of the app, and every other environment starts in Shadow too. You switch a rule to Enforce later, from its page.
2. Select **Save draft**.

The rule's page opens with version 1 saved as a draft. Its **What it says** card shows the sentence the rule gives when it fires.

## Publish the rule [#publish-the-rule]

1. Select **Publish version 1** at the top of the rule's page.
2. Select **Publish version 1** again to confirm.

Version 1 goes to every environment, still in Shadow. Agents running the SDK get it within about a minute.

## Watch what it would catch [#watch-what-it-would-catch]

The rule's page counts the calls the rule would have fired on, in two cards:

- **Would fire, last 24 hours** checks each new run in your [traces](/quickstart/traces) against the rule, so it needs no SDK. It stays at zero until your agent sends traces.
- **Decided in installations, last 24 hours** counts what the SDK decided in your agents. An installation is a service that runs the SDK. The card fills in once an agent running the SDK reports its decisions.

To see results from calls already made, [test the rule on past calls](/rules/test).

## Switch to Enforce [#switch-to-enforce]

Enforce needs the [Team plan](/workspace/billing).

1. At the top of the rule's page, open the mode menu. Its label names the environment picked at the top of the app, such as **Mode in Production**.
2. Choose **Enforce**.
3. Tick **I understand this and want to enforce the rule**, then select **Switch to Enforce**.

Agents running the SDK in that environment start blocking calls within about a minute. Other environments keep their own mode.

To find the runs where the rule blocked a call, open **Traces**. Each such run shows a **1 blocked call** badge, and **Add filter** with **With blocked calls** lists only those runs.

## Next steps

- [Test a rule on past calls](https://docs.amiril.ai/rules/test.md): Replay a rule over the tool calls your agents already made and see which ones it would have fired on, before it blocks anything.
- [Check your agent's tool calls with the Amiril SDK](https://docs.amiril.ai/sdk.md): The Amiril SDK runs inside your agent and checks each tool call against your rules before the tool runs. Pick the guide for your framework and language.
- [Learn the rule language](https://docs.amiril.ai/rules/language.md): Build the rules of a payments agent in short examples, from one amount limit to rules that read earlier calls in the run or the session.
- [Review rule suggestions](https://docs.amiril.ai/rules/suggestions.md): Amiril drafts a rule for an issue and tests it on your past runs. Read the evidence it shows, then dismiss the suggestion or create the rule as a draft.

## More detail

- [Rule settings, modes and publishing](https://docs.amiril.ai/assistant/rules/modes.md): Everything about a rule besides its text: mode, fail mode, if_missing, on_error, ids, versions, publishing, shadow records, backtests, permissions, and the MCP tools and routes for each.
- [Rule errors](https://docs.amiril.ai/assistant/rules/errors.md): Every way rule text or a rule save is rejected: syntax messages, Amiril's own checks, the SDK loader's problem codes, and save and publish refusals, each with its meaning and fix.
