PurviewHow-to

Custom sensitive information types in Purview: regex, keywords, confidence and testing

Build a custom sensitive information type in Microsoft Purview: regex rules, keywords, proximity and confidence levels, rule package XML, limits, and how to test it.

Built-in sensitive information types (SITs) know credit card and passport numbers, but not your project codes, contract numbers or internal account IDs. A custom SIT teaches Microsoft Purview what that data looks like, and every DLP and auto-labeling policy can then use it. In this post I'll build one in the portal, show the XML rule package for finer control, and test it before any policy depends on it.

Errors this guide fixes

  • Generic quantifiers which match more content than expected (e.g., '+', '*')Rule package upload (PowerShell)
  • Lookaround assertionsRule package upload (PowerShell)
  • Complex grouping in conjunction with general quantifiersRule package upload (PowerShell)
How this guide is organized: Prerequisites → Step-by-step → Verify → Tips and gotchasFlow diagram of the article's sections in reading order: 1. Prerequisites. 2. Step-by-step (5 steps: Design the pattern before you click; Write a regex Purview will accept; Create the SIT in the portal; Or copy and tune a built-in SIT; Use a rule package for full control). 3. Verify. 4. Tips and gotchas. Toolbox: Connect-IPPSSession, Set-DlpSensitiveInformationTypeRulePackage, [guid]::NewGuid(), recommendedConfidence, matchStyle="word".1Prerequisites2Step-by-step3Verify4Tips and gotchas1Design the patternbefore you click2Write a regexPurview will accept3Create the SIT inthe portal4Or copy and tune abuilt-in SIT5Use a rule packagefor full controlTOOLBOXConnect-IPPSSessionSet-DlpSensitiveInformationTypeRu…[guid]::NewGuid()recommendedConfidencematchStyle="word"How this guide is organized: Prerequisites → Step-by-step → Verify → Tips and gotchasFlow diagram of the article's sections in reading order: 1. Prerequisites. 2. Step-by-step (5 steps: Design the pattern before you click; Write a regex Purview will accept; Create the SIT in the portal; Or copy and tune a built-in SIT; Use a rule package for full control). 3. Verify. 4. Tips and gotchas. Toolbox: Connect-IPPSSession, Set-DlpSensitiveInformationTypeRulePackage, [guid]::NewGuid(), recommendedConfidence, matchStyle="word".1Prerequisites2Step-by-step1Design the pattern before you click2Write a regex Purview will accept3Create the SIT in the portal4Or copy and tune a built-in SIT5Use a rule package for full control3Verify4Tips and gotchasTOOLBOXConnect-IPPSSessionSet-DlpSensitiveInformationTypeRulePackage[guid]::NewGuid()recommendedConfidencematchStyle="word"
At a glance: how this guide is organized · 5 steps · 5 key settings and tools

Prerequisites#

  • An admin account that can manage classifiers in the Microsoft Purview portal (see Purview roles and role groups), plus Security & Compliance PowerShell (Connect-IPPSSession) for testing and XML uploads.
  • Real-looking sample text: a few true matches and, just as important, near-misses that must not match.
  • Your own regex expertise. Microsoft states that its support engineers can't build content-matching definitions for you.

Step-by-step#

