Custom sensitive information types, without writing regex.
Describe the identifier part by part and test it against real content. The builder then writes a rule package for Security & Compliance PowerShell. It runs in this tab: nothing you type or paste is uploaded or sent anywhere.
01Pattern
0 parts02What it matches
03Sample content
no sample04Test cases
no casesMust match
Must not match
05Deliverables
Rule package XML
Microsoft asks for Unicode encoding; this downloads as UTF-16 LE with a byte order mark, the form Windows uses for it. Upload the file as it is.
Upload & test
06Checks
no pattern07SIT settings
To update an uploaded type, import your session file so the GUIDs stay the same, raise this by one, download again and upload with Set-DlpSensitiveInformationTypeRulePackage.
Proximity counts characters either side of the match. Microsoft recommends 300 for a new custom type.
A keyword must appear within the proximity window of the pattern match for the high-confidence rule to fire.
08Deployment notes
Keep it UTF-16. Microsoft says a rule package saved with any encoding other than Unicode won't work. Opening the XML in an editor and saving it as UTF-8 undoes the download.
Raise the version to update. Microsoft 365 won't deploy a rule package uploaded again with the same version. Import your session file, raise Version in SIT settings, download, and upload with Set-DlpSensitiveInformationTypeRulePackage.
Existing files need a recrawl. SharePoint and OneDrive content already stored is checked against a new type only after it is recrawled or rescanned.
The GUIDs are paired. The schema requires the Resource idRef to equal the Entity id. Change one by hand and change the other.
09Session
That file is not a pattern export.
Nothing is kept between visits by the builder. Export the session file to keep a build, and to update the same type later.
Purview Pattern Builder · runs in this tab and sends nothing you enter anywhere. Patterns are previewed on the browser's regex engine. Purview evaluates them with Boost.RegEx 5.1.3, and the builder emits only constructs on which the two agree, apart from the preview fallback Checks reports.
Check Microsoft’s built-in types first.
Purview already detects the common Australian identifiers. Its built-in list covers tax file numbers, Australian Business Numbers, Australian Company Numbers, Medicare numbers (listed as Australia medical account number), passport and driver’s licence numbers, bank account numbers and physical addresses. Microsoft lists a checksum for the tax file number, ABN, ACN and Medicare formats.
Build a custom type for identifiers your organisation issues itself: staff numbers, client and matter references, policy numbers, ticket and project codes. No built-in type knows their shape.
What the rule package contains.
- One pattern, one capturing group
- The identifier sits inside the single capturing group Microsoft’s validation requires. Standalone matching adds fixed-width lookarounds at the edges so the pattern cannot fire inside a longer word or number. No ^ or $ is ever written: Microsoft says not to use them in a custom type. Upload runs Microsoft’s own validation; if it objects to the lookarounds, choose Anywhere, which leaves them out.
- Confidence
- Purview reads 85 as high, 75 as medium and 65 as low. With supporting keywords, the main rule fires only when one appears near the match. The optional second rule fires on the pattern alone at 65, so a policy can treat the two differently.
- Proximity
- Counted in Unicode characters either side of the match. In email, the message body and each attachment are separate items, so a keyword in the body does not support a match inside an attachment.
- GUIDs and names
- The rule pack, the publisher and the type each get a GUID. The type’s display name is filed under the type’s own GUID, a pairing the rule package schema requires.
- UTF-16
- The file downloads as UTF-16 little-endian with a byte order mark. Microsoft says to save a rule package with Unicode encoding, and that a rule saved any other way won’t work.
- Or skip the file
- The pattern from Copy pattern also works in the Purview portal: Information Protection, Classifiers, Sensitive info types, Create sensitive info type, with a regular expression as the primary element. Types made there go into Purview’s own Microsoft.SCCManaged.CustomRulePack rather than a package of their own, and need no PowerShell.
From download to a tested type.
-
PowerShell Connect-IPPSSessionConnect to Security & Compliance PowerShell.
-
PowerShell New-DlpSensitiveInformationTypeRulePackageUpload the downloaded file. The Upload & test panel above writes the command with the file name filled in.
-
PowerShell Get-DlpSensitiveInformationTypeConfirm the type is listed. A custom type shows a publisher other than Microsoft Corporation: LensIQ, unless you changed it in SIT settings.
-
PowerShell Test-DataClassificationTry a string that should match. The command the builder writes names your type, so the result shows that type’s count and confidence.
-
Sensitive info types › Test
In the Microsoft Purview portal, open Information Protection, then Classifiers, then Sensitive info types. Select the type, choose Test and upload an unencrypted file that should match, then one that should not.
The portal’s Test option is greyed out unless the tenant has at least one Exchange Online licence. Testing also needs a Purview role group, such as Compliance Administrator or Information Protection Admins, and an Exchange role, such as Data Loss Prevention.
To change the type later, import your session file so the GUIDs stay the same, raise Version in SIT settings, download again and upload with Set-DlpSensitiveInformationTypeRulePackage. Microsoft 365 won’t deploy a rule package whose version hasn’t changed.
Putting it to work in a DLP policy.
A data loss prevention rule picks the type in its Content contains condition, with a confidence level and an instance count. Microsoft suggests stricter actions, such as blocking, for high-confidence matches and lighter ones, such as a notification, for low.
Test the type everywhere you plan to use it. Microsoft notes the same type can return different results for email, for files in SharePoint and OneDrive, and on devices. Files already stored in SharePoint and OneDrive are checked against a new type only once they are recrawled, or rescanned with on-demand classification.
What Purview accepts in one custom type.
Every limit on Microsoft Learn’s sensitive information type limits page, and what this builder does about each
| Limit | Value | What the builder does |
|---|---|---|
| Regular expression length | 1,024 characters | Checks fail a longer pattern, counted on the exact expression the package carries, wrapping group included |
| Capturing groups per expression | Exactly 1 | Wraps the identifier in the one group; anything around it is (?: ). Checks fail none or several |
| Distinct regexes per type | 20 | Writes one |
| Term length in a keyword list | 50 characters | Checks fail a longer keyword |
| Terms in a keyword list | 2,048 | Writes one keyword list per type; Checks fail more than 2,048 |
| Keyword dictionaries, combined, after compression | 1 MB (about 1,000,000 characters) | Writes a keyword list, never a dictionary |
| Rule package size | 150 KB | Checks show the size of the file that downloads and fail one over 150 KB. A starter type is 2.6 to 3.8 KB; long keyword lists cross 150 KB at about 1,050 keywords of 50 characters |
| Types per rule package | 50 | Writes one type per package |
| Rule packages | 10 | Each download is a package of its own: uploading it as new uses one of the ten, updating it with Set-DlpSensitiveInformationTypeRulePackage keeps its place. So uploaded one per package, ten types fill every slot |
| Custom types created in the Purview portal | 500 | Not counted here: this builder writes a rule package for PowerShell, not portal types. Microsoft asks for a support ticket above 500 |
Where each statement comes from.
Checked against Microsoft Learn ·
- Microsoft Learn Create a custom sensitive information type using PowerShell Rule package structure, confidence, proximity, version, upload and validation
- Microsoft Learn Sensitive information type limits The limits table
- Microsoft Learn Create custom sensitive information types Capturing group and anchor rules, the portal route, what Microsoft Support can help with
- Microsoft Learn Test sensitive information types Testing in the portal, and the roles it needs
- Microsoft Learn Learn about sensitive information types Exchange Online licence for Test, results by workload
- Microsoft Learn Sensitive information type entity definitions Built-in Australian types and their checksums
- Microsoft Learn Customize a built-in sensitive information type Unicode encoding
- Microsoft Learn Modify a custom sensitive information type using PowerShell Updating with Set-DlpSensitiveInformationTypeRulePackage
- Microsoft Learn Remove a custom sensitive information type using PowerShell Rolling back a rule package
- Microsoft Learn Step 1: Configure pattern-based sensitive data detection Proximity of 300 characters for a new custom type
- Microsoft Learn Test-DataClassification Testing a string from PowerShell
- Microsoft Learn Connect-IPPSSession Connecting to Security & Compliance PowerShell
A tested pattern, built for your documents.
Microsoft Support can’t help create custom classifications or regular expression patterns, and can’t assure that one meets your requirements. We build custom types and test them against the documents in your tenant.