> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tabsutra.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Time and leakage

> How to date your rows so that no prediction reads the future, and how to test that it does not.

Leakage happens when a model reads, during validation, information that would not exist at the moment the prediction is made. The validation score then looks better than the model will be in use. In business data, leakage usually comes from time: a column that was filled in later, an answer that was not known yet, or a row that was changed after the fact.

tabSutra can rule out most of these problems for you. To do that, it needs to know when each row and each answer became known.

## Three moments in the life of a row

| Moment | Setting | Example |
| - | - | - |
| When the row happened | `time_column` | The month-end date of an account snapshot. |
| When the row's values were known, if earlier | `known_column` | A delivery stop whose time was planned when the route set off. |
| When the row's answer was known | `target_delay_days` after the row's time | A recovery amount for the following month is known about 31 days after the month-end. |

With these settings, the model applies two rules.

* A row to predict reads only the context answers that were known strictly before its own values were known.
* A row reads the earlier rows of its own group, such as its account, and never the later ones.

## Date rows by when they became known

The most common source of leakage is a date that does not say when the information was available. Some examples:

* A monthly table where the month's balance is dated at the start of the month, although it is only final at the end. Date it at the end.
* A bureau score fetched today and joined to an application from last year. The score has to be the one that was known on the application date.
* A loan's `status` field that is overwritten when the loan defaults. Reading today's status on an old row reads the answer.

> [!WARNING]
>
> Columns that are overwritten in place leak. If a field in your source system is updated after the fact, such as a current status, a last contact date or a running total, the old rows carry today's value. Use a history table that keeps each value with its own date, or leave such columns out with `column_types` or `exclude_columns`.

## When the answer is not known at once

Many targets describe a period after the row. A default flag covers the 12 months after an application, and a monthly recovery covers the month after a snapshot. Such an answer exists only once the period has ended.

Set `target_delay_days` to the length of that period. A context row then counts as known only from its time plus the delay. Without this setting, a row would read the answers of rows a few days older than itself, although those answers were not known yet when the row was made.

In a database task, the same idea is set by `window_days`. The answer is about the `window_days` days after the date, and an example's answer counts as known that long after its date.

## Standing at a date in the past

To test what the model would have predicted on a given day, use `as_of`. With `as_of`, the model uses only what was known on that date.

* Rows known after the date are left out.
* Answers known only after the date are left out.
* A group answer, such as a total recovery, is left out if the group was still open on that date.

A `/v1/fill` call with `as_of` predicts the rows whose answer came only on or after the date. You can then compare its predictions with what really happened.

```python theme={null}
backtest = requests.post(f"{API}/v1/fill", headers=HEADERS, json={
    "rows": records(history), "target": "recovered_pct", "task": "regression",
    "time_column": "month", "group_column": "account_id", "target_delay_days": 31,
    "as_of": "2026-07-31",
}).json()
```

## Evaluating over time

With a `time_column`, `evaluate` holds out the latest rows. Each held-out row is predicted from what was known before it, including the answers of earlier held-out rows that were already known by then. This is how the model would behave if it were run every day. Nothing from the held-out period shapes how the context is read.

For a database, `evaluate` holds out the examples of the latest dates and predicts them from the earlier ones. For a forecast, it holds out the last steps of every series, and the model sees only the history before them.

## What the model checks for you

* A database row never reads a row of any table dated on or after its own date. This holds for the entity's own columns, its events, its earlier answers, and the rows its events point at.
* If you predict rows that are dated before the latest answer in the context, the report warns you. The answers that came later are not read by those rows, but they were part of the context, so the test is not fully out of time. For a fair test, use `evaluate` or `as_of`.
* If a row you predict is also in the context with its answer, and the table has no time column, the report warns you. A score on such rows says little about new rows.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.