> ## 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.

# Sequences

> Rows in a known order, usually dated, often many per customer, account, vehicle or machine.

Much business data comes as sequences. An account has a row for every month, a customer has a row for every visit, and a machine has a row for every reading. Rows of this kind are not independent of each other. A row's answer often depends on the rows that came before it, and the answer of one month is only known some time later.

The order of such rows carries meaning. A payment that shrinks a little every month, or an alarm that keeps coming back, is lost when the rows are summed up into features. tabSutra reads the rows in their order instead.

This guide shows how to tell the model about the time order and the groups in your table. It uses the same calls as a table, with a few more settings. The examples use the `API`, `HEADERS` and `records` set up in the [Quickstart](https://docs.tabsutra.com/quickstart.md).

## The settings

| Setting | Meaning |
| - | - |
| `time_column` | When the row happened: a date, or a number of days. |
| `group_column` | Which rows belong together, such as the months of one account. |
| `target_delay_days` | How long after the row's time its answer is known. Default 0. |
| `known_column` | When the row's values were known, if before its time. Default: the row's time. |
| `group_target` | A column with the group's own answer, such as an account's total recovery. Empty while the group is open. |
| `group_task` | `classification` or `regression` for the group answer. Default: the same as `task`. |
| `group_target_range` | A range the group answer is clipped to. |
| `as_of` | Stand at a date and use only what was known then. |

You can use any of them on its own. A table with only a `time_column` is a table of dated records, such as daily transactions. A table with only a `group_column` is a table of groups without time, such as the employees of companies. If rows have an order but no dates, give each row its position in the group as a number in the `time_column`.

## What the model does with them

With a `time_column`, a row to predict reads only the context answers known strictly before the row's own values were known. A context answer counts as known from the row's time plus `target_delay_days`.

The `time_column` is also read as an input. Every other date column is read relative to the row's time.

With a `group_column`, a row also reads the other rows of its group. With a `time_column` as well, it reads only the earlier ones and never the later ones. The group column is not read as a feature itself.

## An example: monthly account snapshots

```csv account_months.csv theme={null}
account_id,month,balance_due,payments_made,calls_answered,promise_to_pay,recovered_next_month
AC1042,2026-05-31,100.0,0,1,no,0.0
AC1042,2026-06-30,100.0,0,3,yes,12.5
AC1042,2026-07-31,87.5,1,2,yes,
AC2210,2026-06-30,100.0,0,0,no,0.0
...
```

Each row is one account at one month-end. The target `recovered_next_month` is the amount recovered during the month after the row, as a share of the original amount due. It is known at the end of that following month, about 31 days after the row's date.

```python theme={null}
sequence_settings = {"time_column": "month", "group_column": "account_id", "target_delay_days": 31}

fitted = requests.post(f"{API}/v1/fit", headers=HEADERS, json={
    "rows": records(history), "target": "recovered_next_month", "task": "regression",
    "target_range": [0, 100], **sequence_settings,
}).json()
scored = requests.post(f"{API}/v1/predict", headers=HEADERS, json={
    "context_id": fitted["context_id"], "rows": records(latest_rows),
}).json()
```

The last row of `AC1042` has no answer yet, so it is not a context row. You send it to `/v1/predict`.

## Send the open rows of a group together

The rows of a group are predicted together, and they read each other in time order. If a group has more than one row without a known answer, send all of those rows in the same `/v1/predict` call. Otherwise the later row cannot read the earlier one.

In the example above, with a delay of 31 days, the rows of the last month are always open. With a longer delay, several months per account are open at once, and all of them go in the same call.

## Group answers

Sometimes the group itself has an answer. An account's total recovery is known once the account is closed. A delivery route's total time is known once the route is finished. Put that answer in a column, on any or all of the group's rows, and name it as `group_target`. Leave the column empty while the group is still open.

```python theme={null}
fitted = requests.post(f"{API}/v1/fit", headers=HEADERS, json={
    "rows": records(history), "target": "recovered_next_month", "task": "regression", **sequence_settings,
    "group_target": "total_recovered", "group_target_range": [0, 100],
}).json()
scored = requests.post(f"{API}/v1/predict", headers=HEADERS, json={
    "context_id": fitted["context_id"], "rows": records(latest_rows),
}).json()
print(scored["predictions"][0]["group"])      # this row's prediction of its account's total
```

A group's answer counts as known `target_delay_days` after the group's last row. Every row you predict then carries two predictions: the row's own answer, and the group's answer as of that row's time. At least four groups with a known answer are needed.

A group must have one answer. If two rows of a group give different values, the call stops with the error `group_target_varies`.

## Values known before the row's time

Sometimes a row's values are fixed before the row happens. The stops of a delivery route are planned when it sets off, and an instalment schedule is fixed when the loan is signed. Put the date the values were fixed in a column and name it as `known_column`. The model then reads each such row as of that date. It does not read answers that came between that date and the row's own time.

## Evaluate

With a `time_column`, `/v1/evaluate` holds out the latest rows by the time they were known. Each held-out row is predicted from what was known before it. With a `group_column` and no time column, it holds out whole groups instead, chosen by the group's name.

```python theme={null}
result = requests.post(f"{API}/v1/evaluate", headers=HEADERS, json={
    "rows": records(history), "target": "recovered_next_month", "task": "regression", **sequence_settings,
    "group_target": "total_recovered", "holdout": 0.2,
}).json()
print(result["ours"], result["baseline"])
print(result["group"])                        # the same scores for the group answer
```

## Backtest at a past date

`/v1/fill` with `as_of` stands at a past date. It uses only what was known on that date, and it predicts the rows whose answer came on or after it. Rows known after the date are left out.

```python theme={null}
backtest = requests.post(f"{API}/v1/fill", headers=HEADERS, json={
    "rows": records(history), "target": "recovered_next_month", "task": "regression", **sequence_settings,
    "group_target": "total_recovered", "as_of": "2026-07-31", "id_column": "row_id",
}).json()
```

Changing anything dated after `as_of` does not change these predictions. You can compare them with what happened afterwards.

## Things to check

* The fit report has a `history` section. It shows the time range, the number of groups, the largest group and the number of groups with a known answer. A very large group is slower to read.
* Date rows by when their values became known. See [Time and leakage](https://docs.tabsutra.com/concepts/time-and-leakage.md).
* A row without a date is left out of the context, and a row without a date cannot be predicted.


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