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

# Tasks described in words

> Describe the answer you want, and let tabSutra build the labelled examples from the database.

For a database prediction you normally provide labelled examples: an entity, a date and the known answer. Building them is often the slowest part of a project. You have to pick the dates, compute each answer from the event tables, and make sure no answer reads past its window.

For many common questions you can skip this step. You describe the answer, and tabSutra builds the examples for you.

## Three kinds of task

| Kind | Question | Returns |
| - | - | - |
| `next_days` | A measure of each entity's events in the next N days. | A prediction per entity. |
| `next_items` | The items each source will link to in the next N days. | A ranked list per source. |
| `fill_column` | The empty values of one column of a table. | A prediction per row with an empty value. |

The examples use a database sent as in [Databases](https://docs.tabsutra.com/guides/databases.md), and the `API`, `HEADERS` and `records` set up in the [Quickstart](https://docs.tabsutra.com/quickstart.md).

## next\_days

```python theme={null}
spend = requests.post(f"{API}/v1/databases/{database_id}/tasks/predict", headers=HEADERS, json={
    "task": {"kind": "next_days", "entity": "customers", "events": "orders",
             "measure": "sum", "column": "amount", "window_days": 30},
    "at": "2026-06-01",
    "target_range": [0, None],
}).json()
```

This asks for the total order amount of each customer in the 30 days after 1 June 2026.

The fields are:

| Field | Meaning |
| - | - |
| `entity` | The table whose rows get an answer. |
| `events` | The table of events the answer counts. It needs a time column and a key that leads to the entity. |
| `through` | The keys from the events to the entity, when there is more than one way, for example `["seller_id"]`. |
| `measure` | What to compute over the events in the window. See below. |
| `column` | For `sum`, `mean` and `max`: a numeric column of the events. |
| `where` | For `share` and `any_matching`: a condition on the events, as `{"column", "op", "value"}`. `op` is `eq`, `ge`, `le` or `missing`. |
| `threshold` | For `more_than`: the number of events. |
| `window_days` | The length of the window after the date. |
| `rows` | Which entities get an answer: `all` (every entity that exists by the date; the default), `active` (those with an event in the window before the date), or `with_events` (those with an event in the window itself). |
| `exclude_columns` | Columns the model must not read, as `"table.column"`. |

The measures are:

| Measure | Answer | Task |
| - | - | - |
| `count` | the number of events | regression |
| `sum`, `mean`, `max` | the sum, mean or largest value of `column` | regression |
| `share` | the share of the events that match `where` | regression |
| `any` | yes if there is at least one event | classification |
| `none` | yes if there is no event (churn) | classification |
| `more_than` | yes if there are more than `threshold` events | classification |
| `any_matching` | yes if at least one event matches `where` | classification |

A mean, a maximum and a share need at least one event in the window. With `rows` set to `all`, an entity with no event in an example's window gets no example for that date.

## How the examples are built

You give the date to stand at with `at`. By default it is the database's last date. tabSutra then:

1. picks 12 dates, one window apart, the latest one window before `at`, so that every answer is known by `at`;
2. leaves out dates that have less than two windows (or a tenth of the database's span) of history before them;
3. computes the answer of every entity at each date from the events in the window after it;
4. predicts the answer at `at` for the entities chosen by `rows`.

Change the number of dates with `n_dates`. Nothing dated after `at` is read, so you can stand at a past date and compare the predictions with what happened.

The report lists the dates of the examples and the number of examples made.

## next\_items

```json theme={null}
{
  "task": {"kind": "next_items", "source": "customers", "items": "products",
           "events": "orders", "window_days": 30, "k": 10},
  "at": "2026-06-01"
}
```

By default the sources are those with a link in the window before `at`. To choose them yourself, add `"rows": [list of source keys]`. The answer is a recommendation, as described in [Recommendation](https://docs.tabsutra.com/guides/recommendation.md).

## fill\_column

```json theme={null}
{"task": {"kind": "fill_column", "table": "customers", "column": "segment", "task": "classification"}}
```

This predicts the empty values of `segment` from the rows of `customers` that have one. It reads it as a table, including its text columns. Send these bodies to `/v1/databases/{database_id}/tasks/predict`.

## Evaluate a task

`/v1/databases/{database_id}/tasks/evaluate` builds the examples in the same way and holds out the latest dates.

```python theme={null}
result = requests.post(f"{API}/v1/databases/{database_id}/tasks/evaluate", headers=HEADERS, json={
    "task": {"kind": "next_days", "entity": "customers", "events": "orders",
             "measure": "none", "window_days": 30, "rows": "active"},
}).json()
print(result["ours"], result["simple_rules"])
```

For `next_items` it gives MAP\@k, and for `fill_column` it gives the scores of a table.


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