# Max Length Check Examples

Source: https://userguide.qualytics.io/data-quality-checks/max-length/deep-dive/examples/

Three real-world scenarios that show how the Max Length check is typically used in production: guarding a fixed-width code, protecting a downstream column with a filter, and auditing free-text notes mid-cleanup. The first two run at 100% coverage and report Record Anomalies; the third lowers coverage and reports a Shape Anomaly instead.

**Tab: Fixed-Width Country Code**

**The situation:** The `addresses` table stores a two-letter country code. Values longer than two characters mean a country name or a padded value was written into the code column, which breaks every join against the country reference table.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Max Length |
| Field | `country_code` |
| Filter | *(none)* |
| Custom Anomaly Description | Off |
| Length | `2` |
| Array Element Context | Off |
| Coverage | 100% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Reference Data team)* |
| Description | Country code must be at most 2 characters. |
| Tags | `reference`, `format` |
| Additional Metadata | `jira: DATA-8601` |
| Status | Active |

**Payload**

```json
{
    "description": "Country code must be at most 2 characters.",
    "rule": "maxLength",
    "fields": ["country_code"],
    "container_id": 145,
    "coverage": 1,
    "filter": null,
    "properties": {"value": 2},
    "tags": ["reference", "format"],
    "additional_metadata": {"jira": "DATA-8601"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 12
}
```

**Sample Data**

| address_id | country_code | city |
| --- | --- | --- |
| A-001 | BR | São Paulo |
| A-002 | BRA | Recife |
| A-003 | PT | Porto |
| A-004 | *(null)* | Unknown |

**What gets flagged**

Address `A-002` holds a three-letter code. `A-004` is NULL and passes without firing an anomaly. Coverage is 100%, so the failing row is reported as a Record Anomaly, naming the value and the limit it breaks.

> **Example: Record Anomaly**
>
> country_code has the value BRA, which is longer than the maximum of 2

**Flowchart**

```mermaid
graph TD
    A["No filter, evaluate all rows"] --> B["Read country_code"]
    B --> C{"Is value NULL?"}
    C -->|Yes| D["Row passes"]
    C -->|No| E{"Is the length <= 2?"}
    E -->|Yes| D
    E -->|No| F["Flag row.<br/>Record Anomaly per failing row."]
```

**Equivalent SQL**

```sql
-- Rows the Max Length check would flag.
SELECT a.*
FROM addresses a
WHERE a.country_code IS NOT NULL
  AND length(a.country_code) > 2;
```

**Tab: Downstream Column Limit with Filter**

**The situation:** Records synced to an external CRM must fit its 100-character description column; anything longer is silently truncated on their side. Records that are not synced can hold any length and are out of scope.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Max Length |
| Field | `description` |
| Filter | `sync_to_crm = true` |
| Custom Anomaly Description | Off |
| Length | `100` |
| Array Element Context | Off |
| Coverage | 100% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Integrations team)* |
| Description | Synced descriptions must fit the CRM's 100-character limit. |
| Tags | `integration`, `format` |
| Additional Metadata | `jira: DATA-8644` |
| Status | Active |

**Payload**

```json
{
    "description": "Synced descriptions must fit the CRM's 100-character limit.",
    "rule": "maxLength",
    "fields": ["description"],
    "container_id": 512,
    "coverage": 1,
    "filter": "sync_to_crm = true",
    "properties": {"value": 100},
    "tags": ["integration", "format"],
    "additional_metadata": {"jira": "DATA-8644"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 29
}
```

**Sample Data** (filtered to `sync_to_crm = true`)

| record_id | sync_to_crm | description |
| --- | --- | --- |
| R-01 | true | Annual maintenance contract |
| R-02 | true | Long free-text note copied from the ticket, 180 characters |
| R-03 | true | Renewal, standard terms |

**Why the filter matters**

The filter runs **before** the measurement, so records that are never synced are not tested against the external limit. Only synced rows are evaluated.

**What gets flagged**

`R-02` exceeds the CRM's column limit and would be truncated on delivery. 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**
>
> description has the value Long free-text note copied from the ticket, 180 characters, which is longer than the maximum of 100 (applied to records where sync_to_crm = true)

**Flowchart**

```mermaid
graph TD
    A["Apply filter: sync_to_crm = true"] --> B["Read description"]
    B --> C{"Is the length <= 100?"}
    C -->|Yes| D["Row passes"]
    C -->|No| E["Flag row.<br/>Message names the filter:<br/>applied to records where sync_to_crm = true"]
```

**Equivalent SQL**

```sql
-- Rows the check would flag among synced records.
SELECT r.*
FROM records r
WHERE r.sync_to_crm = true
  AND r.description IS NOT NULL
  AND length(r.description) > 100;
```

**Tab: Free-Text Notes Mid-Cleanup**

**The situation:** A legacy `note` column holds pasted content well beyond the 500 characters the new schema allows. A cleanup job is trimming them, so a small fraction of oversized rows is expected and the check tolerates up to 0.5% failures.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Max Length |
| Field | `note` |
| Filter | *(none)* |
| Custom Anomaly Description | Off |
| Length | `500` |
| Array Element Context | Off |
| Coverage | 99.5% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Legacy Migration team)* |
| Description | Notes must fit the 500-character schema limit. |
| Tags | `legacy`, `format` |
| Additional Metadata | `jira: DATA-8688` |
| Status | Active |

**Payload**

```json
{
    "description": "Notes must fit the 500-character schema limit.",
    "rule": "maxLength",
    "fields": ["note"],
    "container_id": 733,
    "coverage": 0.995,
    "filter": null,
    "properties": {"value": 500},
    "tags": ["legacy", "format"],
    "additional_metadata": {"jira": "DATA-8688"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 41
}
```

**Sample Data**

| note_id | note | migrated |
| --- | --- | --- |
| N-01 | Customer confirmed the renewal by phone. | true |
| N-02 | Pasted email thread, 2,400 characters | false |
| N-03 | Pasted contract clause, 1,100 characters | false |
| N-04 | *(null)* | false |

**What gets flagged**

Notes `N-02` and `N-03` still hold pasted content beyond the limit. `N-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**
>
> note values are longer than the maximum of 500, affecting 2 of 4 asserted records

**Flowchart**

```mermaid
graph TD
    A["No filter, evaluate all rows"] --> B["Read note"]
    B --> C{"Is value NULL?"}
    C -->|Yes| D["Row passes"]
    C -->|No| E{"Is the length <= 500?"}
    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 n.*
FROM notes n
WHERE n.note IS NOT NULL
  AND length(n.note) > 500;
```

## See Also

- **How It Works**

  The complete reference: definition, field scope, the length property, NULL handling, arrays, filter behavior, and coverage.

  [How It Works](https://userguide.qualytics.io/data-quality-checks/max-length/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/max-length/deep-dive/anomaly-reporting/)
- **Best Practices**

  Guidelines for choosing the length, pairing rules, and keeping the signal clean.

  [Best Practices](https://userguide.qualytics.io/data-quality-checks/max-length/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/max-length/deep-dive/permissions/)

*Last updated: September 22, 2026.*
