Measured results, reproducible from one command
What would it take to say yes to AI on customer data?
Banks, insurers, retailers, telecoms, hospitals and governments all want the same AI models, and are stopped by the same three questions: where does the personal information go, who can prove what was sent, and what stops a team overspending. This gateway answers all three in the one place every request passes through. It replaces personal details with placeholders before a request leaves and puts them back in the answer, it refuses to send data where the policy says it may not go, it writes every call into a record that cannot be quietly changed, and it enforces each team's budget before the call, not after the invoice. Every one of those costs time, so the cost is measured and published too.
The live record: reading the audit chain's head from this server.
Nothing is modelled in your browser: every number on this page was measured in advance, is a cell of a table the measurement commands write into the public repository's README, and carries a 95% confidence interval there. The two buttons above are the live gateway itself. See how it's built, in four diagrams.
The meeting that stops AI adoption
The technology is rarely what stops a bank, an insurer, a retailer, a hospital or a government department from using AI. A meeting is. Privacy, audit and finance each ask a question, and in most organisations nobody can answer, because the plumbing to answer it was never built.
| The question asked | The usual answer | What the gateway does, measured |
|---|---|---|
| Where does personal information go? | A contract, and a rule telling staff not to paste anything sensitive | Replaces it with placeholders before it leaves: 0 of 1,450 planted details reached the vendor |
| Which country does it travel to? | A region chosen once, at sign-up | Checks every request against a policy and refuses what may not go: 0 of 550 forbidden requests sent |
| What exactly was sent, and when? | Application logs, if somebody added them | A chained record, published daily: 2,400 of 2,400 rewrites caught |
| What did it cost, and who spent it? | The vendor's invoice, weeks later, as one number | Every call costed and counted against its team before it is sent: 0 of 17 calls past a cap reached the vendor |
| How much slower does all that make it? | "Negligible" | Measured per control, at three loads: 27.6 ms at the 99th percentile at 500 requests a second |
It speaks the same protocol as the AI vendors, so an existing application moves onto it by changing one address and one key, and every project in this portfolio that calls a model already calls it through this gateway's library.
One request, in eight steps
The order is the design. The record is written before anything leaves, so a call that crashes halfway is still on the books, and every refusal happens before the network is touched.
- 1DeclareThe caller says what class of data this is. Saying nothing counts as personal.
- 2ScreenFlag text that looks like an attempt to hijack the model.
- 3RedactSwap names and numbers for placeholders, and refuse if any is left.
- 4RouteSend only to a provider and region the policy allows for this data.
- 5BudgetRefuse if the worst-case cost would pass the team's limit.
- 6RecordWrite the ledger row, before anything is sent.
- 7SendCall the vendor, and put the real values back into the answer.
- 8SealChain the finished row into the audit record, anchored daily in public.
How it works, control by control
Four controls, each with its number and the limit of that number
Each part starts in plain language. Where there is more to say for someone who builds these systems for a living, it is folded away under For the technical reader, so a reader who only wants the idea can skip it and a reader who wants the detail loses nothing.
Personal details stay inside
This is a real run of the gateway's redaction engine, the one the live server uses, on a made-up request. The vendor receives placeholders, writes its answer in placeholders, and the person asking gets the real values back. Nobody here exists.
Draft a short reply to Jane Roe about her disputed card charge, claim CLM-2024-1749. Her SIN is 046 454 286 and she asked us to call 709-555-0142 or write to jane.roe@example.com. Confirm we received it and that we will answer within 10 business days.
Draft a short reply to <NAME_LIKE_1> about her disputed card charge, claim <FILE_NUMBER_1>. Her SIN is <SIN_1> and she asked us to call <PHONE_1> or write to <EMAIL_1>. <NAME_LIKE_2> we received it and that we will answer within 10 business days.
Dear <NAME_LIKE_1>, thank you for your message about claim <FILE_NUMBER_1>. We have received it and will answer within 10 business days.
Dear Jane Roe, thank you for your message about claim CLM-2024-1749. We have received it and will answer within 10 business days.
6 placeholders were minted for this request. It also masked "Confirm", which identifies nobody. The second pass masks any capitalised word it cannot vouch for, and that over-masking is measured below. The answer in step 3 is written here for the example, since no model is called when this page is built; steps 2 and 4 are the engine's own output.
It fails closed. Without a language model it recognises only 35.3% of the details on its own, and still nothing leaks, because a second pass masks whatever it cannot vouch for and the gateway refuses to send text it cannot vouch for. The price is masking too much, and on real text that price is high.
For the technical reader: two passes, three corpora, and the limitation measured
- Detection, then a guard. Rule-based recognisers (Canadian SIN with its checksum, provincial health numbers, postal codes, phone numbers, email, file numbers) find spans; a second pass masks capitalised runs and identifier-shaped tokens the vocabulary does not excuse;
outboundrefuses any text in which a value or a shape survives. Detector recall alone is 35.3%; the leak rate after the guard is 0.0% (0.0% to 0.3%). - Through the proxy, over HTTP. 200 generated pages holding 1,450 planted values, sent as
personal, plain and streamed, to an upstream that parses what it received. A value counts as leaked if it is there whole or any three of its digits are. The run is repeated with redaction off and must find every value, so the zero could have said otherwise. - On real text. On the Text Anonymization Benchmark's court judgments it masks 97.1% of direct identifiers, but its precision is 32.2% and it touches 78.4% of the spans annotators marked safe, because its vocabulary is Canadian and knows nothing of British courts. An allow list derived from the benchmark's training split takes that to 41.7%. A deployment in another jurisdiction has to supply its own.
- Reversible, and scoped. Placeholders are consistent within a request and put back on the way out, tolerant of the ways models rewrite them. Only values the caller's own messages carried are put back, for the reason in What did not work.
- Every figure, per entity type, with Wilson intervals: docs/redact.md.
Where a request may go
Every request carries a class: public, internal, personal or sensitive. The policy says which providers and regions each class may reach, and the gateway refuses the rest before anything is sent. This grid is computed from the live configuration by the same function the gateway calls; point at a cell for the reason.
| Provider entry | public | internal | personal | personal, redacted | sensitive |
|---|---|---|---|---|---|
| anthropicnot declared, not declared | may go | refused | refused | refused | refused |
| openainot declared, not declared | may go | refused | refused | refused | refused |
| googlenot declared, not declared | may go | refused | refused | refused | refused |
| openweightsnot declared, not declared | may go | refused | refused | refused | refused |
| locallocalhost, single-region | may go | may go | may go | may go | may go |
| openrouternot declared, not declared | may go | refused | refused | refused | refused |
| kevnot declared, not declared | may go | refused | refused | refused | refused |
| azure-docintelnot declared, not declared | may go | refused | refused | refused | refused |
| foundrynot declared, not declared | may go | refused | refused | refused | refused |
| foundry-canadacanadacentral, global | may go | may go | refused | may go | refused |
| bedrockca-central-1, geo | may go | may go | refused | may go | refused |
| vertexglobal, global | may go | may go | refused | may go | refused |
The policy is the Canadian worked example, written to show the refusal. Unredacted personal data may go only where single-region processing in Canada can be declared, and no hosted vendor here can declare it, so only the local model qualifies. Once the gateway has redacted it, a personal request is judged as internal data and may reach a provider with a declared residency, such as Claude on Amazon Bedrock in Canada.
For the technical reader: declared, never inferred, and never measured
- The class is declared by the caller and never guessed from content. A gateway that classified data itself would be making a compliance judgement no human signed. An absent declaration is
personal, so a forgetful caller is refused rather than exposed. - Residency is the operator's declaration on each provider entry. Not one of the vendors reports where a request was actually processed, so the gateway enforces a declaration and says so, rather than presenting it as a measurement.
- The expected answer comes from an oracle that reads the policy file as plain data and shares no code with the engine. Through the proxy over HTTP: 0 of 220 forbidden cases sent, 0.0% (0.0% to 1.7%).
- docs/policy.md and the policy file.
A record nobody can quietly change
Every call is written into a chain: each record carries a fingerprint of the one before it, so changing any old record breaks every record after it. Once a day the chain's newest fingerprint is published in the public repository, so even the organisation running the gateway cannot rewrite its own history without it showing.
After the last anchor, a competent forger wins, and the page says so. Of rewrites made after the last published fingerprint, 1,193/2,400 = 49.7% (47.7% to 51.7%); 6 of 12 kinds never, by design. No hash chain can do better: there is nothing yet to disagree with. That window is one day, which is why the anchor is published daily.
For the technical reader: what the chain proves, and what it cannot
- The tamper test corrupts a 500-record chain anchored every 50 records, 200 times per kind, from a careless edit to a forger who owns every file, recomputes every hash and edits the ledger to agree.
- Append-only by grant, not only by trigger. On the live server the proxy's database role can add records and cannot change or delete one, and a trigger refuses changes for the owner too.
- The anchor is a GitHub Action that reads
/audit/headevery morning and commits it to anchors/gateway.jsonl, refusing a sequence that goes backwards or a sequence whose fingerprint changed. - An intact chain does not prove the ledger recorded every call; the completeness test in Budgets is that claim. docs/audit.md.
Budgets that refuse before the call
Each team has a monthly budget, and the public demo key a daily one. Before a request is sent, the gateway adds a deliberately pessimistic estimate of its cost to what the team has spent, and refuses if the total would pass the limit. Cost comes from the token counts the vendor returns and a dated price list; a model with no known price is recorded as uncosted, never guessed.
The record survives a crash. 600 of 600 calls left a ledger row under fault injection, across ok, 500, 400, timeout, malformed and a kill mid-call, both modes (100 rows left in flight by the kills, as designed).
For the technical reader: why the row is written before the call
- The usual order loses exactly the calls that matter. Logging after the reply means the only calls that go unrecorded are the ones that crashed, timed out or were killed. Here the row is written before sending, holding its estimate against the budget, and completed after.
- One step for every worker. The hosted gateway runs four processes; the cap check and the row it admits are one call to a function in Postgres under an advisory lock, so two workers cannot both pass a cap only one fits under. A test sends twelve calls at once at a cap that fits three, and three go through.
- The vendor's own console cap is the first line of defence, outside this code. A budget whose only enforcement is the code that might have the bug is not a budget.
What it costs in time
Every control adds delay. Measured on the server that runs the gateway, against a stand-in vendor that always takes 50 ms, with the controls switched on one at a time, at 50, 200 and 500 requests a second: the extra time the gateway adds, five runs each, with a 95% interval across runs.
Each measurement changed the design. The first run stopped at 200 requests a second because the record was written on the request path; moving it off fixed that. A later run blamed the server for failures at 500, and was wrong: the workers had processor time to spare and were queued on the budget check's lock. That check is now a single call inside the database, and every request is answered.
For the technical reader: method, and what the profile found
- Method. k6 at a constant arrival rate, so a slow answer never slows the next request; overhead is the gateway's percentile minus the stand-in's in the same run; a run whose baseline shows a pause on the host is dropped and counted. The server is a 4 vCPU, 8 GB VPS in Beauharnois, Quebec, shared by the generator, the stand-in, four gateway workers, Postgres and Redis.
- The lock. Postgres showed three workers waiting on the admission lock while the fourth held it idle between round trips. One function call in the database took routing at 500 a second from about 13% failed to none.
- A profile under load found four more costs: threads queued on one database connection, the HTTP client's pool walking every connection on each request, a Redis call blocking the event loop, and a missing package that turned an import inside every lock into a search of the disk.
- The cache sheds rather than queues. Embedding a question costs about 19 ms of a core whatever the batch, so past what the server can embed, a request goes upstream as if the cache were off, and says so. Those cells report how many were shed instead of a figure.
- docs/loadtest.md, with every run since the first.
Does redaction make the answers worse?
The question a buyer asks second, and almost never hears answered. Measured with project 03's release gate, the portfolio's measuring instrument: the same questions with and without redaction, paired, across three models, and judged by 03's own calibrated judge.
The real cost is in retrieval. Given a page that cannot answer the question, a redacted model is more likely to answer from memory than to say so. For a pipeline that sometimes fetches the wrong document, that is the case that matters, and it is reported as the result rather than averaged away.
Answers from memory, with the risk beside the saving
Repeated questions can be answered from a store of earlier answers, at no cost. The risk is answering a slightly different question with the confidence of an exact match, so the false-hit rate is published beside the hit rate, and the cache is switched off for personal and sensitive data entirely.
For the technical reader: what goes in, and the injection screen beside it
- Only a bare question the caller marks (
X-Boundary-Cache: question), one store per team, never personal, sensitive, redacted, flagged or streamed, and only a complete answer is stored. The threshold, 0.82, was chosen on one half of the questions and committed before the other half ran. - The injection screen catches 80.8% of attacks on the set its rules were written on and 43.3% on held-out ones; it caught 200 of 200, 100.0% (98.1% to 100.0%) of project 03's templated attacks and flagged 0 of 150, 0.0% (0.0% to 2.5%) ordinary prompts. It flags by default rather than blocking, because blocking's false-positive cost belongs to the policy owner. docs/screen.md, docs/cache.md.
What did not work
Putting every value back into the answer. The first design restored every placeholder in the vendor's reply, including values that came from the application's own instructions rather than from the person asking. Under 03's red team, one model refused every attempt to extract a confidential record, listing the placeholders it would not share, and the gateway then helpfully filled them in: 13 of 200 attacks succeeded through the gateway that had failed against the model. Restoring only the values the caller sent took that to 0 of 200, and it is now the default.
Try it yourself
The gateway on this server takes the same requests as OpenAI's API. The demo page has a public key, limited to US$0.25 a day and one inexpensive model, with a request to copy, a request it refuses, and a repeated question answered from the cache. Every call it makes appears on the dashboard beside the rest of the portfolio's.
What this does not do
It does not decide what is sensitive
The caller declares the class and the gateway enforces the policy for that declaration. Guessing would be a compliance judgement nobody signed.
It cannot verify where a vendor processed a request
No vendor reports it. The gateway enforces the operator's declaration and says that is what it is.
Redaction over-masks on real text
78.4% of safe words touched on court judgments with its Canadian vocabulary. A deployment elsewhere supplies its own allow list.
Text only
Images and audio cannot be redacted here, so they are refused for anything but public data.
One server, one region
Residency here controls where requests may go, not where the gateway runs. It is one 4 vCPU host, and redaction at 500 a second is at its edge.
The cache's saving is not yet measured
What it saves depends on how often real traffic repeats, which needs a replay of real traffic with hand-labelled hits.
How it is engineered
- Python 3.13
- FastAPI
- httpx
- Postgres 17
- pgvector
- Redis
- OpenTelemetry
- Presidio
- bge-small embeddings
- k6
- py-spy
- Hash chains
- Wilson and Newcombe intervals
- Bootstrap
- mypy --strict
- ruff
- pytest
- uv
- Docker Compose
- Caddy
- GitHub Actions
- OVHcloud
- Cloudflare
For the technical reader: the rules the code enforces on itself
- Pass-through mode is inviolable. No retries, no cache, no rewriting; a test compares the bytes handed to the HTTP client with the bytes the adapter built.
- No content in telemetry. The fields a span may carry are listed in code, and attaching anything else raises.
- No vendor SDKs. Plain HTTP with pinned API version headers, because an SDK's changed default is a silent edit to a measurement.
- Never guess a price. An unknown price writes an uncosted row; it never writes an estimate.
- Every reported number carries an interval, and every table is written by the command that measured it. This page reads those tables, so it cannot disagree with them.
How this was built
Design, methodology, evaluation choices and judgement are Peter Parker's, from years of production machine learning in government, where the questions on this page are the ones asked before anything ships. AI coding assistants (Claude Code) were used for implementation and drafting, the way a senior engineer uses them in 2026. Every number on this page is reproducible from the repository.
Glossary
- Anchor
- The newest fingerprint of the audit chain, published somewhere the operator cannot edit, here a public repository, once a day.
- Confidence interval
- The range a measured rate would plausibly fall in if the measurement were repeated. A bare number without one is treated as a defect here.
- Data class
- What a request says it carries: public, internal, personal or sensitive. It decides where the request may go.
- Hash chain
- A list of records in which each carries a fingerprint of the one before, so changing an old record breaks every later fingerprint.
- Percentile
- The 99th percentile is the delay that 99 requests in 100 stay under: it describes the slow requests, which the median hides.
- Placeholder
- A typed stand-in such as <PHONE_1> that replaces a personal detail on the way out and is swapped back on the way in.
- Residency
- Where a provider declares it processes data: in one region, in a group of countries, or anywhere.
- SHA-256
- A fingerprint of a piece of data. Change one character and the fingerprint changes completely.