Contextual AI vs. regex: why pattern-based classification misses context
The short version
Pattern-based classification asks: does this file contain something that looks like sensitive data? Contextual classification asks: what is this file, and how sensitive is it?
The first question works for structured identifiers. The second is the one that matters for most business documents.
Side by side
| Dimension | Regex and pattern matching | Contextual AI classification |
|---|---|---|
| How it decides | Matches strings, keywords and formats against rules | Reads the content and determines the document's purpose and sensitivity |
| Strong at | Card numbers, national IDs, account numbers, health record numbers | Contracts, board material, financial models, legal opinions, R&D, source code |
| Documents with no pattern | Invisible, so no label and no DLP rule | Recognized by what they are |
| Templates and test data | Fires on them, because the pattern looks real | Tells a real contract from a template |
| Setup | Rules to write, tune and maintain for each category | Categories built in, mapped to your labels |
| Effect on DLP | Noisy alerts, so policies are often left in audit mode | Fewer false positives, so policies can enforce |
Where regex breaks down
False negatives. The documents with the most business risk usually contain nothing a rule can match. Board minutes and quarterly results are just figures. An unreleased product design is specifications and drawings. A legal opinion is prose. No pattern, no label, no protection.
False positives. Patterns can't tell context. A sample card number in a test file, an ID number in a training template or a contract clause in a boilerplate library all look sensitive to a rule. Alert volume grows, teams loosen policies to audit mode, and enforcement quietly stops.
Maintenance. Every new category means new rules, new keyword lists and more tuning. Trainable classifiers help, but each one needs a training set and ongoing maintenance, and only covers the categories someone thought to define.
Where regex still belongs
Pattern matching is fast, predictable and easy to explain. It's the right tool for regulated identifiers with a fixed format. The goal isn't to replace it, but to add the context it can't provide, so that a card number in a real customer export and a card number in a test file are treated differently, and a board pack with no identifiers is recognized at all.
What changes with context
When policy acts on what a document is, rather than on what it contains, DLP becomes precise enough to enforce. Cognni customers see up to 80% fewer false positives once policy acts on context, and labels become specific enough to drive the right action.
Where Cognni fits
Cognni classifies content by meaning with its own AI models, using more than 400 information types and no regex or rules to write. It writes the resulting labels into Microsoft Purview, so your existing DLP and Copilot policies act on context instead of patterns alone.
Frequently asked questions
Is contextual AI the same as a trainable classifier?
No. A trainable classifier learns one category from examples you provide and needs tuning for each category you define. Contextual classification comes with its categories built in and recognizes document types nobody defined in advance.
Will contextual classification replace our sensitive information types?
It doesn't need to. Keep them for structured identifiers, and add contextual classification for the business content they can't see.
Why do DLP policies end up in audit mode?
Usually because pattern-based rules produce too many false positives to enforce without disrupting work. Acting on context reduces those false positives.