VG-DOC · rev 0.1.0PII / DLP redaction firewall for LLM pipelinesMIT · Node 22+
VeilgateDocumentation
Flow 05 / 14PackagesStages 01–0448 tests

Core — veilgate

The Veilgate core engine — the redact() and rehydrate() API, the RedactResult shape, the reversible Vault, and the lower-level chunker, regex and policy exports.

veilgate is the core engine: chunker, regex fast-path, Jev adapter + mock, priority-ordered policy engine, reversible vault, and the redact() / rehydrate() entry points. 48 tests.

terminal
npm install veilgate

redact(payload, options?)

types.ts
type Payload = string | Record<string, unknown> | ChatMessage[];

interface RedactOptions {
  policy?: Policy;                       // default: DEFAULT_POLICY ("balanced")
  mode?: "mock" | "live";                // default: "mock"
  format?: "text" | "json" | "chat";     // default: inferred from the payload
  jev?: Partial<JevConfig>;              // model, baseUrl, apiKey, budgets, pricing
  client?: JevClient;                    // inject a live client or a test double
}

Returns a Promise<RedactResult>:

types.ts
interface RedactResult {
  output: Payload;        // same shape as the input, redactable spans replaced
  decisions: Decision[];  // every decision, in pipeline order (regex first, then Jev)
  vault: Vault;           // reversible placeholder → original map
  blocked: boolean;       // true if any span produced a BLOCK — do not forward
  stats: RedactStats;     // spans, regexRedactions, jevSpans, jevCalls, actions{}
}
example.ts
import { redact } from "veilgate";

const r = await redact("deploy key AKIAIOSFODNN7EXAMPLE now");
r.output;                 // "deploy key [REDACTED_AWS_KEY_1] now"
r.stats.regexRedactions;  // 1  (stripped locally, zero Jev cost)

rehydrate(text, vault)

Replaces every stored placeholder with its original value, resolving nested placeholders (looping until stable), so round-trips are exact.

roundtrip.ts
import { redact, rehydrate } from "veilgate";

const input = "email Alice Johnson, ssn 123-45-6789";
const r = await redact(input);
rehydrate(r.output, r.vault) === input; // true

The vault

vault.ts
import { Vault } from "veilgate";

const v = new Vault();
const p = v.store("Alice", "PII_NAME");  // "[REDACTED_PII_NAME_1]"
v.get(p);                                // "Alice"
v.entries();                             // [["[REDACTED_PII_NAME_1]", "Alice"]]

Placeholders are typed and per-type incrementing: [REDACTED_<TYPE>_<n>].

Lower-level exports

For building on the pipeline directly:

Export Purpose
chunk, inferFormat Split a payload into spans; detect its format
scanText, luhnValid Run the regex fast-path; Luhn card validation
evaluateSpans, DEFAULT_JEV_CONFIG The Jev adapter + its default config
evaluate The policy engine (span detectors → decision)
DEFAULT_POLICY, ACTION_PRIORITY The built-in balanced policy; action ordering
estimateTokens, batchSpans Token estimation and batching for Jev calls
VERSION The package version string

DEFAULT_JEV_CONFIG:

defaults
{
  model: "jev-1.13.0",
  baseUrl: "https://api.typesafe.ai",
  maxTokensPerCall: 6000,
  inputPricePerMTok: 0.042,
}
Tip

To change what gets redacted and how, pass a policy. See The policy model and the ready-made presets in veilgate-policy.