AI Engineering / White paper

Precision-first context scrubbing: measuring synthetic format-marker detection and finding-output size

A synthetic benchmark compares format-marker detection, serialized finding size, and local scan boundaries for a deterministic scanner and simple regex baselines.

Koality-AssuredOctober 27, 2026Research paper

Autonomous artificial intelligence agents may inspect source files, logs, and configuration through tools that return content to a model context. A broad, unvalidated pattern can flag benign test or documentation values as sensitive; this paper evaluates that possibility using reserved and documented synthetic fixtures rather than live personal data.

False-positive findings may add irrelevant output to an agent's tool context, but this paper's benchmark measures scanner findings and serialized output only; it does not measure actual PII detection, agent behavior, task quality, or ReDoS resistance.

Across 101 labeled format-test and negative-control cases, the deterministic scanner produced 8 true-positive format-marker findings, 1 false positive, and 8 false negatives (aggregate precision 0.8889; recall 0.5000). The simple regex baseline produced 16 true positives and 46 false positives (precision 0.2581; recall 1.0000). Positive labels are 13 documented fake Stripe card values and 3 RFC 9542 documentation-range MAC values, not live personal data; four categories have no positive cases. On a separate five-file all-negative workload, the baseline emitted 17 findings (912 JSON tokens) and the deterministic scanner emitted none (1 JSON token). One run on a host reported as Windows-10-10.0.26200-SP0 measured 6,253.6 lines/second, a 7.48 ms scan call for 100 lines, and a 46.656 ms call that skipped an overlength line. These are fixture- and environment-specific observations, not guarantees.

1. Thesis, questions, audience, and structure

Thesis. False-positive findings can add irrelevant material to an agent's tool context. This benchmark measures findings and serialized output on synthetic inputs; it does not establish an effect on agent behavior. On the tested format markers, the deterministic scanner has higher aggregate precision and lower recall than the simple regex baseline.

Research questions.

  1. What is the empirical error rate of standard heuristic regular expressions when applied to developer source code, mock fixtures, and configuration files?
  2. How do structural validators affect precision and recall on documented synthetic format markers and negative controls?
  3. How does serialized JSON finding size differ on one synthetic all-negative workload, using tiktoken o200k_base?
  4. What scan-call timings and line-length skip behavior are observed in one local run, and what limits do those measurements have?

Audience. Systems architects, security engineers, AI platform teams, and developers building autonomous coding harnesses, pre-commit security gates, and Model Context Protocol (MCP) data-protection layers.

2. The false-positive asymmetry in autonomous AI agents

In a human-reviewed workflow, a developer can inspect a suspected sensitive-data finding and decide whether it represents a real issue. For example, 127.0.0.1 is a loopback address and Stripe documents its test-card values as fake. Review time is not measured here.

In an autonomous agent system, findings may be serialized into a tool response. The scenario below is illustrative, not a measured agent interaction; this benchmark does not test agent behavior or task outcomes.

Potential workflow costs include:

  • Context Window Use: Serialized findings consume tokens; the measured size depends on output format and count.
  • Potential remediation errors: An agent could act on a false finding and alter a valid test value or configuration; this release does not measure whether that happens.
  • Potential workflow interruption: Changes based on false findings may require additional debugging; task completion and repair loops were not tested.
  • Regex runtime risk: This release does not run an unbounded or adversarial regex and does not measure ReDoS behavior.

3. Deterministic architecture: structural validation and contextual anchoring

The pinned koality-pii-scanner source combines regular-expression candidate matching with structural checks, contextual rules, and token-scoped allowlists. The benchmark results below apply only to its stated synthetic fixtures.

  • Credit Cards (is_valid_credit_card): Validates length (13–19 digits), checks allocated IIN network prefixes per ISO/IEC 7812 (Visa, Mastercard, Amex, Diners Club, JCB, Discover), and verifies the modulus-10 Luhn checksum.
  • US SSNs (is_valid_ssn): Verifies SSA randomization rules (area ≠ 000, 666, 900–999; group ≠ 00; serial ≠ 0000). Enforces contextual keyword anchoring requiring the terms ssn or social security within 20 characters of unformatted nine-digit sequences.
  • IP Addresses (is_valid_ipv4 / is_valid_ipv6): Uses Python's ipaddress module to check global unicast classification, with explicit exclusions in the pinned source.
  • Email Suppression: Suppresses RFC 2606 and RFC 6761 reserved documentation domains (.test, .example, .invalid, .localhost, example.com, example.org).
  • Token-Scoped Allowlisting: Matches exact token values against allowlists rather than skipping whole lines, ensuring adjacent real credentials cannot hide behind a test fixture.
  • Pre-Scan Length Boundaries: Lines exceeding 10,000 characters are skipped with a MINIFIED_SKIP diagnostic. This behavior does not prove ReDoS resistance.

