Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 4 min read

Amazon Bedrock Guardrails on Malaysian ID numbers: what it catches, and where a regex stops

TL;DR. I ran Amazon Bedrock Guardrails' sensitive-information filter over 1,000 synthetic Malaysian documents from MyPII-Bench. Guardrails has no built-in type for the MyKad (national ID) or SSM company numbers, so I add

TL;DR. I ran Amazon Bedrock Guardrails' sensitive-information filter over 1,000 synthetic Malaysian documents from MyPII-Bench.
Guardrails has no built-in type for the MyKad (national ID) or SSM company numbers, so I added three custom regexes written from the
official formats. On cleanly formatted MyKad numbers it caught all 67 of 67. It caught none of the 165 noisy ones: OCR slips like
l for 1, and numbers split across a line. A one-line change to the separator brought the line-split cases from 0/70 to 70/70 and
added one false positive. One configuration detail matters more than any regex: with action alone, the filter did not run on
source=INPUT at all.

Why this matters

Malaysian text carries identifiers that global PII detectors don't know: the 12-digit MyKad (YYMMDD-PB-####, where PB is one of
86 place-of-birth codes), 12-digit SSM company registration numbers, and Malaysian phone formats. If you put Guardrails in front of
a model that sees Malaysian customer data, you need to know which of these it will mask.

Setup

  • ApplyGuardrail with source=INPUT and outputScope=FULL, region ap-southeast-2.
  • Built-in PII types: PHONE, EMAIL, NAME, ADDRESS, AGE, CREDIT_DEBIT_CARD_NUMBER (action ANONYMIZE).
  • Custom regexes, written from documented formats and frozen before the run: MyKad with all 86 JPN place-of-birth codes, SSM 12-digit (year + entity code 01–06), and the old SSM form (123456-X).
  • Benchmark: ujian4 split of MyPII-Bench, 1,000 synthetic documents in Malay, English and Manglish, labelled for three entities. The split is deliberately hard: it includes OCR noise inside numbers, numbers broken by a newline, East Malaysian landlines, and MyKad-shaped numbers in non-ID contexts (member or account numbers) that are labelled not PII.

Two things that tripped me up (useful even if you skip the numbers)

  1. Set inputEnabled and inputAction explicitly. My first guardrail version listed each entity with action: ANONYMIZE only. ApplyGuardrail with source=INPUT then returned action: NONE and zero sensitive-information units, while the same text with source=OUTPUT was masked. Adding inputEnabled: true, inputAction: "ANONYMIZE" (and the output pair) on every entity and regex fixed it. If your input-side masking seems to do nothing, check this first.
  2. New accounts created through the console's Projects flow restrict regions. CreateGuardrail was denied by a service control policy outside the project's selected region (I hit it in ap-southeast-1), while ApplyGuardrail itself was allowed. The error says "explicit deny in a service control policy", which looks like a permissions bug but is a region choice.

Results (exact-match F1)

System All entities MyKad Phone SSM
Guardrails, frozen regexes 0.470 0.245 0.595 (0.803 partial-overlap) 0.509
Guardrails, tolerant separator (exploratory) 0.528 0.444 0.595 0.509
MyPII 1.1.0 (my detector) 0.980 0.941 1.000 1.000

The headline row is misleading on its own. The breakdown is the useful part:

  • MyKad by surface form. Dashed, spaced and plain 12-digit forms: 67/67 caught. OCR letter slips: 0/95. Split across a line: 0/70 with the frozen regex, 70/70 after changing the separator from [- ]? to [-\s]{0,4}, at the cost of one extra false positive. I did not try to handle OCR slips, because that would be tuning to a test set I had already seen.
  • False positives. Most MyKad false positives (131 of 247) are MyKad-shaped numbers in non-ID contexts, such as a member number. A context-free regex cannot tell them apart. The benchmark counts them as errors; for privacy, masking them is a defensible choice. Other false positives were invoice and reference numbers that happen to match the SSM format.
  • Phone. 115 of the phone "false positives" overlap a real phone number with different span boundaries, which is why partial-overlap F1 is 0.803. The built-in PHONE type also labelled 18 MyKad numbers as phone numbers.
  • Not scored. Guardrails also found names (823), card numbers (23) and addresses (7). The benchmark doesn't label those, so this is not an overall quality comparison.

What I'd do as a builder

  • Add custom regexes for MyKad and SSM; Guardrails won't catch them otherwise. Use a whitespace-tolerant separator.
  • Set the input-side fields explicitly and test with source=INPUT before you rely on it.
  • If you need OCR-robust or context-aware detection (member numbers vs ID numbers), a regex in Guardrails won't get you there; put a Malaysia-specific recogniser in front of it, or accept masking the lookalikes.

Limits and disclosure

I built MyPII-Bench, its hard categories, and MyPII, the detector in the last row, so the benchmark plays to MyPII's strengths. The
test templates were written by a different model family, but the categories are mine. The data is synthetic. Each guardrail ran
once, and AWS does not version its detectors, so results may change. All test splits were already opened before this comparison, so
it is descriptive, registered in the benchmark's pre-registration file before each run, with the exploratory variant labelled as such.

Reproduce

Code, the exact guardrail definitions, and the raw Guardrails responses are in the MyPII repository (docs/BANDINGAN-BEDROCK.md,
hasil/cache/bedrock/, scripts/bedrock_guardrail_cipta.py, scripts/bedrock_pecahan.py). Re-scoring needs no AWS account; re-running
needs about 1,000 Guardrails text units per guardrail. Repository: https://github.com/sasateguh/mypii (results: docs/BANDINGAN-BEDROCK.md).

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.