AI data loss prevention for Strands Agents
Users paste sensitive data into AI prompts – card numbers, phone numbers, home addresses, and whole résumés – often without realizing the risk. Once that data reaches your AI provider it can end up in logs, training pipelines, or model outputs, well outside your control.
Arcjet sensitive info detection scans prompt content inside your application, before it reaches the AI provider. Detection runs locally in your own environment, so the raw text never leaves your app: only the decision – whether sensitive data was found – is reported to Arcjet. When something is detected you choose what happens next: block the request, strip the data, or warn the user.
Get started
Section titled “Get started”This example scans a free-text tool argument for personal information before the tool executes. Detection runs locally. Don’t pass opaque IDs such as an order number to the detector.
We assume you already have a Strands Agents project set up. For helper options and denial behavior, see the Strands Agents agent guard.
Install the dependencies:
# Export your Arcjet API key from https://console.arcjet.comexport ARCJET_KEY="ajkey_..."
npm install @arcjet/guard @arcjet/sensitive-info-rampart @strands-agents/sdk zodCreate the example:
import { launchArcjet, localDetectSensitiveInfo } from "@arcjet/guard";import { guardTool } from "@arcjet/guard/strands-agents/v1";import { rampart } from "@arcjet/sensitive-info-rampart";import { tool } from "@strands-agents/sdk";import { z } from "zod";
const arcjet = launchArcjet({ key: process.env.ARCJET_KEY! });const detectPii = localDetectSensitiveInfo({ deny: ["EMAIL", "PHONE_NUMBER", "IP_ADDRESS", "CREDIT_CARD_NUMBER"], backend: rampart(),});
export const saveNote = guardTool( arcjet, tool({ name: "save_note", description: "Save a free-text note on an order", inputSchema: z.object({ orderId: z.string(), note: z.string() }), callback: ({ orderId, note }) => ({ orderId, note }), }), { action: "note.saved", rules: (input) => [detectPii(input.note)], },);Then start or invoke the agent with a test prompt.
Requests appear in your Arcjet dashboard in real time.
This example scans a free-text tool argument for personal information before the tool executes. Detection runs locally. Don’t pass opaque IDs such as an order number to the detector.
We assume you already have a Strands Agents project set up. For helper options and denial behavior, see the Strands Agents agent guard.
Install the dependencies:
# Export your Arcjet API key from https://console.arcjet.comexport ARCJET_KEY="ajkey_..."export ARCJET_ENV=development
pip install "arcjet[strands-agents,sensitive-info-rampart]"Create the example:
import os
from strands import toolfrom arcjet.guard import LocalDetectSensitiveInfo, launch_arcjetfrom arcjet.guard.strands_agents import guard_toolfrom arcjet_sensitive_info_rampart import rampart
arcjet = launch_arcjet(key=os.environ["ARCJET_KEY"])detect_pii = LocalDetectSensitiveInfo( deny=["EMAIL", "PHONE_NUMBER", "IP_ADDRESS", "CREDIT_CARD_NUMBER"], backend=rampart(),)
@tooldef save_note(order_id: str, note: str) -> dict: """Save a free-text note on an order.""" return {"order_id": order_id, "note": note}
guarded_save_note = guard_tool( guard=arcjet, tool=save_note, action="note.saved", rules=lambda arguments: [detect_pii(arguments["note"])],)Then start or invoke the agent with a test prompt.
Requests appear in your Arcjet dashboard in real time.
How detection works
Section titled “How detection works”Sensitive info detection runs on-device with Rampart, a named-entity-recognition (NER) model paired with deterministic recognizers:
- Deterministic recognizers match structured types with validated patterns – card numbers, email addresses, IP addresses, URLs, and Social Security numbers.
- The NER model detects the free-form PII people actually paste into prompts – names, street addresses, phone numbers, and government or financial identifiers. This is the data a structured-pattern matcher can’t catch.
Detection runs entirely on your own infrastructure. Nothing is sent to a third party for analysis, which is what makes this safe to put in front of an AI provider in the first place.
Configure detection
Section titled “Configure detection”Choose which PII to block
Section titled “Choose which PII to block”Use deny to list the entity types to block, or allow to block everything
except the types you list (the two are mutually exclusive). Tune the list to
your app – for a support bot that legitimately collects phone numbers, leave
PHONE_NUMBER out of deny:
See the entity detection table for every type Rampart supports, and for defining your own custom recognizers.
Detect names, addresses, and IDs
Section titled “Detect names, addresses, and IDs”Choose what text to scan
Section titled “Choose what text to scan”Pass the text to scan as sensitiveInfoValue (JS) / sensitive_info_value
(Python) / WithSensitiveInfoValue (Go). For a chat endpoint this is usually
the user’s most recent message.
Pass the full conversation history instead if you want to scan every message,
not only the most recent one – PII can appear earlier in the exchange.
Test before you block
Section titled “Test before you block”Set mode to "DRY_RUN" (JS) / Mode.DRY_RUN (Python) / ModeDryRun (Go)
to log detections without blocking any requests. Run this in production for a
while to audit what PII actually shows up in your prompts, then switch to live
mode once you’re confident in the entity list.
Combine with other protections
Section titled “Combine with other protections”Sensitive info detection controls what data reaches your AI provider. Pair it with the other AI protection layers for full coverage:
- Prompt injection detection blocks hostile instructions and jailbreak attempts.
- AI abuse protection and AI budget control block automated clients and enforce per-user token budgets.
- Agent guards apply PII detection directly inside agent tool handlers and pipelines that don’t route through HTTP. A local policy input keeps the raw string in the SDK while reporting policy evidence to Arcjet.