---
title: "Contextual Matching"
description: "Contextual matching detects sensitive data using structural patterns plus surrounding context — the technique that makes detection both sensitive and precise."
url: "https://sonomos.ai/glossary/contextual-matching/"
source: "https://sonomos.ai/glossary/contextual-matching/"
---

# Contextual Matching

Detecting sensitive data by combining structural patterns with surrounding context, instead of relying on regex alone.

## In depth

Pure regular-expression detection produces too many false positives on free-form text — every nine-digit number is not a Social Security Number, every name is not a client. Contextual matching pairs a structural rule (digit format, checksum, named-entity tag) with a contextual signal (nearby keyword, document section, surrounding language). A nine-digit string near the words 'employer ID' is treated differently than the same string near 'patient SSN'. Contextual matching is the difference between a noisy detector that nobody trusts and a precise one that surfaces real risk.

## Examples

- Flagging a name only when it appears within ten tokens of 'plaintiff', 'witness', or 'client'.
- Treating a Luhn-valid 16-digit number as a credit card only inside billing-related text.
- Matching ICD-10 codes only in clinical contexts, not in general technical writing.

## How Locke handles contextual matching

Locke's on-device detection layers structural rules with contextual signals: keyword proximity, document type, named-entity recognition, and per-industry profiles. The result is detection that is sensitive enough to catch indirect identifiers and specific enough to avoid yellow-screen fatigue.

[See the product](https://sonomos.ai/locke/)

## Related terms

- Personally Identifiable Information (PII)

  Any information that can identify a specific person, either directly (name, SSN) or in combination with other data (zip code + birthdate).
- Data Masking

  Replacing sensitive values with realistic-looking substitutes so the data remains usable while the originals never leave the device.
- On-Device AI

  Running model inference or pre-processing entirely on the user's machine instead of sending data to a cloud service.

## Reading on this topic

- [PHI vs PII vs Personal Data: A Plain-English Compliance Glossary for 2026](https://sonomos.ai/blog/phi-vs-pii-vs-personal-data-glossary/)
- [What Is PII Redaction? A Plain-English Guide for AI Users](https://sonomos.ai/blog/what-is-pii-redaction-ai/)
