@bulkhead-ai/core

中文文档
0.9.1发布于 2026/07/28MITTypeScriptESM + CJS构建来源已验证近 30 天下载 1999

Cascading content protection engine — PII detection, secret scanning, prompt injection defense

原始使用文档
文档目录8 节
  1. Install
  2. Quick Start
  3. Sanitize JSON-Compatible Documents
  4. What It Detects
  5. Policy Scanning
  6. BERT Layer (Optional)
  7. Documentation
  8. License

Bulkhead Core

Cascading content protection engine -- detects and redacts PII, secrets, prompt injection, and system prompt leakage in text before it reaches LLMs.

Part of the Bulkhead project.

Install

npm install @bulkhead-ai/core

Also available as @floatingsidewal/bulkhead-core via GitHub Packages.

Quick Start

import { createEngine } from "@bulkhead-ai/core";

const engine = createEngine();

// Fast regex-only scan (sub-millisecond)
const result = await engine.analyze("My SSN is 123-45-6789 and key is AKIAIOSFODNN7EXAMPLE");

console.log(result.passed);      // false
console.log(result.detections);   // [{ entityType: "US_SSN", ... }, { entityType: "AWS_ACCESS_KEY", ... }]

// Scan and redact
const redacted = await engine.scan("Call me at 555-867-5309");
console.log(redacted.redactedText); // "Call me at [REDACTED-US_PHONE]"

Sanitize JSON-Compatible Documents

sanitizeDocument() is the recommended API for objects and arrays. It scans keys and string values before mutation, resolves overlapping detections once, uses one consistency map and temporal anchor for the document, and reports pre-treatment detections separately from post-treatment safety.

import { sanitizeDocument } from "@bulkhead-ai/core";

const result = await sanitizeDocument(
  {
    contact: "[email protected]",
    opened: "2026-07-10",
    events: [{ occurred: "07/12/2026" }],
  },
  "eval",
  { localizedDateOrder: "mdy" },
);

if (!result.metadata.postTreatment.safe ||
    !result.metadata.postTreatment.structurallyValid) {
  throw new Error("Sanitization boundary rejected output");
}

console.log(result.value);
console.log(result.metadata.detectedRisk);

Localized dates require an explicit mdy, dmy, or reject-ambiguous choice. Detected dates that are ambiguous, invalid, or unsupported are replaced with [REDACTED-DATE_TIME] by default rather than passing through unchanged.

What It Detects

CategoryCoverage
PII45+ entity types across 20+ countries (SSN, credit cards, IBAN, phone, email, medical IDs, national IDs)
Secrets154 patterns across 13 categories (AWS, Azure, GCP, GitHub, Slack, Stripe, database credentials, private keys)
Prompt Injection16+ patterns (role-play attacks, DAN mode, instruction override)
System Prompt Leakage7+ patterns (prompt extraction, "repeat everything above")

All structured patterns include checksum validation where applicable (Luhn, IBAN mod-97, Verhoeff).

Policy Scanning

import { createEngine, getPolicy } from "@bulkhead-ai/core";

const engine = createEngine({
  enabled: true,
  debounceMs: 500,
  guards: {
    pii: { enabled: true },
    secret: { enabled: true },
    injection: { enabled: true },
    contentSafety: { enabled: false },
  },
  cascade: {
    modelEnabled: false,
    escalationThreshold: 0.75,
    contextSentences: 3,
    modelId: "Xenova/bert-base-NER",
  },
  policy: "strict",
});

const policy = getPolicy("strict");
const { risk } = await engine.policyScan(inputText, policy);
console.log(risk.level);        // "critical" | "high" | "medium" | "low" | "none"
console.log(risk.issues);       // classified issues by category and severity
console.log(risk.testDataFlags); // synthetic/eval data detected

BERT Layer (Optional)

For contextual entities like names, locations, and organizations:

npm install @huggingface/transformers
const engine = createEngine({
  // ...
  cascade: { modelEnabled: true, /* ... */ },
});

const result = await engine.deepScan("Send the report to John Smith at Acme Corp");

The BERT model (~29 MB) downloads on first inference and runs in a worker thread. No GPU required.

Documentation

See the How-To Guide for comprehensive examples and the full documentation for architecture, deployment, and API reference.

License

MIT

版本与发布记录

@bulkhead-ai/core 共发布 11 个版本,首次发布于 2026/04/12;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.9.1latest2026/07/283 个月前
0.9.02026/07/283 个月前
0.7.02026/06/045 个月前
0.6.02026/05/295 个月前
0.5.62026/05/056 个月前
0.5.42026/05/046 个月前

关于 @bulkhead-ai/core 的常见问题

@bulkhead-ai/core 是什么?

Cascading content protection engine — PII detection, secret scanning, prompt injection defense

如何安装 @bulkhead-ai/core?

在项目目录运行 npm install @bulkhead-ai/core,或使用 pnpm add / yarn add / bun add。

@bulkhead-ai/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bulkhead-ai/core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bulkhead-ai/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bulkhead-ai/core 可以商用吗?

@bulkhead-ai/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bulkhead-ai/core 的下载量有多少?

根据 npm 官方下载统计,@bulkhead-ai/core 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,999 次,日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bulkhead-ai/core 还在维护吗?

最新版本 0.9.1 发布于 2026/07/28(3 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 11 个;首次发布于 2026/04/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。