# ❖ ChainedInequality

{% hint style="info" %}
❖ **SDV Enterprise Bundle**. This feature is available as part of the **CAG Bundle**, an optional add-on to SDV Enterprise. For more information, please visit the [CAG Bundle](/sdv/explore/sdv-bundles/cag.md) page.
{% endhint %}

The **ChainedInequality** constraint enforces a chain of inequality relationships between any number of columns. For every row, the value in these columns must follow a strict ordering system.

## Constraint API

Create a `ChainedInequality` constraint.

**Parameters:**

* (required) `column_names`: A list of strings that represent the column names. They should appear in ascending order (lowest to highest). *Only numerical and datetime columns are allowed.*
* `strict_boundaries`: Whether a column must be strictly greater than previous one
  * (default) `True`: The value in the higher column must be strictly greater than the lower one
  * `False`: The value in the higher column must be greater than *or equal to* the value of the lower one
* `table_name`: A string with the name of the table to apply this to. Required if you have a multi-table dataset.

```python
from sdv.cag import ChainedInequality

my_constraint = ChainedInequality(
    column_names=['purchase_date', 'start_date', 'end_date', 'expiration_date']
)   
```

## Usage

Apply the constraint to any SDV synthesizer. Then fit and sample as usual.

```python
synthesizer = GaussianCopulaSynthesizer(metadata)
synthesizer.add_constraints([my_constraint])

synthesizer.fit(data)
synthetic_data = synthesizer.sample()
```

For more information about using predefined constraints, please see the [**Constraint-Augmented Generation tutorial**](https://colab.research.google.com/drive/1WCMQujfVKL5giULZXOPPIBoMfzR9Zj68?usp=sharing).

## Auto-Detection

Auto-detection is allowed for this constraint and it is enabled by default. Run the detection with your data to detect all instances of this constraint throughout the dataset.

```python
constraints = synthesizer.detect_constraints(data)
```

**Detection Parameters**: By default, SDV detects this constraint for `datetime` columns only. Use the the `sdtypes` parameter to update this. Provide a list of sdtypes to detect (`datetime`, `numerical`, or both).

```python
constraints = synthesizer.detect_constraints(
    data,
    constraint_classes=['ChainedInequality'],
    detection_params={
        'ChainedInequality': { 'sdtypes': [ 'numerical', 'datetime' ] }
    }
)
```


---

# Agent Instructions: 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 current page URL with the `ask` query parameter:

```
GET https://docs.sdv.dev/sdv/concepts/constraint-augmented-generation-cag/predefined-constraints/chainedinequality.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
