Skip to content

Agent guards

This example gives an AI agent two tools. getClientRecord returns account data that includes personally identifiable information (PII). Arcjet guards sendEmail, so the model can read the record but cannot send its sensitive fields outside the application. Arcjet checks the model-selected recipient and generated message body before the email provider runs.

What is Arcjet? Arcjet is the runtime security platform that ships with your code. Enforce budgets, stop prompt injection, detect bots, and protect personal information with Arcjet's AI security building blocks.

This guide shows you how to guard an agent tool in your project.

In the Arcjet Console, create an Agent Guard policy with the label email.sent. Add these inputs:

InputExposureType
recipientSERVERString
allowed_recipientsSERVERString list
bodyLOCALString

Then add:

  1. A string-list membership rule requiring recipient to be a member of allowed_recipients.
  2. A sensitive information rule on body that denies BANK_ACCOUNT and ROUTING_NUMBER.

The examples configure the on-device Rampart backend, which detects these entity types locally.

Publish the policy before running the example.

Framework wrappers take action for the same slug you configured as the policy label. Direct guard() calls still use the field name label.

In your project root, install the SDK:

Create a free Arcjet account and follow the instructions to add a site and get a key.

Wrap the send-email tool so Arcjet evaluates the remote policy before the email provider runs.

Keep identity, allowed recipients, and sensitive records on the server. The browser sends only the scenario name.

Each scenario demonstrates a different result from the same guarded tool:

  • Allowed recipient: The recipient is on the allow list and the body has no sensitive data, so sendEmail can reach the email provider.
  • Blocked recipient: The model calls the same tool with an external address. When the adapter maps inputs, the remote membership policy denies the call before the provider runs, and the model receives the denial result.
  • Sensitive information: The recipient is allowed, but the agent first calls getClientRecord and receives test bank account and routing numbers. When the model includes that tool result in the email body, local sensitive information policy blocks sendEmail before the data leaves the application.

Need help with anything? Email support@arcjet.com to get support from our engineering team.

Discussion