VG-DOC · rev 0.1.0PII / DLP redaction firewall for LLM pipelinesMIT · Node 22+
VeilgateDocumentation
Flow 11 / 14ReferenceMonorepo map

Architecture

How Veilgate is built, drawn out — the trust boundary, the one-direction dependency graph, and the two detection subsystems inside the core engine.

Veilgate is one framework-agnostic core engine wrapped in thin integrations. The drawings below show the three things the code is shaped around: a trust boundary that originals never cross, a dependency graph that points one way, and a core that runs two detection subsystems into a single decision.

The trust boundary

Your applicationsupport bot · RAG · agent · gateway
↓ redact(payload, policy)
Integration layer
veilgate-proxy veilgate-ai-sdk veilgate-langchain veilgate-cli
↓ same call, every runtime
Core engine · veilgate
chunk→regex→policy→vault
evaluation call ⟷ TypeSafe Jev · sees the post-regex spans, returns calibrated P ∈ [0,1] — or the mock, which uses fixtures and calls nothing
trust boundary · the protected cloud model only ever sees [REDACTED_*]
Cloud LLM forward · OpenAI / Anthropic / Gemini — redacted payload only Local model reroute · trusted, receives the original
↑ rehydrate(reply) — originals restored for the user

The core runs inside your boundary. It strips regex-detectable secrets locally, then asks Jev to score the spans that are left — Jev (TypeSafe’s evaluator) sees that post-regex text, while the built-in mock sees nothing and answers from fixtures. Only after the decision does the core redact: the frontier cloud model you are protecting receives the placeholder payload and nothing else, while a REROUTE_LOCAL span is handed to a trusted local model in the clear. On the way back, the vault restores the originals for the user.

One direction of dependency

veilgate-policy veilgate-proxy veilgate-ai-sdk · ai 7+ veilgate-langchain · @langchain/core veilgate-cli · + policy
veilgatethe core engine — redact() / rehydrate()

Dependencies run one way. Every package depends on veilgate through a workspace:* link, and nothing depends on an integration — so an adapter can be added or dropped without touching the engine, and the engine has no knowledge of any runtime it is wired into. The one extra edge is the CLI, which also pulls in veilgate-policy to load its presets. Each adapter is small — roughly 150–210 lines — doing only the glue: redact the inbound payload, forward the redacted output, re-hydrate the reply.

Inside the core

spanssentences · fields · chat turns
→
regex fast-pathAWS · GCP · Azure · JWT · SSN · cards — local, zero cost
Jev adapterone systemOne() call, or the mock — calibrated P ∈ [0,1]
→
policy enginehighest-priority action wins
AllowRedactRerouteBlock
vaultplaceholder → original, for re-hydration

Two detection subsystems run into one decision. The deterministic path (regex) settles high-confidence secrets locally, for free; whatever is left goes to the semantic path (Jev, or its mock) for a calibrated judgement. The policy engine turns those signals into one action per span, and the vault keeps every redaction reversible so re-hydration is exact.

Why it’s shaped this way

  • Pure decide-and-transform. The core never calls your destination and never throws on a block — it sets a blocked flag and leaves the refusal to the caller, which keeps it fully testable.
  • Fail-closed. A Jev error never comes back as ALLOW — the affected spans are forced to at least a REROUTE_LOCAL; a reroute with no local handler and a stream that can’t be inspected both refuse the request outright. Never a silent allow.
  • Config, not constants. Model id, price and thresholds are passed in, so a deployment tunes risk without forking the engine.
  • Mock-first. The deterministic runtime ships with the core, so CI and local dev need no network and no key.
Next

See The policy model for how overlapping rules resolve, or The pipeline for the per-stage flow a payload takes through the core.