Building a custom sensitive information type, from design to policyStep 1: Design the pattern before you click. Bare regex at Low confidence, regex plus a keyword at High. Step 2: Write a regex Purview will accept. No ^ or $ anchors and exactly one capturing group. Step 3: Create the SIT in the portal. Or copy a built-in SIT, or upload an XML rule package for full control. Step 4: Test it with Test-DataClassification. High with the keyword, Low without it, and no result for near-misses. Step 5: Add it to a DLP policy in simulation. Review the matches before you enforce the policy. Step 6: Reclassify existing content. SharePoint and OneDrive need a recrawl or an on-demand classification scan.1Design the pattern beforeyou clickBare regex at Low confidence,regex plus a keyword at High.2Write a regex Purview willacceptNo ^ or $ anchors and exactly onecapturing group.3Create the SIT in the portalOr copy a built-in SIT, or upload anXML rule package for full control.4Test it withTest-DataClassificationHigh with the keyword, Lowwithout it, and no result fornear-misses.5Add it to a DLP policy insimulationReview the matches before youenforce the policy.6Reclassify existing contentSharePoint and OneDrive need arecrawl or an on-demandclassification scan.Building a custom sensitive information type, from design to policyStep 1: Design the pattern before you click. Bare regex at Low confidence, regex plus a keyword at High. Step 2: Write a regex Purview will accept. No ^ or $ anchors and exactly one capturing group. Step 3: Create the SIT in the portal. Or copy a built-in SIT, or upload an XML rule package for full control. Step 4: Test it with Test-DataClassification. High with the keyword, Low without it, and no result for near-misses. Step 5: Add it to a DLP policy in simulation. Review the matches before you enforce the policy. Step 6: Reclassify existing content. SharePoint and OneDrive need a recrawl or an on-demand classification scan.1Design the pattern before you clickBare regex at Low confidence, regex plus a keyword atHigh.2Write a regex Purview will acceptNo ^ or $ anchors and exactly one capturing group.3Create the SIT in the portalOr copy a built-in SIT, or upload an XML rule package forfull control.4Test it with Test-DataClassificationHigh with the keyword, Low without it, and no result fornear-misses.5Add it to a DLP policy in simulationReview the matches before you enforce the policy.6Reclassify existing contentSharePoint and OneDrive need a recrawl or anon-demand classification scan.
Figure 1 · Process Building a custom sensitive information type, from design to policy. Work through the steps in order and test on sample text before any DLP or auto-labeling policy depends on the new SIT.

1. Design the pattern before you click#

A SIT is one or more patterns. Each pattern has a primary element (a regular expression with an optional validator, a keyword list, a keyword dictionary or a built-in function), optional supporting elements found within a character proximity window, and a confidence level: Low, Medium or High (65, 75 and 85 in XML). The usual design is a bare regex at Low, regex plus a keyword at High, so policies can notify on Low and block on High.

2. Write a regex Purview will accept#

Purview uses the Boost.RegEx 5.1.3 engine and enforces a few rules:

  • No positional anchors such as ^ and $.
  • Exactly one capturing group; use non-capturing groups for prefixes and suffixes, and put variants inside the single group with |.
  • Lookbehinds must be fixed length, and a pattern can't start or end with | or .{0,m}, or put an unbounded repeater on a group.

For a project code such as PRJ-204518: \b(PRJ-[0-9]{6})\b. Word boundaries (\b) are safer than \s delimiters, especially if the SIT later becomes an exact data match primary element.

3. Create the SIT in the portal#

  1. Go to Information Protection › Classifiers › Sensitive info types and choose Create sensitive info type.
  2. Enter a name and description, then choose Create pattern.
  3. Pick the pattern's default confidence level, set the regex as the primary element and set Character proximity.
  4. Add supporting elements (for example a keyword list with "project code" and "confidential project") and any additional checks, then choose Create.
  5. Add a second, lower-confidence pattern without the keyword, choose the recommended confidence level for the SIT, and save.

Custom SITs created this way land in the Microsoft.SCCManaged.CustomRulePack rule package.

4. Or copy and tune a built-in SIT#

