> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/sdv/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/sdv/modeling/configuration/range-extrapolation.md).

# ❖ Range Extrapolation

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

By default, your synthesizers learns the patterns based on the training data you provide, including the possible ranges within each column. The **range extrapolation** feature allows you to create synthetic data that is **outside the ranges of your training data**.

## Usage

This feature is meant for extrapolating outside of the ranges that your training data contains. This covers:

* Extrapolating the possible min and max for continuous attributes like numerical or datetime columns
* Creating brand new category values that were not present in your original training data
* Allowing null (or non-null) values in a column even when your training data doesn't have this scenario covered

### Specify Your Ranges

To get started, we recommend creating a JSON file that contains the ranges of the columns. You do not need to specify all columns, just the ones that need extrapolation.

The JSON should comprise of a dictionary called "tables". Inside of it, each table name should map to another dictionary of columns.

```json
{
  "tables": {
    "users": {
      "age": {
        "min": 0,
        "max": 100,
        "missing_values_allowed": false
      },
      "tax_status": {
        "categories": ["Single", "Married Filing Jointly", ... ],
        "missing_values_allowed": true
      }
    ...
```

For each column, specify the name of the column and map to the range information for that column. The range information can be found below.

{% tabs %}
{% tab title="Numerical" %}
If your column is numerical specify:

* `"min"`: The min allowable value for the column.&#x20;
* `"max"`: The max allowable value for the column.
* `"missing_values_allowed"`: A boolean describing whether missing values are allowed.

If any of these keys are not provided, then the synthesizer will learn this information from the data.

```json
"age": {
    "min": 0, 
    "max": 100,
    "missing_values_allowed": false
}
```

{% endtab %}

{% tab title="Datetime" %}
If your column is a datetime specify:

* `"min"`: The min allowable value for the column. This should be represented in the same datetime format as your data.&#x20;
* `"max"`: The max allowable value for the column. This should be represented in the same datetime format as your data.
* `"missing_values_allowed"`: A boolean describing whether missing values are allowed.

If any of these keys are not provided, then the synthesizer will learn this information from the data.

```json
"date_of_birth": {
    "min": "1926-01-01", 
    "max": "2026-01-01",
    "missing_values_allowed": false
}
```

{% endtab %}

{% tab title="Categorical" %}
If your column is categorical specify:

* `"categories"`: A list of strings describing all the allowed category values.
* `"missing_values_allowed"`: A boolean describing whether missing values are allowed.

If any of these keys are not provided, then the synthesizer will learn this information from the data.

```json
"ethnicity": {
    "categories": ["Single", "Married Filing Jointly", "Married Filing Separately", "Head of Houshold", "Qualifying Surviving Spouse"],
    "missing_values_allowed": true
}
```

{% endtab %}

{% tab title="Other" %}
For any other column specify:

* `"missing_values_allowed"`: A boolean describing whether missing values are allowed.

```json
"ssn": {
    "missing_values_allowed": true
}
```

*Please note missing values are not allowed for primary key columns.*
{% endtab %}
{% endtabs %}

{% hint style="info" %}
We recommend saving this as a JSON file. You can then read the JSON file as a Python dictionary using the command below.

```python
import json

FILENAME = 'my_ranges.json'

with open(FILENAME, 'r') as file:
    range_dictionary = json.load(file)
```

{% endhint %}

### \<synthesizer>.add\_ranges

Use this function to add ranges to your synthesizer before fitting the data. This function can be applied to any single- or multi-table synthesizer that you have access to.

**Parameters**:

* (required) `range_info`: A dictionary that describes the extrapolated ranges that the columns in your data should have. Not all tables or columns have to be present in this dictionary, only the ones that need range extrapolation. See the section above for more details.

**Output**: (None) The synthesizer will now be able to extrapolate outside of the ranges that are present in the training data during `fit`.

```
my_synthesizer.add_ranges(range_info=range_dictionary)
```

## What's Next?

Be sure to fit your syntheizer for the extrapolation to work.

```python
my_synthesizer.fit(data)
```

After fitting, you can sample synthetic data as usual. The synthetic data will now contain the full ranges that you specified in your dictionary as opposed to the ranges from the training data.

```python
synthetic_data = my_synthesizer.sample(scale=10)
```

Note that you may need to sample many data points in order to see the extrapolated values. Alternatively, you can request the extrapolated values explicitly. For example, say your training data only included users aged 25-60 but your range extrapolation extends the ranges from 18-100. You can then request synthesizing any age between 18 and 100.

```python
from sdv.sampling import Condition

older_users = Condition(
    num_rows=10,
    table_name='users',
    column_values={'age': '90'})

younger_users = Condition(
    num_rows=10,
    table_name='users',
    column_values={'age': '18'})

synthesizer.sample_from_conditions([older_users, younger_users])
```

For more information, see the API docs for [conditional sampling](/sdv/sampling/conditional.md).


---

# 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 current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sdv.dev/sdv/modeling/configuration/range-extrapolation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