4. Empirical evaluation: labeled corpus confusion matrix

We compared the deterministic scanner with simple regex baselines across 101 synthetic cases in supporting/benchmark/corpus/labeled.jsonl: 13 Stripe fake-card format markers, 3 RFC 9542 documentation-range MAC markers, and 85 negative controls. Labels describe format recognition only; there are no positive SSN, email, IPv4, or IPv6 cases.

Detector Positive cases Det. TP/FP/FN Det. Precision Det. Recall Naive TP/FP/FN Naive Precision Naive Recall
credit-card 135 / 0 / 81.00000.384613 / 10 / 00.56521.0000
ssn-us 00 / 0 / 0n/an/a0 / 8 / 00.0000n/a
email 00 / 0 / 0n/an/a0 / 8 / 00.0000n/a
ipv4 00 / 0 / 0n/an/a0 / 15 / 00.0000n/a
ipv6 00 / 0 / 0n/an/a0 / 2 / 00.0000n/a
mac-address 33 / 1 / 00.75001.00003 / 3 / 00.50001.0000
OVERALL 168 / 1 / 80.88890.500016 / 46 / 00.25811.0000

On this corpus, the deterministic scanner produced 1 false positive and missed 8 of 13 card-format markers; the regex baseline produced 46 false positives. Recall is undefined for the four categories with no positive examples, so those cases do not demonstrate detection ability for SSNs, email, IPv4, or IPv6.

5. Context window efficiency and multi-file workload analysis

A separate five-file synthetic all-negative workload contains reserved domains, invalid or documented test values, and a generated overlength asset. No findings are expected; this comparison measures serialized finding JSON only.

Evaluation Metric Naive Regex Engine Deterministic Scanner Impact / Savings
Findings emitted17017 fewer findings
False-positive findings17017 fewer on this workload
Serialized finding JSON tokens (o200k_base)9121911 fewer (99.89%)

6. Performance, throughput, and ReDoS boundary

These are timing observations from one run on a host reported as Windows-10-10.0.26200-SP0, not service-level latency guarantees or a cross-platform study:

Benchmark Task Workload Scope Measured Result
Repository Scanning Throughput 50 files (10,000 lines) 6,253.6 lines/second (1.599s total)
100-Line Standard TypeScript File Single file 7.48 ms
24KB Minified Single-Line Bundle Single line (>24,000 chars) 46.656 ms (skipped via MAX_LINE_LENGTH)

7. Limitations, failure modes, and security trade-offs

Systems engineers must account for known operational boundaries:

  • Address Semantics: A dotted version string that coincides with an address the validator classifies as global may be reported as an IP. This benchmark includes no positive IPv4 cases and does not assess such collisions.
  • Corporate vs. Consumer Email: The standard email rule reports corporate domain addresses; teams should configure internal domain allowlists or use the consumer-restricted companion rule email-public-service.
  • Adversarial Steganography: The engine evaluates line-bounded text; steganographic obfuscation or multi-variable concatenations require multi-stage deobfuscation pre-processors.

8. Conclusion & reproducibility

On the 101 synthetic cases, deterministic aggregate precision/recall were 0.8889/0.5000; the simple regex baseline measured 0.2581/1.0000. On the separate five-file all-negative workload, their finding JSON sizes were 1 and 912 tokens. These fixture-specific results do not measure actual PII detection, agent task quality, or ReDoS resistance.

The package includes the benchmark runner, synthetic fixtures, pinned dependencies, a vendored source snapshot with its MIT license, and SHA-256 manifests. The reproduction guide documents a failed upstream wheel build and explains the bounded snapshot mitigation.