> For the complete documentation index, see [llms.txt](https://docs.slingdata.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.slingdata.io/concepts/data-quality.md).

# Data Quality

Learn how to use sling for data quality

Sling provides several powerful features to ensure and maintain data quality throughout your data pipeline:

### Constraints

[Constraints](https://github.com/slingdata-io/sling-docs/blob/master/concepts/constraints.md) allow you to validate data at ingestion time using SQL-like syntax. They're specified at the column level and can prevent invalid data from entering your system.

```yaml
streams:
  my_stream:
    columns:
      # Ensure email is valid
      email: string | value ~ '^[^@]+@[^@]+\.[^@]+$'
      
      # Status can only be specific values
      status: string | value in ('active', 'pending', 'inactive')
      
      # Amount must be positive
      amount: decimal | value > 0
```

### Check Hooks

[Check](https://github.com/slingdata-io/sling-docs/blob/master/hooks/check.md) hooks enable you to implement custom validation logic at any point in your pipeline. They're particularly useful for:

* Validating row counts
* Ensuring data freshness
* Implementing complex business rules

```yaml
hooks:
  post:
    # Ensure minimum row count
    - type: check
      check: "run.total_rows >= 1000"
      on_failure: abort
    
    # Verify recent data
    - type: check
      check: "state.freshness_check.result.last_update >= timestamp.unix - 3600"
      on_failure: warn
```

### 3. Query Hooks

[Query](https://github.com/slingdata-io/sling-docs/blob/master/hooks/query.md) hooks allow you to run SQL-based quality checks and store results:

```yaml
hooks:
  post:
    - type: query
      connection: target_db
      query: |
        INSERT INTO quality_metrics (
          stream_name,
          check_time,
          null_rate,
          duplicate_rate
        )
        SELECT 
          '{run.stream.name}',
          CURRENT_TIMESTAMP,
          SUM(CASE WHEN email IS NULL THEN 1 ELSE 0 END) * 100.0 / COUNT(*),
          COUNT(*) - COUNT(DISTINCT id) * 100.0 / COUNT(*)
        FROM {run.object.full_name}
```

### Failure Handling

All data quality features support flexible failure handling:

* `abort`: Stop processing immediately
* `warn`: Continue but emit a warning
* `skip`: Skip the problematic record (for constraints)
* `quiet`: Continue silently

This allows you to implement the appropriate level of strictness for your use case.

By combining these features, you can build robust data quality checks throughout your pipeline, from ingestion to final delivery.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.slingdata.io/concepts/data-quality.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
