@arcjet/sensitive-info-rampart
v1.17.0
Published
Arcjet sensitive information detection backend powered by the on-device Rampart NER model
Readme
@arcjet/sensitive-info-rampart
Arcjet helps developers protect their apps in just a few lines of code. Implement rate limiting, bot protection, email verification, and defense against common attacks.
This package is the recommended detection backend for Arcjet's
sensitive information rule and Arcjet Guard's
localDetectSensitiveInfo rule. It runs the on-device Rampart
named-entity-recognition model — a ~15 MB quantized ONNX model — to detect
names, addresses, government and financial identifiers, email addresses, phone
numbers, IP addresses, and card numbers. Everything runs locally (Node.js, Bun,
or Deno); no data leaves your environment, and the model weights are bundled so
nothing is fetched at runtime.
Installation
npm install @arcjet/sensitive-info-rampartUsage
Pass the backend to the sensitiveInfo rule. The rest of the rule — mode,
allow/deny, and the result shape — is unchanged.
import arcjet, { sensitiveInfo } from "@arcjet/node";
import { rampart } from "@arcjet/sensitive-info-rampart";
const aj = arcjet({
key: process.env.ARCJET_KEY!,
rules: [
sensitiveInfo({
mode: "LIVE",
// Every Rampart entity is a built-in type — no generic needed.
deny: ["EMAIL", "GIVEN_NAME", "SURNAME", "STREET_NAME", "SSN"],
backend: rampart(),
}),
],
});
const decision = await aj.protect(req, {
sensitiveInfoValue: "My name is Alex Rivera and my SSN is 472-81-0094.",
});Pass backend: rampart() to every sensitiveInfo rule. The rule uses Rampart
only when the backend is configured.
With Arcjet Guard, pass the same backend to localDetectSensitiveInfo:
import { launchArcjet, localDetectSensitiveInfo } from "@arcjet/guard";
import { rampart } from "@arcjet/sensitive-info-rampart";
const arcjet = launchArcjet({ key: process.env.ARCJET_KEY! });
const si = localDetectSensitiveInfo({
deny: ["GIVEN_NAME", "SURNAME", "EMAIL", "SSN"],
backend: rampart(),
});
const decision = await arcjet.guard({
label: "tools.summary",
rules: [si(userMessage)],
});Detected entities
The model detects: GIVEN_NAME, SURNAME, EMAIL, PHONE_NUMBER, URL,
TAX_ID, BANK_ACCOUNT, ROUTING_NUMBER, GOVERNMENT_ID, PASSPORT,
DRIVERS_LICENSE, BUILDING_NUMBER, STREET_NAME, SECONDARY_ADDRESS,
CITY, STATE, and ZIP_CODE.
Deterministic recognizers additionally detect EMAIL, URL, IP_ADDRESS, and
SSN. Labelled candidates cover 6–17 digit bank accounts, checksum-valid
ABA routing numbers, numbered apartment or suite units, and named US states
in a state field. These candidates retain the exact value span; an ABA checksum
does not prove that a number was issued. Phone numbers are left to the model because their digit shape
overlaps with financial and government identifiers. On overlapping text the
recognizer result wins over the model.
CREDIT_CARD_NUMBER is detected by Arcjet's own card detection from
@arcjet/analyze, the same as the default backend, whatever recognizers are
configured. The model's card labels are not used.
The full set is exported as rampartEntities:
import { rampart, rampartEntities } from "@arcjet/sensitive-info-rampart";
sensitiveInfo({ deny: rampartEntities, backend: rampart() });Options
rampart({
// Run a GPU instead of CPU when the runtime supports it.
device: "webgpu",
// Minimum confidence for a model token to count (default: 0.5).
threshold: 0.6,
// Longest input to scan, in UTF-16 code units (default: 100_000).
maxInputChars: 50_000,
// Add or replace the deterministic recognizers. This is the extension point
// for custom detection with this backend.
recognizers: [
...defaultRecognizers,
(value) => /* DetectedSpan[] */,
],
});The model loads once on first use and is reused for every request. To detect custom patterns, add a recognizer.
[!NOTE] Inference runs in the request path, so its latency affects request handling. The model performs best on Latin-script text; see the model card for accuracy and language details.
Input size limit
Scan time grows with input length, so the backend caps how much text it scans.
maxInputChars sets the cap in UTF-16 code units, the unit of a JavaScript
string's length. The default is 100_000. It must be a positive safe
integer; rampart() throws otherwise, and there is no unlimited setting.
The rule denies longer input without scanning any of it. It does not scan the first part and let the rest through:
- With the
sensitiveInforule, the result has conclusionDENYand anArcjetErrorReasonwhose message gives the input length and the limit, sodecision.isDenied()istrueanddecision.reason.isSensitiveInfo()isfalse. InDRY_RUNmode the rule logs a warning and doesn't deny. - With
localDetectSensitiveInfo, and with sensitive-info inputs in a remotely configured Guard policy, the rule reports aDENYwith no detected entities. Guard enforces it when the rule isLIVE.
Each denial logs one warning with the input length and the limit. The text itself is never logged.
Longer text and PHI
Rampart suits typical request fields. If your app accepts longer text, raise
maxInputChars to fit it when the extra latency fits your budget, or send the
text as a SERVER input to the server-side sensitive information detector in
an agent guard policy, which screens values up to about
100 KB. Only the server-side detector detects the PHI types, such as
medical record numbers, so screen PHI with a server input.
The server-side detector allows up to 3 seconds to screen a value over 2 KB,
and a live rule fails closed if the scan doesn't finish. Pass timeoutSeconds
above 3 to guard() (the default is 2) so the client doesn't stop waiting
first, and deny when decision.hasFailedOpen() is true.
Each guard() call screens up to two SERVER inputs longer than 2 KB, and a
third fails a live rule closed. To screen text longer than about 100 KB, split
it into parts and screen each part in its own call.
Custom runtimes
The bundled loader needs a filesystem and dynamic module loading, which edge
runtimes such as Cloudflare Workers don't provide. Pass classify to replace
the loader alone: it receives one chunk of text, already windowed to the model's
input budget, and returns the model's raw tokens for that chunk. Everything
else — normalization, windowing, offset reconstruction, token aggregation, and
overlap resolution with the recognizers — stays in this package, so detection on
a custom runtime matches detection on Node.js.
import { rampart } from "@arcjet/sensitive-info-rampart";
import type { RawToken } from "@arcjet/sensitive-info-rampart";
const backend = rampart({
async classify(value: string): Promise<RawToken[]> {
// Run the model with your runtime's own ONNX bindings, then return one
// token per wordpiece.
return [{ entity: "B-SURNAME", score: 0.98, word: "rivera", index: 4 }];
},
});Each token needs the raw BIO label (entity), its confidence (score), the
wordpiece text (word, keeping any ## continuation prefix), and its position
in the sequence (index). Character offsets are reconstructed from word, so
you don't have to provide start and end.
To replace detection entirely — including windowing — pass runModel instead,
which takes the whole value and returns spans.
Either way, card numbers come from Arcjet's card detection in
@arcjet/analyze, which runs WebAssembly. A custom runtime must support
WebAssembly. If card detection, the model or a recognizer fails, the backend
reports the error rather than a clean result. The error carries what the rest of the scan denied,
and the sensitiveInfo rule still denies those, with the error as the reason;
with nothing denied, the rule result is an ERROR.
Bundlers and frameworks
By default this package loads a native ONNX runtime
(@huggingface/transformers / onnxruntime-node) and reads its bundled model
weights from disk at runtime, so it must not be bundled by a server build. That
loader requires a server runtime with filesystem and native-addon access
(Node.js, Bun, or Deno); to run the backend elsewhere, supply your own
classifier — see Custom runtimes.
Next.js
Mark the package (and its native dependencies) as
server external packages
so Next.js loads them from node_modules at runtime instead of bundling them:
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
serverExternalPackages: [
"@arcjet/sensitive-info-rampart",
"@huggingface/transformers",
"onnxruntime-node",
],
};
module.exports = nextConfig;Any route handler that uses the backend must run on the Node.js runtime (the default for route handlers), not the Edge runtime:
// app/api/protect/route.ts
export const runtime = "nodejs";License
The source code of this package is licensed under the Apache License, Version 2.0 © Arcjet Labs, Inc.
Bundled model
This package bundles the Rampart model and its tokenizer/configuration
files (under models/rampart/), which are a separate work:
"Rampart: Client-side PII redaction for AI assistants" by National Design Studio, Copyright 2026 National Design Studio, licensed under CC BY 4.0. The files are redistributed unmodified.
The full model license is in models/rampart/LICENSE
and the attribution is recorded in NOTICE. If you redistribute this
package or the model files, retain that attribution as required by CC BY 4.0.
@misc{rampart-2026,
author = {National Design Studio},
title = {Rampart: Client-side PII redaction for AI assistants},
year = {2026},
url = {https://huggingface.co/nationaldesignstudio/rampart},
}