Sensitive information detection for Genkit
Arcjet Sensitive Information Detection protects against clients sending you sensitive information such as personally identifiable information (PII) that you do not wish to handle.
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.Quick start
Section titled “Quick start”This guide shows you how to configure Arcjet for a
1. Install Arcjet
Section titled “1. Install Arcjet”In your project root, install the SDK:
npm i @arcjet/guard genkitpnpm add @arcjet/guard genkityarn add @arcjet/guard genkit2. Set your key
Section titled “2. Set your key”Create a free Arcjet account then follow the
instructions to add a site and get a key. Add it to a .env.local file in your
project root.
Add your key to a .env.local file in your project root.
ARCJET_KEY=ajkey_yourkeyARCJET_ENV=development3. Protect a route
Section titled “3. Protect a route”Create a sensitive info detection rule that scans untrusted text before you
process it. HTTP adapters can use the on-device Rampart backend.
Agent integrations use localDetectSensitiveInfo from the Guard SDK. You can
change which entity types to detect. For details, see the
reference.
Scan a free-text tool argument with localDetectSensitiveInfo /
LocalDetectSensitiveInfo. Don’t pass an opaque ID such as an order
number – those values don’t contain personal information.
import { launchArcjet, localDetectSensitiveInfo } from "@arcjet/guard";import { guardTool } from "@arcjet/guard/genkit/v1";import { genkit, z } from "genkit";
const arcjet = launchArcjet({ key: process.env.ARCJET_KEY! });const ai = genkit({ // Configure your model plugin.});const detectPii = localDetectSensitiveInfo();
export const saveNote = guardTool( arcjet, ai.defineTool( { name: "save_note", description: "Save a free-text note on an order", inputSchema: z.object({ orderId: z.string(), note: z.string() }), }, async ({ orderId, note }) => ({ orderId, note }), ), { action: "note.saved", rules: (input) => [detectPii(input.note)], },);4. Test sending personal info
Section titled “4. Test sending personal info”Start your app and try making a request with an email address in the body of the request:
Start the agent and send a tool argument that contains an email address, such
as note: "Call ada@example.com". The tool does not execute and the model
receives a denial.
Decisions appear in your Arcjet dashboard.
Your logs show this
Arcjet decision ArcjetDenyDecision { id: '', // This will contain the Arcjet request ID ttl: 0, results: [ ArcjetRuleResult { ruleId: '', ttl: 0, state: 'RUN', conclusion: 'DENY', reason: [ArcjetSensitiveInfoReason] } ],...The default response for a request containing unexpected sensitive information is a 400:
< HTTP/2 400< content-type: application/json; charset=utf-8< date: Tue, 09 Jan 2024 13:43:04 GMT< vary: Accept-Encoding< content-length: 72The requests also appear in the Arcjet dashboard.
Do I need to run any infrastructure e.g. Redis?
No, Arcjet handles all the infrastructure for you so you don't need to worry about deploying global Redis clusters, designing data structures to track rate limits, or keeping security detection rules up to date.
What is the performance overhead?
Arcjet SDK tries to do as much as possible asynchronously and locally to minimize latency for each request. Where decisions can be made locally or previous decisions are cached in-memory, latency is usually <1ms.
When a call to the Cloud API is required, such as when tracking a rate limit in a serverless environment, there is some additional latency before a decision is made. The Cloud API has been designed for high performance and low latency, and is deployed to multiple regions around the world. The SDK will automatically use the closest region which means the total overhead is typically no more than 20-30ms, often significantly less.
What happens if Arcjet is unavailable?
Where a decision has been cached locally e.g. blocking a client, Arcjet will continue to function even if the service is unavailable.
If a call to the Cloud API is needed and there is a network problem or Arcjet is unavailable, the default behavior is to fail open and allow the request. You have control over how to handle errors, including choosing to fail close if you prefer. See the reference docs for details.
How does Arcjet protect me against DDoS attacks?
Network layer attacks tend to be generic and high volume, so these are best handled by your hosting platform. Most cloud providers include network DDoS protection by default.
Arcjet sits closer to your application so it can understand the context. This is important because some types of traffic may not look like a DDoS attack, but can still have the same effect. For example, a customer making too many API requests and affecting other customers, or large numbers of signups from disposable email addresses.
Network-level DDoS protection tools find it difficult to protect against this type of traffic because they don't understand the structure of your application. Arcjet can help you to identify and block this traffic by integrating with your codebase and understanding the context of the request e.g. the customer ID or sensitivity of the API route.
Volumetric network attacks are best handled by your hosting provider. Application level attacks need to be handled by the application. That's where Arcjet helps.
What next?
Section titled “What next?”Explore
Section titled “Explore”Arcjet can be used with specific rules on individual routes or as general protection on your entire application. You can set up bot protection, rate limiting for your API, minimize fraudulent registrations with the signup form protection and more.
Get help
Section titled “Get help”Need help with anything? Email support@arcjet.com to get support from our engineering team.