# Contains Credit Card Check Examples

Source: https://userguide.qualytics.io/data-quality-checks/contains-credit-card/deep-dive/examples/

Three real-world scenarios that show how the Contains Credit Card check is typically used in production: validating a payment reference column, checking card transactions 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: Payment Token Column**

**The situation:** A payment integration writes the masked card reference into `card_reference`. Rows where the column holds a token, a bank slip number, or a note instead of a card number break reconciliation with the acquirer.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Contains Credit Card |
| Field | `card_reference` |
| Filter | *(none)* |
| Custom Anomaly Description | Off |
| Coverage | 100% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Payments Engineering)* |
| Description | Card reference must hold a credit card number. |
| Tags | `payments`, `format` |
| Additional Metadata | `jira: DATA-7201` |
| Status | Active |

**Payload**

```json
{
    "description": "Card reference must hold a credit card number.",
    "rule": "containsCreditCard",
    "fields": ["card_reference"],
    "container_id": 301,
    "coverage": 1,
    "filter": null,
    "properties": {},
    "tags": ["payments", "format"],
    "additional_metadata": {"jira": "DATA-7201"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 15
}
```

**Sample Data**

| payment_id | card_reference | method |
| --- | --- | --- |
| P-001 | 4111 1111 1111 1111 | card |
| P-002 | boleto-99213 | card |
| P-003 | 5500-0000-0000-0004 | card |
| P-004 | *(null)* | card |

**What gets flagged**

Payment `P-002` holds a bank slip identifier where the card number should be. `P-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**
>
> card_reference has the value boleto-99213, which does not contain a credit card number

**Flowchart**

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

**Equivalent SQL**

```sql
-- Rows the Contains Credit Card check would flag.
SELECT p.*
FROM payments p
WHERE p.card_reference IS NOT NULL
  AND p.card_reference NOT RLIKE '<credit card pattern>';
```

**Tab: Card Payments Only, with Filter**

**The situation:** The `transactions` table mixes card payments with transfers and vouchers. Only rows whose method is `card` must carry a card number in `instrument`; the other methods legitimately hold other identifiers.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Contains Credit Card |
| Field | `instrument` |
| Filter | `method = 'card'` |
| Custom Anomaly Description | Off |
| Coverage | 100% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Payments Engineering)* |
| Description | Card transactions must carry a credit card number. |
| Tags | `payments`, `format` |
| Additional Metadata | `jira: DATA-7233` |
| Status | Active |

**Payload**

```json
{
    "description": "Card transactions must carry a credit card number.",
    "rule": "containsCreditCard",
    "fields": ["instrument"],
    "container_id": 302,
    "coverage": 1,
    "filter": "method = 'card'",
    "properties": {},
    "tags": ["payments", "format"],
    "additional_metadata": {"jira": "DATA-7233"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 15
}
```

**Sample Data** (filtered to `method = 'card'`)

| txn_id | method | instrument |
| --- | --- | --- |
| T-01 | card | 4012888888881881 |
| T-02 | card | pending |
| T-03 | card | 6011000000000004 |

**Why the filter matters**

The filter runs **before** the evaluation, so transfers and vouchers are never tested for a card number. Only card transactions are evaluated.

**What gets flagged**

`T-02` holds the placeholder `pending`, 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**
>
> instrument has the value pending, which does not contain a credit card number (applied to records where method = 'card')

**Flowchart**

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

**Equivalent SQL**

```sql
-- Rows the check would flag on card transactions.
SELECT t.*
FROM transactions t
WHERE t.method = 'card'
  AND t.instrument IS NOT NULL
  AND t.instrument NOT RLIKE '<credit card pattern>';
```

**Tab: Legacy Import Mid-Cleanup**

**The situation:** A legacy import left free-text values in `stored_card`. A cleanup job is rewriting them, and a small fraction is expected to stay broken until it finishes, so the check tolerates up to 0.5% failures.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Contains Credit Card |
| Field | `stored_card` |
| Filter | *(none)* |
| Custom Anomaly Description | Off |
| Coverage | 99.5% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Legacy Migration team)* |
| Description | Stored card column must hold a credit card number. |
| Tags | `legacy`, `payments` |
| Additional Metadata | `jira: DATA-7290` |
| Status | Active |

**Payload**

```json
{
    "description": "Stored card column must hold a credit card number.",
    "rule": "containsCreditCard",
    "fields": ["stored_card"],
    "container_id": 303,
    "coverage": 0.995,
    "filter": null,
    "properties": {},
    "tags": ["legacy", "payments"],
    "additional_metadata": {"jira": "DATA-7290"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 41
}
```

**Sample Data**

| wallet_id | stored_card | migrated |
| --- | --- | --- |
| W-01 | 4111111111111111 | true |
| W-02 | see contract | false |
| W-03 | 0000 | false |
| W-04 | *(null)* | false |

**What gets flagged**

Wallets `W-02` and `W-03` still hold free-text and a truncated value. `W-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**
>
> stored_card values do not contain a credit card number, affecting 2 of 4 asserted records

**Flowchart**

```mermaid
graph TD
    A["No filter, evaluate all rows"] --> B["Read stored_card as text"]
    B --> C{"Is value NULL?"}
    C -->|Yes| D["Row passes"]
    C -->|No| E{"Does it contain<br/>a credit card 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 w.*
FROM wallets w
WHERE w.stored_card IS NOT NULL
  AND w.stored_card NOT RLIKE '<credit card 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-credit-card/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-credit-card/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-credit-card/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-credit-card/deep-dive/permissions/)

*Last updated: September 22, 2026.*
