Consider an illustrative autonomous coding-agent workflow that runs a regex scan before opening a pull request. The scenario below is hypothetical; this benchmark did not run an agent or test whether findings change its behavior.
The linter scans the codebase and immediately flags four "Critical PII Leaks":
host: "127.0.0.1"→ Public IPv4 address detected!adminEmail: "dev-null@example.com"→ Customer email detected!ssn: "000-12-3456"→ US Social Security Number detected!testCard: "4111-1111-1111-1111"→ Visa credit card PAN detected!
An engineer could inspect each finding. An agent could instead treat it as an issue to fix; this example illustrates a possible consequence rather than a measured outcome.
In this hypothetical, the agent might try to remediate the findings:
- It replaces
"127.0.0.1"with"[REDACTED]", crashing the local test server. - It replaces the test-only value with
"[REDACTED]", potentially changing the behavior under test. - It replaces
dev-null@example.comwith"[REDACTED]", breaking unit test email assertions.
If those edits broke an assertion, the test suite could fail and require further work. This release does not measure that loop or its cost.
False-positive findings can add irrelevant tool output. Whether they harm agent task performance remains unmeasured here.
The naive regex baseline: 46 false alarms in the synthetic corpus
For this benchmark, we compared the scanner with six simple unvalidated regex patterns. They are specific baselines included with the package, not a representative survey of pre-commit hooks or DLP tools.
The 101-case synthetic corpus contains 13 documented fake Stripe card format markers, 3 MAC format markers from the IANA documentation range, and 85 negative controls. Labels describe format recognition only; no live personal data is included. There are no positive email, SSN, IPv4, or IPv6 cases.
- Credit-card false positives: 10.
- SSN-shaped false positives: 8.
- Email false positives: 8.
- IPv4 / IPv6 false positives: 15 / 2.
- MAC false positives: 3.
The baseline detected all 16 positive format markers, giving aggregate precision 0.2581 and recall 1.0000. These counts characterize only the supplied fixtures and patterns. The output token cost is measured separately below; the corpus count cannot be converted into a claim about thousands of context tokens.
The solution: deterministic structural validation
The pinned koality-pii-scanner source combines regex candidate extraction with structural and contextual checks. These implementation details do not establish that every actual leak will be detected:
- Credit Cards: Luhn Checksum + IIN Network Ranges: The source checks candidate length, IIN prefixes, and the modulus-10 Luhn checksum. The benchmark includes documented fake card format markers and negative controls; it does not verify active payment accounts.
- Network Addresses: Global-Unicast Checks: The scanner uses Python's
ipaddressmodule to check global-unicast classification, with explicit exclusions in the pinned source. This benchmark has no positive IPv4 or IPv6 cases. - US SSNs: SSA Structure + Contextual Anchoring: For an unformatted nine-digit candidate, the source requires
ssnorsocial securitynearby. The corpus uses the SSA-invalid000-12-3456as a negative control and includes no positive SSN cases. - Emails: RFC 2606 Reserved Domain Suppression: Addresses ending in
.test,.example,.invalid,.localhost, orexample.com/org/netare suppressed at the token level. - Line-Length Skip Behavior and ReDoS Limits: Lines exceeding 10,000 characters are skipped with a
MINIFIED_SKIPannotation. The benchmark did not run an unprotected or adversarial regex, so this is not evidence of ReDoS resistance.
The results: precision, recall, and output-size trade-offs
On the 101 labeled cases, deterministic aggregate results were:
- Precision / recall: 0.8889 / 0.5000 (8 TP, 1 FP, 8 FN).
- Category results: 5 of 13 positive card-format markers detected, and 3 of 3 positive MAC-format markers detected with 1 false positive.
- Baseline: precision 0.2581, recall 1.0000 (16 TP, 46 FP, 0 FN).
The scanner repository has a configured 0.95 corpus-test floor, but that threshold is not a measured result for this publication: observed deterministic recall here is 0.5000. See the pinned corpus-test source.
On a separate five-file synthetic all-negative workload, no findings were expected:
- The baseline emitted 17 false-positive findings (912 serialized JSON tokens); the deterministic scanner emitted none (1 token), 911 fewer tokens (99.89%).
- One run on a host reported as
Windows-10-10.0.26200-SP0scanned 10,000 generated lines in 1.599 seconds (6,253.6 lines/second); one 100-line scan call took 7.48 ms. - A 24 KB overlength line was skipped in 46.656 ms. This does not test or establish ReDoS resistance.
Three rules for agent harness builders
- Measure both false positives and false negatives: On these fixtures the deterministic scanner had higher precision but lower recall than the regex baseline.
- Enforce contextual keyword anchoring on ambiguous numbers: Require variable names or nearby keywords before treating bare integers as sensitive identifiers.
- Evaluate line-length behavior separately: This run observed an overlength skip but did not test worst-case regex runtime.