# Block your first tool call

Run a rule that caps payments, then watch the Amiril SDK block a tool call on your laptop. You need no account and no API key to try it.

At the end of this page, a rule stops a payment of 20000 before the tool runs. A short script stands in for a payments agent with an `issue_payment` tool, and nothing leaves your laptop.

## Before you start [#before-you-start]

- The Amiril SDK needs Python 3.11 or later, or Node.js 24 or later. Node.js 24 runs a TypeScript file directly, with no build step.
- An empty folder to work in.

<Steps>
<Step>
### Install the SDK [#install-the-sdk]

```bash tab="Python"
pip install amiril
```

```bash tab="TypeScript"
npm init -y
npm pkg set type=module
npm install @amiril/sdk
```
</Step>

<Step>
### Save the rule [#save-the-rule]

Save this file in your folder as `payment-cap.rules.json`. It blocks any call to `issue_payment` unless the amount is above 0 and at most 10000.

```json title="payment-cap.rules.json"
{
  "schema": "amiril.rules/1",
  "ruleset_version": "quickstart-1",
  "rules": [
    {
      "id": "payment-cap",
      "version": "1",
      "mode": "enforce",
      "description": "A payment must be above 0 and at most 10000",
      "target": { "tools": ["issue_payment"] },
      "assert": { "and": [{ ">": [{ "arg": "amount" }, 0] }, { "<=": [{ "arg": "amount" }, 10000] }] },
      "action": "block"
    }
  ]
}
```

You do not need to change it. JSON is the form the SDK runs, and a local file lets you try it without an account. In your own project you write the same rule as [rule text](/rules/language) in the web app, and Amiril turns it into this JSON for the SDK.
</Step>

<Step>
### Save the agent script [#save-the-agent-script]

Save this beside the rule. It starts the SDK with the rule file and asks for two payments, 500 and then 20000.

```py tab="Python" title="agent.py"
import amiril
from amiril import plain

# #region setup
amiril.init(rules_file="payment-cap.rules.json")  # no API key, so nothing leaves your laptop

agent = plain.Agent("payments")

@agent.tool
def issue_payment(payee: str, amount: float) -> str:
    """Send a payment to a payee."""
    return f"Paid {amount} to {payee}"
# #endregion setup

# #region run
with agent.run(session_id="laptop-1") as run:
    run.turn()
    print(issue_payment(payee="Acme", amount=500))

    run.turn()
    refused = issue_payment(payee="Acme", amount=20000)  # the tool does not run
    print(refused["message"])  # what the model reads in place of the result
# #endregion run
```

```ts tab="TypeScript" title="agent.ts"
import { init } from "@amiril/sdk/node";
import { Agent } from "@amiril/sdk/plain";

// #region setup
init({ rulesFile: "payment-cap.rules.json" }); // no API key, so nothing leaves your laptop

const agent = new Agent("payments");

const issuePayment = agent.tool(
  { name: "issue_payment", description: "Send a payment to a payee." },
  async ({ payee, amount }: { payee: string; amount: number }) => `Paid ${amount} to ${payee}`,
);
// #endregion setup

// #region run
await agent.run({ sessionId: "laptop-1" }, async (run) => {
  run.turn();
  console.log(await issuePayment({ payee: "Acme", amount: 500 }));

  run.turn();
  const refused = await issuePayment({ payee: "Acme", amount: 20000 }); // the tool does not run
  if (typeof refused !== "string") console.log(refused.message); // what the model reads in place of the result
});
// #endregion run
```

`agent.tool` hands your tool function to the SDK, which checks each call before the function runs. If a rule blocks the call, you get back an object with a `message` instead of the tool's result. `agent.run` marks one run of the agent. `run.turn()` marks a turn, the point where a real agent's model would pick its next call. Rules that count calls or check their order use these marks.
</Step>

<Step>
### Run it [#run-it]

```bash tab="Python"
python agent.py
```

```bash tab="TypeScript"
node agent.ts
```
</Step>
</Steps>

## See the result [#see-the-result]

```text
Paid 500 to Acme
The call to issue_payment was not performed. Rule payment-cap blocked it: A payment must be above 0 and at most 10000 (amount 20000). Do not retry this call with different arguments or achieve the same outcome another way; tell the user it was not performed.
```

The payment of 500 runs, but the payment of 20000 never reaches the tool. The script gets the message on the second line instead, built from the rule's `description`. In your own agent, the model reads this message in place of the tool's result. It tells the model not to retry and to tell the user the payment was not made.

To run your workspace's rules in place of the file, see how to [connect the SDK to your workspace](/sdk/no-framework#connect-to-your-workspace).

## Next steps

- [Add Amiril to an agent without a framework](https://docs.amiril.ai/sdk/no-framework.md): Check each tool call of an agent loop you wrote yourself against your rules, in Python or TypeScript, with the core SDK package and nothing else.
- [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.
- [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.
- [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.

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