# Contains Social Security Number Check Examples

Source: https://userguide.qualytics.io/data-quality-checks/contains-social-security-number/deep-dive/examples/

Three real-world scenarios that show how the Contains Social Security Number check is typically used in production: validating a tax identifier column, checking domestic records with a filter, and auditing a legacy column mid-cleanup. The first two run at 100% coverage and report Record Anomalies; the third lowers coverage and reports a Shape Anomaly instead.

**Tab: Tax Identifier Column**

**The situation:** An HR dataset stores the employee tax identifier in `tax_id`. Rows where the column holds an internal badge number or a placeholder break payroll filings.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Contains Social Security Number |
| Field | `tax_id` |
| Filter | *(none)* |
| Custom Anomaly Description | Off |
| Coverage | 100% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(People Operations Data)* |
| Description | Employee tax identifier must hold a social security number. |
| Tags | `hr`, `format` |
| Additional Metadata | `jira: DATA-7301` |
| Status | Active |

**Payload**

```json
{
    "description": "Employee tax identifier must hold a social security number.",
    "rule": "containsSocialSecurityNumber",
    "fields": ["tax_id"],
    "container_id": 410,
    "coverage": 1,
    "filter": null,
    "properties": {},
    "tags": ["hr", "format"],
    "additional_metadata": {"jira": "DATA-7301"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 18
}
```

**Sample Data**

| employee_id | tax_id | status |
| --- | --- | --- |
| E-001 | 123-45-6789 | active |
| E-002 | BADGE-4471 | active |
| E-003 | 987-65-4320 | active |
| E-004 | *(null)* | pending |

**What gets flagged**

Employee `E-002` has an internal badge number where the tax identifier should be. `E-004` is NULL and passes without firing an anomaly. Coverage is 100%, so the failing row is reported as a Record Anomaly.

> **Example: Record Anomaly**
>
> tax_id has the value BADGE-4471, which does not contain a social security number

**Flowchart**

```mermaid
graph TD
    A["No filter, evaluate all rows"] --> B["Read tax_id as text"]
    B --> C{"Is value NULL?"}
    C -->|Yes| D["Row passes"]
    C -->|No| E{"Does it contain<br/>a social security number?"}
    E -->|Yes| D
    E -->|No| F["Flag row.<br/>Record Anomaly per failing row."]
```

**Equivalent SQL**

```sql
-- Rows the Contains Social Security Number check would flag.
SELECT e.*
FROM employees e
WHERE e.tax_id IS NOT NULL
  AND e.tax_id NOT RLIKE '<social security number pattern>';
```

**Tab: Domestic Records Only, with Filter**

**The situation:** The `contractors` table mixes domestic and international records. Only domestic contractors carry a social security number in `national_id`; international ones hold other national identifiers and are out of scope.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Contains Social Security Number |
| Field | `national_id` |
| Filter | `country = 'US'` |
| Custom Anomaly Description | Off |
| Coverage | 100% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Compliance Data team)* |
| Description | Domestic contractors must carry a social security number. |
| Tags | `compliance`, `format` |
| Additional Metadata | `jira: DATA-7344` |
| Status | Active |

**Payload**

```json
{
    "description": "Domestic contractors must carry a social security number.",
    "rule": "containsSocialSecurityNumber",
    "fields": ["national_id"],
    "container_id": 411,
    "coverage": 1,
    "filter": "country = 'US'",
    "properties": {},
    "tags": ["compliance", "format"],
    "additional_metadata": {"jira": "DATA-7344"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 18
}
```

**Sample Data** (filtered to `country = 'US'`)

| contractor_id | country | national_id |
| --- | --- | --- |
| K-01 | US | 111-22-3333 |
| K-02 | US | pending review |
| K-03 | US | 444-55-6666 |

**Why the filter matters**

The filter runs **before** the evaluation, so international contractors are never tested against a domestic format. Only domestic rows are evaluated.

**What gets flagged**

`K-02` holds a status note instead of an identifier, so it is the only row reported. Coverage is 100%, so the failure is reported as a Record Anomaly, and the message names the filter that scoped the evaluation.

