Duczer East
Healthcare

In-perimeter AI on governed clinical and operational data.

Financial Services

Private AI and data platforms built to clear model-risk and audit review.

Financial services

Private AI, KYC/AML, API gateways and data governance for banks.

Insurance

Change data capture, governed agents and integration for insurers.

Healthcare

PHI document intelligence, FHIR APIs and in-perimeter AI for health systems and plans.

GuideIntegration & Security6 min read

AI Gateway Guardrails: PII Masking and a Test Set to Run

Where guardrails sit, what masking can and cannot catch and a test set to run

Authored byCo-Founder and Managing Partner, Duczer East
Part of the Insights topic: API Management & Integration
On this page
  1. Where guardrails sit
  2. PII masking
  3. Deterministic vs model checks
  4. Test set
  5. Common mistakes
  6. A first engagement

AI gateway guardrails are checks that run at the gateway between your application and the model provider, inspecting what goes in and what comes back. Deterministic guardrails, such as pattern checks and length limits, give the same answer every time and are simple to test. Model-based checks catch more but vary, so each needs its own test set. PII masking by pattern catches formats you can describe, such as card numbers, and misses names and addresses in free text. This guide explains where guardrails sit, how to split the work between deterministic and model-based checks and what to put in a test set before go-live. Product facts below come from the WSO2 documentation. The gateway is now named Choreo AI Gateway (formerly WSO2 AI Gateway), after Choreo Labs, formerly WSO2, renamed on November 17, 2026.

Where guardrails sit

A guardrail sits on the traffic path, so every call passes through it whether the application or the developer remembers or not. That is the difference between a guardrail and a prompt instruction: the instruction is a request to the model, while the guardrail is enforced outside it. The WSO2 guardrail overview describes guardrails between your application and the model provider that check both inputs and outputs.

PositionWhat it can doExample
On the requestBlock, mask or reshape what the model seesMask a card number before it leaves your network
On the responseBlock or flag what the application receivesReject a reply that breaks a required format
Per API or proxyApply rules to one applicationStricter rules on a customer-facing assistant
Per organisationApply a floor everywhereAlways mask account numbers

The overview does not describe the order the checks run in or what the caller sees on a block, so confirm both in a lab. For the wider setup, see WSO2 AI Gateway setup and registration and the gateway setup page.

PII masking

Pattern masking replaces text that matches a rule you define. It is strong where the data has a fixed shape and weak where it does not.

DataPattern maskingAdd
Card and account numbersGood, with a check digit test where availableTests for spaced and split forms
Government ID numbersGood, if the format is fixedCountry-specific patterns
Email addresses and phone numbersGoodVariants with spaces or words
NamesPoorMeaning-based or external check
Street addressesPoorMeaning-based or external check
Medical or case details in free textPoorMeaning-based check and human review

Mask before the data leaves your network and before it reaches logs. The record should show that a mask applied, not the value. Our PII masking scenario walks through a health system case with synthetic data.

Deterministic vs model checks

DeterministicModel-based
Examples in the 4.7.0 listContent length, word and sentence count, regex, JSON schema, URL, PII masking with regexSemantic prompt, semantic tool filtering, Azure Content Safety, AWS Bedrock Guardrail
Same input, same resultYesNot always
Test effortLowHigher, needs a larger set and repeat runs
Catches new phrasingNoOften
Failure shapeMisses what the rule did not describeMisses or blocks by judgment
Where to placeFirst, as the hard floorAfter, for what rules cannot describe

Put hard rules first and keep a deterministic check as the last word on anything that must never pass. Why a hard rule belongs after a classifier is argued in our piece on prompt injection controls.

Test set

Build the set before you configure the guardrails, and keep it in version control. Use synthetic data only.

GroupCasesExpected outcome
Normal traffic10 to 20 ordinary promptsPass and logged
Card, account and ID patternsPlain, spaced, split across lines, inside a sentenceMasked
Names and addresses in free textSeveral formsFlagged or masked by the meaning-based check
Over-length promptOne far over the limitRejected
Refused topicPrompts on topics you denyDenied
Structured outputResponse that must match a JSON shapeFails when the shape is wrong
TricksObfuscated numbers, instructions to ignore rulesBlocked or flagged, and every miss recorded
Repeat runsSame prompt several times on model-based checksConsistent outcome, or recorded variance

Record the result for every case, the release and guardrail version and who ran it. Re-run the set after every change to a rule, a provider or a release. The set is also your regression test when you upgrade, as the setup guide suggests.

Check the cases that fail, not the ones that pass. A mask that works on 19 of 20 card formats leaves a gap an attacker or a typo will find.

Common mistakes

  • Testing with real customer data instead of synthetic data.
  • Treating a passing demo as a passing test set.
  • Putting every check on a model-based service and losing repeatability.
  • Logging the original value next to the mask event.
  • Skipping the test after a provider, rule or release change.

A first engagement

Duczer East offers an AI gateway fit check: we review where the gateway runs, the release it needs and the guardrails to attach, then test them with a prompt set and hand back a short written plan. See WSO2 AI Gateway setup.

Related: WSO2 AI Gateway setup · PII masking on LLM traffic · WSO2 AI Gateway setup and registration · AI gateway vs API gateway · WSO2 AI Gateway troubleshooting

Frequently asked questions

What are AI gateway guardrails?

Checks that run at the gateway between your application and the model provider. They inspect requests and responses and can allow, mask, block or flag them.

Does regex PII masking catch names and addresses?

No. A pattern guardrail catches formats you can describe, such as card, account and ID numbers. Names and addresses in free text need a meaning-based or external check on top.

Should guardrails be deterministic or model-based?

Use both. Deterministic checks give the same answer every time and are easy to test. Model-based checks catch what rules cannot but vary and need their own testing.

What do you test before go-live?

A fixed set of prompts and responses with expected outcomes: normal traffic, patterns that must be masked, content that must be blocked and cases built to slip through.

Does the guardrail catalogue differ by release?

Yes. Guardrails arrived in WSO2 API Manager 4.6, and the 4.7.0 documentation lists eleven. Check the catalogue for your release.

Authored by

Co-Founder and Managing Partner, Duczer East

David deBoisblanc is co-founder of Duczer East and a digital transformation and innovation leader in data-centric AI, agentic systems, and enterprise integration. He shapes intent-driven AI solutions that modernize how organizations use data, drawing on deep experience with Cloudera and complex enterprise integration landscapes.

Newsletter

The Practitioner's Briefing

Senior-level insights on agentic AI, data engineering and enterprise integration, delivered to your inbox.

One email when there is something worth reading. Unsubscribe any time.

Let's Talk

Want to discuss the ideas raised here?

Tell us what you are working on. A senior practitioner replies, and only your email is required.

Get a quote