Regex first, judgment model second: leak recall went from 0.25 to 0.95 for about $1 a month
Our in-house regex caught 0.25 of the confidential items in a test set. With a judgment model added behind it, 0.95. That model costs about $1.1 a month at 2,000 checks a day, answers in a 146 ms median from Tokyo, and n
Our in-house regex caught 0.25 of the confidential items in a test set. With a judgment model added behind it, 0.95. That model costs about $1.1 a month at 2,000 checks a day, answers in a 146 ms median from Tokyo, and never saw the values the regex had masked.
The last part is the design. Here is how we measured it in promptflow, our multi-AI service, on 120 synthetic Japanese items with 3 runs each, and how we then shipped it in a form that changes no routing decision.
The short version
- The regex runs first, the judgment model second. The model only sees masked text and adds what format alone cannot show.
- Misses dropped sharply. Leak recall went from 0.25 (regex alone) to 0.95 with TypeSafe jev-preview behind it. Difficulty routing went from 0.25 to 1.00 exact.
- Speed and cost fit on every request. jev-preview: 146 ms median, $1.1β1.4 a month at 2,000 checks a day.
- We shipped it in shadow mode. The current rule still decides. jev's answer is only recorded, with judgment fees capped at $2 a month.
Why the regex goes first
promptflow makes two cheap, fast judgments on every request:
- Confidential content. Enterprise plans get a Security Filter. Regex finds and masks five kinds of values, such as emails, phone numbers, card numbers and API keys, before anything goes to an AI provider.
- Difficulty level. Auto mode picks a model tier from L0 to L3. For ordinary chat, today's rule is "over 600 characters β L2, otherwise L0."
Regex sees values by their shape. It cannot see that a paragraph describes an unannounced acquisition. A judgment model, a small model that answers yes/no or picks a level and returns a probability, can.
But sending raw text to an outside AI in order to decide whether it is safe to send to an outside AI defeats the purpose. So the order was fixed before anything was measured: our own regex masks first, and the judgment model only gets the masked text. Only fixed-format values can be masked, so contextual secrets still reach the judgment model, which makes the choice of vendor part of the design (see the shipping section). The benchmark used exactly that pipeline.
What we compared
| Candidate | What it is | Input price per 1M tokens |
|---|---|---|
| TypeSafe jev-latest / jev-preview | Judgment model; answered as jev-1.13.0 and jev-1.14.0 | $0.042 (output free) |
| OpenAI Decisions API | Judgment model (gpt-6-luna), public beta | $0.10 (output not billed) |
| gpt-5.4-nano / gpt-5.4-mini | Ordinary chat models forced to answer in strict JSON | nano $0.20, mini $0.75 (output billed) |
The data: 120 synthetic Japanese items written for this test. 80 for the confidential task (40 confidential, 40 not) and 40 for difficulty (10 per level). Two AI reviewers labelled them independently and reached agreement on all 120. The same items were also machine-translated into English.
Every candidate got the same question, 3 runs per language, called from Tokyo. That was 4,320 model calls, and the whole test, translation included, cost about $0.31 in API fees.
Leak recall: 0.25 to 0.95
We scored the confidential task in its production shape. Whatever the regex masked counts as caught, and the model can only add to it.
Regex alone catches the 10 confidential items whose values have a fixed format, out of 40: 0.25. Adding jev-preview gives 0.95, the Decisions API 0.92. gpt-5.4-mini reached 1.00 and missed nothing, at more than 10x jev's cost and about 5x the latency.
Why not score the models on their own? An item with an API key reaches the model as apiKey: '<PII_1>', because the regex has already masked it. "No leak here" is the right answer to that text. The number that matters in production is regex and model together.
Two items were missed by all three judgment models. One was an investment memo that described an acquisition target without naming it. The other said, in effect, "there is an auth-bypassing backdoor we did not report to the auditors." That one is a compliance violation more than a data leak, so it fell outside the question we asked. Judgment models are built to be composed from small questions, so the fix is a second question such as "does this describe an unreported violation?"
The version mattered too. jev-latest (1.13) missed three items, a revenue-recognition correction, customer cost data under NDA, and a policy on an undisclosed vulnerability; jev-preview (1.14) caught all three. The only leak that the Decisions API alone missed was a pre-filing patent detail. That is one more reason to pin the version in production: a version change swaps which items get caught. How to compare results item by item is the subject of "Before you switch AI models, compare pass/fail task by task."
jev-preview's probabilities also looked usable for a block / warn / allow policy. No confidential item scored below 0.3, and no benign item scored 0.6 or above. Those cut-offs were fitted on the same data, though, so they need to be re-measured on real traffic.
The Decisions API spreads its probabilities differently. It is sharp below 0.1 and above 0.8, but 12 of its 240 answers on confidential items landed between 0.1 and 0.2. "Allow below 0.2" would let leaks through with that model. Cut-offs belong to a model and a version, not to the task.
Difficulty routing: 0.25 to 1.00
Both jev versions got all 40 items right in all 3 runs. The Decisions API rated the same 2 items one level too low every time, for 0.95. No model was ever off by two levels.
The rule's 0.25 is partly the dataset's fault. The longest Japanese item is 265 characters, so the rule always answers L0, which matches chance. Long prompts and pasted documents were not tested.
Language mattered in an unexpected direction. TypeSafe's docs say Chinese, Japanese and Korean are handled less well than English. On our Japanese data, jev-preview did not miss more. The Decisions API, on the other hand, dropped to 0.80 on difficulty in English, rating five hard requests one level too low in every run. Vendor claims about languages are worth checking on your own data.
Speed, cost, and answers that change between runs
jev's servers are across the Pacific; from Tokyo, opening the connection alone takes about 140 ms. Even so, jev-preview's median was 146 ms. The chat models sat at 750β800 ms regardless of size, which is the time it takes to generate tokens.
At 2,000 judgments a day, jev costs $1.1β1.4 a month and the Decisions API $1.7β2.0. Neither is a reason to hesitate.
On list price, jev is 2.4x cheaper than the Decisions API. The real gap is only about 1.5x, because the same Japanese prompt counts as 459 tokens on jev and 278 on the Decisions API. Budget from measured tokens, not characters.
Stability matters more than either. Sent the same input three times, gpt-5.4-nano changed its answer on 14 of 80 items; jev-preview on 1. A security check that flips on the same text is hard to trust.
The Decisions API also showed it is a beta. On 2 of 720 calls it returned HTTP 200 with an empty body, and one run had a 95th-percentile latency of 3.4 seconds. Any integration needs a timeout and a decision, per call site, on which way to fail.
Shipping it: record only, change nothing
We started with the difficulty task. Switching the rule outright would send more requests to the pricier L2 and L3 models, and the benchmark data was synthetic. So the current rule keeps deciding, and for the same request we record what jev would have said.
-
jev-preview, with the version pinned. We send
jev-1.14.0. During the test, thejev-latestalias still answered as 1.13 after the newer version shipped. - Only regex-masked text is sent. We do not store the text. The regex only masks five kinds of values with a fixed shape, though. Names, company names and contextual secrets such as an unannounced acquisition still reach the judgment model. Requests from users in a company organization, or whose organization cannot be determined, are skipped.
- A 3-second cutoff, and failures change nothing in the answer. Users never see the judgment. Responses can take up to a little over 3 seconds longer, and the records measure that too.
- A cap on judgment fees. Production gets $0.056 a day, every other environment $0.001. Across all three environments that stays at or under $1.80 in a 31-day month, inside the approved $2.
- A feature flag can turn it off at any time.
Later we added a second question to the same single call: the request type (text, Office, image, video, audio). The path that would let jev's type answer drive real decisions is in the code with its flag off. It gets turned on only after more than 5,000 recorded judgments, a look at how often jev agrees with the current classifier, and an explicit approval. All of these changes are in promptflow's release promptflow-web-v91.
What the records must show before anything switches
After at least 14 days and at least 5,000 recorded judgments, we aggregate and look at five things:
- Level distribution and agreement. How L0βL3 split, and where jev disagrees with the current rule.
- Added latency. Median and 95th percentile, plus timeout and error rates.
- Actual spend. Dollars per day, and the ratio of our up-front estimate to what was really spent.
- Cost of switching. How much more the pricier tiers would cost if the routing followed jev.
- Skew. If skipped requests (company organizations and unknowns) exceed 30%, we hold the conclusion and revisit who gets sent.
What choosing TypeSafe adds
Which vendor to use is not something the numbers settle. OpenAI is already one of the providers our requests go to, so the Decisions API adds no new recipient. TypeSafe adds a US company that receives the masked text, and masked text still carries names and contextual secrets. With 120 synthetic items, a few points between judgment models are within noise; what is clear is the gap between the current rule and any of them. We chose jev-preview. Where the judgment models clearly differed was speed (146 ms vs 222 ms median) and the Decisions API being a beta that returned empty bodies. Masking format-detectable values before sending stays the same whichever vendor we use.
Wrapping up
Do not send raw text out to find out whether it is safe to send out. Mask it with your own regex first, then ask the judgment model.
jev-preview behind the regex took leak recall from 0.25 to 0.95 and difficulty routing from 0.25 to 1.00, for a dollar or two a month. We shipped it to record its answers next to the current rule, so that real prompts, not synthetic ones, show how it does.
Terms
- Judgment model. An AI model built to answer yes/no or pick one of a fixed set of levels, with a probability. It does not write prose, so it is fast and cheap.
- Regex (regular expression). A way of finding text by its pattern. Good for values with a fixed shape, such as email addresses or card numbers.
- JSON. A structured text format of named fields and values that programs read easily.
- Token. The unit an AI model counts text in. Pricing is per token, and models count the same text differently.
-
Masking. Replacing a found value with a placeholder like
<PII_1>, so the original never leaves. - Recall. Of the items that really are confidential, the share the check flagged. 1.00 means nothing was missed.
- Exact match. The share of requests whose predicted level (L0βL3) equals the correct level.
- p50 / p95. The median latency, and the latency that 95% of calls stay under.
- Shadow mode. Sending the same input to a new mechanism and only recording its answer, while the production decision, response and billing stay unchanged. Users do not see it.
This series shares practical knowledge from building and operating our flagship SaaS, Prompt Flow Studio, and other AI products. If you are interested, please like and follow.
Prompt Flow Studio is a multi-AI workspace where you use, compare, and debate multiple AIs on one screen. Learn more at https://prompt-flow.studio
Our other products are listed at https://www.eln.ne.jp/products
EarthLink Network builds its own products to run the whole company on AI β each one born from a need along the way. See the full index of what we build:
β The 18 products EarthLink Network builds in-house
For more about the company and each product, visit www.eln.ne.jp.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.