Select a built-in SIT and choose Copy, then edit the copy's patterns, for example adding a keyword requirement to cut noise. A few SITs can't be copied (including the EU and U.S. driver's license types and the ICD code types), and a SIT with ten text processors has to be copied with PowerShell instead.

5. Use a rule package for full control#

XML lets you exclude false-positive keywords, require several unique matches, or manage SITs as code. A trimmed example (generate your own GUIDs with [guid]::NewGuid()):

XML
<?xml version="1.0" encoding="utf-16"?>
<RulePackage xmlns="http://schemas.microsoft.com/office/2011/mce">
 <RulePack id="00000000-0000-0000-0000-000000000001">
  <Version major="1" minor="0" build="0" revision="0"/>
  <Publisher id="00000000-0000-0000-0000-000000000002"/>
  <Details defaultLangCode="en-us"><LocalizedDetails langcode="en-us">
   <PublisherName>Contoso</PublisherName><Name>Contoso SITs</Name><Description>Project codes</Description>
  </LocalizedDetails></Details>
 </RulePack>
 <Rules>
  <Entity id="00000000-0000-0000-0000-000000000003" patternsProximity="300" recommendedConfidence="75">
   <Pattern confidenceLevel="65"><IdMatch idRef="Regex_project"/></Pattern>
   <Pattern confidenceLevel="85">
    <IdMatch idRef="Regex_project"/><Match idRef="Keyword_project"/>
    <Any minMatches="0" maxMatches="0"><Match idRef="Keyword_not_real"/></Any>
   </Pattern>
  </Entity>
  <Regex id="Regex_project">\b(PRJ-[0-9]{6})\b</Regex>
  <Keyword id="Keyword_project"><Group matchStyle="word"><Term>project code</Term><Term>confidential project</Term></Group></Keyword>
  <Keyword id="Keyword_not_real"><Group matchStyle="word"><Term>sample</Term><Term>template</Term></Group></Keyword>
  <LocalizedStrings><Resource idRef="00000000-0000-0000-0000-000000000003">
   <Name default="true" langcode="en-us">Contoso project code</Name>
   <Description default="true" langcode="en-us">Detects Contoso project codes</Description>
  </Resource></LocalizedStrings>
 </Rules>
</RulePackage>

The Any block with minMatches="0" maxMatches="0" means "none of these words nearby". Every entity needs recommendedConfidence, or policies that use the SIT can't be saved. Save the file with Unicode encoding and upload it:

PowerShell
Connect-IPPSSession
New-DlpSensitiveInformationTypeRulePackage -FileData ([System.IO.File]::ReadAllBytes('C:\SIT\ContosoSITs.xml'))
Get-DlpSensitiveInformationType -Identity "Contoso project code" | Format-List Name,Publisher

To change it later, raise the Version numbers and upload with Set-DlpSensitiveInformationTypeRulePackage; without a new version number the package isn't deployed. If the validator spots a performance risk, the upload is refused with one of these messages:

Text
Generic quantifiers which match more content than expected (e.g., '+', '*')
Lookaround assertions
Complex grouping in conjunction with general quantifiers

Verify#

Test text before any policy uses the SIT:

PowerShell
$r = Test-DataClassification -TextToClassify "Kickoff for confidential project PRJ-204518 is Monday." -ClassificationNames "Contoso project code"
$r.ClassificationResults
$t = Test-TextExtraction -FileData ([System.IO.File]::ReadAllBytes('C:\SIT\sample.docx'))
(Test-DataClassification -TestTextExtractionResults $t.ExtractedResults).ClassificationResults

Good looks like your SIT listed with a count and the high confidence level when the keyword is present, the low level without it, and no result for your near-miss samples. Then:

  • Add the SIT to a DLP policy in simulation and review the matches; see from simulation mode to enforcement.
  • Existing SharePoint and OneDrive content is only classified with the new SIT after a recrawl, or after an on-demand classification scan.

Tips and gotchas#

LimitValue
Custom SITs created in the portal500
Regex length / distinct regexes per SIT1,024 characters / 20
Keyword list2,048 terms, 50 characters per term
Rule packages / SITs per package / package size10 / 50 / 150 KB
Instance count in policiesMin 1–500; max 1–500 or Any
  • Long or huge keyword lists: move them into a keyword dictionary.
  • Prefer matchStyle="word"; use string only for parts of words or Asian languages.
  • Email: the body and each attachment are separate items, so the keyword must sit in the same item as the match.
  • Your own records: for exact customer or employee data, exact data match beats a regex; for noisy matches see tuning DLP false positives.

References#

Written and checked against current Microsoft Learn documentation. Test changes with a pilot group before rolling them out to everyone, and if an admin center path has moved since, search for the setting name instead.

Spotted a mistake, or did this fix work differently for you? Email me or message me on LinkedIn — corrections are credited in the article.

Written by

Omer Eltayeb

Intune Subject Matter Expert in Cairo, Egypt, former Microsoft Cloud Solutions Architect, Microsoft Certified Trainer and Microsoft Innovative Educator Expert (2024–26) and Microsoft Elevate Educator Expert (2026–27). I share practical, step-by-step guides, study plans, scripts and toolkits for Microsoft Intune, Configuration Manager, Microsoft Entra ID, Microsoft Defender, Exchange and Microsoft 365 with the community.

Microsoft Certified Trainer (MCT) 2026Microsoft Innovative Educator Expert 2025–2026Microsoft Elevate Educator Expert 2026–2027ISC2 Certified Information Systems Security Professional (CISSP)Microsoft 365 Certified: Enterprise Administrator Expert (MS-102)