# Test a rule on past calls

Replay a rule over the tool calls your agents already made and see which ones it would have fired on, before it blocks anything.

A test replays one version of a rule over the tool calls your agents made in the last day, week or month. It uses the same engine the SDK runs in your agent. You see how many calls the rule would have fired on, and which ones. Test a rule before you publish it or switch it to Enforce.

You need a saved rule, and a draft is enough. You also need [traces from your agent](/quickstart/traces), because the test replays the calls they recorded.

## Run a test [#run-a-test]

1. Open **Rules** and open the rule.
2. Scroll down to the **Past calls** card on the rule's page.
3. In the first menu, pick the version to test. The newest is chosen for you, and a version not yet published reads like **Version 2, draft**.
4. In the second menu, pick **24 hours**, **7 days** or **30 days**. The default is 7 days.
5. Select **Test on past calls** in the card. If that version was tested over that window before, the card shows the last result and the button reads **Test again**.

The replay usually takes a few seconds.

## Read the result [#read-the-result]

The **Past calls** card leads with the count, such as "Would have fired on 12 past calls". Under it you see how many calls and runs the test replayed.

The table below lists the calls the rule fired on. Each row shows when the call ran, the agent and tool, the decision and the sentence the rule gave. Select a row to open its run.

The **By agent** table gives the count for each agent. A rule that names one agent counts only that agent's calls.

If nothing would have fired, try **30 days**. If the count is still zero, open a run where the call happened. Check that the rule names the same tool and argument the call used.

## Change the rule and test again [#change-the-rule-and-test-again]

1. Select **Edit rule** and change the rule.
2. Select **Save changes**. It saves a new draft version.
3. Pick that version under **Past calls** and select **Test on past calls**.

When every call in the table is one you meant to stop, [publish that version](/rules/first-rule#publish-the-rule).

## Next steps

- [Write your first rule](https://docs.amiril.ai/rules/first-rule.md): 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.
- [Rule recipes](https://docs.amiril.ai/rules/recipes.md): Complete rules to paste into the rule editor and adapt to your agent. Start from a payment cap, a format check, a required order or a budget per run.
- [How rules work](https://docs.amiril.ai/rules.md): A rule checks each tool call your agent makes and lets it run, flags it or blocks it. Rules run in your agent, and Shadow mode shows what one would do first.
- [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.

## 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.
