> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/sdmetrics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/sdmetrics/data-metrics/diagnostic/boundaryadherence.md).

# BoundaryAdherence

This metrics measures whether a synthetic column respects the minimum and maximum values of the real column. It returns the percentage of synthetic rows that adhere to the real boundaries.

## Data Compatibility

* **Numerical** : This metric is meant for numerical data
* **Datetime** : This metric converts datetime values into numerical values

*If you have missing values in the real data, then the metric will consider them valid in the synthetic data. Otherwise, they will be marked as out-of-bounds.*

## Score

**(best) 1.0**: All values in the synthetic data respect the min/max boundaries of the data

**(worst) 0.0**: No value in the synthetic data respects the min/max boundaries of the data data

The graph below shows an example of some fictional real and synthetic data (black and green, respectively) with BoundaryAdherence=0.912.

![The real data is in range \[37.0, 97.7\], shown by vertical dotted lines. Around 8.8% of the synthetic data is outside of the min/max bounds of the real data, so the overall BoundaryAdherence score is 91.2%.](https://2284413265-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrNLha4DaPNwVJ930KhmB%2Fuploads%2FhGhxNaSO7X0Eknn9TxWX%2FBoundary%20Adherence.png?alt=media\&token=5110e24c-81b5-476c-93fc-75a8fcf04a6c)

## How does it work?

This metric computes the min and max values of the real column. Then, it computes the frequency of synthetic values that are in the \[min, max] range. If there are missing values in the real data, then the metric will consider them as valid in the synthetic data; otherwise, missing values are considered out-of-bounds.

In some cases the allowable min/max range as well as the allowable missing values may be more expansive than what is present in the real data. This can happen when your real data is actually a smaller subset of the entire database. In this case you can override the allowable ranges by providing the `range_min`, `range_max`, and `range_is_nullable` parameters. If provided, these values will be used for checking the synthetic data rather than ranges derived from the real data.&#x20;

## Usage

{% hint style="success" %}
**Recommended Usage:** The [Diagnostic Report ](/sdmetrics/data-metrics/diagnostic/diagnostic-report-api.md)applies this metric to applicable columns.
{% endhint %}

To manually apply this metric, access the `single_column` module and use the `compute` method.

```python
from sdmetrics.single_column import BoundaryAdherence

BoundaryAdherence.compute(
    real_data=real_table['column_name'],
    synthetic_data=synthetic_table['column_name']
)
```

**Parameters**

* (required) `real_data`: A pandas.Series object with the column of real data
* (required) `synthetic_data`: A pandas.Series object with the column of synthetic data&#x20;
* `range_min`: A float or datetime containing the absolute minimum value that the data can possibly have. This may be less than the minimum value present in the real training data. If provided, this value will be used instead of the minimum value from the `real_data`.
* `range_max`: A float or datetime containing the absolute maximum value that the data can possible have. This may be greater than the maximum value present in the real training data. If provided, this value will be used instead of the maximum value from the `real_data`.
* `range_is_nullable`: A boolean describing whether the column is allowed to be null. This can be `True` even if the real training data does not have any missing values. If provided, this value will be used instead of computing it from the `real_data`.

## FAQs

<details>

<summary>Is there an equivalent metric for discrete data?</summary>

For discrete datasets, only a select number of values are possible. Use the [CategoryAdherence](/sdmetrics/data-metrics/diagnostic/categoryadherence.md) metric to ensure they have the correct values.

</details>

<details>

<summary>What kind of scores should I expect to see?</summary>

The scores that you see are based on the model that you used to create the synthetic data. Some models are designed to learn the min/max boundaries from the real data. For such models, the score should always be 1.0

Other models do not learn the boundaries. In these cases, you can expect the score to be close to, but not exactly, 1.0. Note that this may be a desirable feature if it is risky to leak the true min/max values in the synthetic data.&#x20;

</details>

<details>

<summary>What if my synthetic data is only covering a small subset of the real values?</summary>

This metric only quantifies cases where the synthetic data is going out of bounds. If you're interested in knowing whether the synthetic data covers the full range of real values, use the [RangeCoverage](/sdmetrics/data-metrics/quality/rangecoverage.md) metric.

</details>


---

# 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 by asking a question.

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

```
GET https://docs.sdv.dev/sdmetrics/data-metrics/diagnostic/boundaryadherence.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 `automate deployments from our CI pipeline` 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.