> **Example: Record Anomaly**
>
> national_id has the value pending review, which does not contain a social security number (applied to records where country = 'US')

**Flowchart**

```mermaid
graph TD
    A["Apply filter: country = 'US'"] --> B["Read national_id as text"]
    B --> C{"Does it contain<br/>a social security number?"}
    C -->|Yes| D["Row passes"]
    C -->|No| E["Flag row.<br/>Message names the filter:<br/>applied to records where country = 'US'"]
```

**Equivalent SQL**

```sql
-- Rows the check would flag among domestic contractors.
SELECT k.*
FROM contractors k
WHERE k.country = 'US'
  AND k.national_id IS NOT NULL
  AND k.national_id NOT RLIKE '<social security number pattern>';
```

**Tab: Legacy Column Mid-Cleanup**

**The situation:** A legacy `person_ref` column mixes identifiers with free-text notes. A cleanup job is rewriting the bad rows, and a small fraction is expected to remain broken until it finishes, so the check tolerates up to 0.5% failures.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Contains Social Security Number |
| Field | `person_ref` |
| Filter | *(none)* |
| Custom Anomaly Description | Off |
| Coverage | 99.5% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Legacy Migration team)* |
| Description | Legacy person reference must hold a social security number. |
| Tags | `legacy`, `format` |
| Additional Metadata | `jira: DATA-7388` |
| Status | Active |

**Payload**

```json
{
    "description": "Legacy person reference must hold a social security number.",
    "rule": "containsSocialSecurityNumber",
    "fields": ["person_ref"],
    "container_id": 412,
    "coverage": 0.995,
    "filter": null,
    "properties": {},
    "tags": ["legacy", "format"],
    "additional_metadata": {"jira": "DATA-7388"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 41
}
```

**Sample Data**

| record_id | person_ref | migrated |
| --- | --- | --- |
| R-01 | 222-33-4444 | true |
| R-02 | see paper file | false |
| R-03 | unknown | false |
| R-04 | *(null)* | false |

**What gets flagged**

Records `R-02` and `R-03` still hold free-text notes. `R-04` is NULL, so it passes without firing an anomaly but still counts in the scanned total. Only 50% of the rows pass, which is below the 99.5% coverage threshold, so the check reports a single Shape Anomaly for the dataset with a sample of the offending rows. Coverage below 100% does not produce Record Anomalies.

> **Example: Shape Anomaly**
>
> person_ref values do not contain a social security number, affecting 2 of 4 asserted records

**Flowchart**

```mermaid
graph TD
    A["No filter, evaluate all rows"] --> B["Read person_ref as text"]
    B --> C{"Is value NULL?"}
    C -->|Yes| D["Row passes"]
    C -->|No| E{"Does it contain<br/>a social security number?"}
    E -->|Yes| D
    E -->|No| F["Flag row.<br/>Passing rate falls below the 99.5%<br/>coverage, so one Shape Anomaly is reported."]
```

**Equivalent SQL**

```sql
-- Rows the check would flag.
SELECT r.*
FROM person_records r
WHERE r.person_ref IS NOT NULL
  AND r.person_ref NOT RLIKE '<social security number pattern>';
```

## See Also

- **How It Works**

  The complete reference: definition, field scope, pattern matching, NULL handling, arrays, filter behavior, and coverage.

  [How It Works](https://userguide.qualytics.io/data-quality-checks/contains-social-security-number/deep-dive/how-it-works/)
- **Anomaly Reporting**

  The anomaly messages the check produces, what the numbers mean, Source Records highlighting, and Custom Anomaly Description.

  [Anomaly Reporting](https://userguide.qualytics.io/data-quality-checks/contains-social-security-number/deep-dive/anomaly-reporting/)
- **Best Practices**

  Guidelines for scoping the check, pairing rules, and keeping the signal clean.

  [Best Practices](https://userguide.qualytics.io/data-quality-checks/contains-social-security-number/deep-dive/best-practices/)
- **Permissions**

  The team permission each action needs: view, create, edit, archive, restore, and delete.

  [Permissions](https://userguide.qualytics.io/data-quality-checks/contains-social-security-number/deep-dive/permissions/)

*Last updated: September 22, 2026.*
