VG-DOC · rev 0.1.0PII / DLP redaction firewall for LLM pipelinesMIT · Node 22+
VeilgateDocumentation
Flow 03 / 14Start hereStages 01–04

The pipeline

How Veilgate turns a payload into a routed decision — chunking, the deterministic regex fast-path, speculative Jev evaluation, the priority-ordered policy engine, and re-hydration.

Every redact() call runs a four-stage hybrid pipeline.

INCOMING PAYLOAD · text | JSON | chat[]
01local · zero cost
Chunk + deterministic fast-path
  • split into spans: sentences, fields, chat turns
  • local regex: AWS, GCP, Azure, JWT, SSN, Luhn-valid cards
  • matched spans redacted locally, zero network
spans still needing semantic judgement
02one systemOne() call
Speculative parallel fan-out (Jev)
  • batch remaining spans into one call
  • parallel Noul + Score detectors → calibrated P-values
DetectorResult per span
03priority-ordered
Calibrated policy engineBLOCK > REDACT_AND_FORWARD > REROUTE_LOCAL > ALLOW
04reversible
Execute, re-hydrate, audit
  • vault maps placeholder → original
  • model reply re-hydrated on the way back to the user

Fig. 3.1 Stages of a redact() call. Spans leave stage 01 only if regex could not settle them.

Stage 1 — chunk + fast-path

The payload is split into spans: sentences for text, field values for JSON, message turns for chat. Then a local, zero-latency regex pass flags high-confidence patterns — AWS/GCP/Azure keys, JWTs, SSNs, and Luhn-valid credit cards — and redacts them before any network call.

Because these spans are handled locally, they cost nothing against your Jev budget, and the secret is stripped before it could be sent anywhere — including into Jev’s own input.

Stage 2 — speculative Jev fan-out

Whatever is left (spans that need semantic judgement) is batched into a single systemOne() call. Jev evaluates all five detectors across all spans in one parallel pass and returns a calibrated DetectorResult (each value in [0,1]) per span.

Stage 3 — the policy engine

Each span’s detector values are compared against the active policy. When several rules fire for one span, the highest-priority action wins:

Plaintext
BLOCK (3)  >  REDACT_AND_FORWARD (2)  >  REROUTE_LOCAL (1)  >  ALLOW (0)
Action What happens
ALLOW Span passes through untouched
REDACT_AND_FORWARD Span replaced with a typed placeholder; original stored in the vault
REROUTE_LOCAL Payload diverted to a trusted local model instead of the cloud
BLOCK blocked is set; the caller must refuse to forward

Stage 4 — re-hydration

Redactions are stored in a reversible vault mapping each placeholder to its original value. When the model’s reply comes back, rehydrate() restores the originals so the end user sees real values while the cloud model only ever saw placeholders.

roundtrip.ts
const r = await redact("email Alice Johnson, ssn 123-45-6789");
r.output;                      // "email [REDACTED_PII_1]"  (regex + policy combined)
rehydrate(r.output, r.vault);  // "email Alice Johnson, ssn 123-45-6789"  (exact round-trip)
Note

rehydrate() resolves nested placeholders: when the regex fast-path redacts a substring and a policy rule then redacts the enclosing span, the stored value itself contains a placeholder. Re-hydration loops until stable, so round-trips are exact.