# backfill

URL: /business/nouns/dataset/backfill · Id: `verb:Dataset.backfill` · Call: `await $.Dataset.backfill({ … })` (SDK) or the `do` tool at `https://api.sb/mcp`. Inputs says what to pass, Outputs what returns, When it waits who approves.

> Backfill reads one Source of a Dataset over a past date range and records every value observed in it.

Backfill reads one [Source](/business/nouns/source) of a [Dataset](/business/nouns/dataset) over a past date range and records every value observed in it.

## Inputs
| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `dataset` | [Dataset](/business/nouns/dataset) | Yes | The Dataset. |
| `source` | [Source](/business/nouns/source) | Yes | The Source to read. |
| `from` | `date` | Yes | The first day of the range. |
| `to` | `date` | Yes | The last day of the range. |

## Outputs
| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `dataset` | [Dataset](/business/nouns/dataset) | Yes | The Dataset, with the range filled. |

## Effects
| Fact | Value |
| --- | --- |
| Action class | None: no approval rule names it, so it runs within its seat's Permissions and Limits |
| Stakes | The Startup's own records only |
| Door | Two-way: it runs at once |
| Modes | `try` previews it and stores nothing; `send` returns a pending Action; `do` (default) waits for the result |
| Idempotent | Only with a key: a repeat with the same `Idempotency-Key` and input returns the first Action, the same key with other input is refused with `409`, and a repeat without a key runs again |
| Undo | [Action.undo](/business/nouns/action/undo) reverses it |
| Emits | [`Dataset.backfilled`](/business/events/Dataset.backfilled) |
| Performed by | The [Data Engineer](/agents/engineering/data-engineer) |

## Refuses when
| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
| `dataset` is missing, or is not a dataset | [`invalid-input`](/code/api/errors/invalid-input) | Send `dataset` as a dataset, then call it again. | None. |
| `source` is missing, or is not a source | [`invalid-input`](/code/api/errors/invalid-input) | Send `source` as a source, then call it again. | None. |
| `from` is missing, or is not a date | [`invalid-input`](/code/api/errors/invalid-input) | Send `from` as a date, then call it again. | None. |
| `to` is missing, or is not a date | [`invalid-input`](/code/api/errors/invalid-input) | Send `to` as a date, then call it again. | None. |
| The `Idempotency-Key` was sent before with another operation or other input | [`idempotency-mismatch`](/code/api/errors/idempotency-mismatch) | Send a new key for new input; reuse a key only to retry the same request. | None. |

## When it waits
| Gate | Default |
| --- | --- |
| Decision class | Low: two-way, no delay window |
| [Delay window](/systems/trust-and-governance/controls/one-way-windows) | None: it runs once review passes. |
| Limit | The call [Limit](/business/nouns/limit) of the [Permission](/business/nouns/permission) it runs under. |
| Over the Limit | It waits `pending` for an [Approval](/business/nouns/approval), which a Human answers: the owner of record, or a Human they named to approve for the [Founder](/agents/founding/founder) seat. Approved, it runs; refused, it ends `refused` with [`limit-exceeded`](/code/api/errors/limit-exceeded); unanswered by its deadline, it ends `canceled`. |

## Example

**Ask**

```text
Backfill the latest dataset with a source.
```

**API**

```bash
curl -X POST https://api.sb/ratebook.dev/datasets/dataset_UDQXk0KsJB/backfill \
  -H "Authorization: Bearer $SB_TOKEN" \
  -H "Idempotency-Key: ratebook-dataset-backfill-1" \
  -H "Content-Type: application/json" \
  -d '{"source":"source_DIdhfB6mF5","from":"2026-10-22","to":"2026-10-22"}'
```

```json
{
  "api": "https://api.sb/ratebook.dev",
  "dataset": {
    "$id": "https://api.sb/ratebook.dev/datasets/dataset_UDQXk0KsJB",
    "$type": "Dataset",
    "name": "Ratebook",
    "promise": "A rate for any US address in under 100 milliseconds.",
    "status": "draft"
  },
  "action": {
    "$id": "https://api.sb/ratebook.dev/actions/act_M5LgINdysq",
    "operation": "Dataset.backfill",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/ratebook.dev/actions/act_M5LgINdysq"
  }
}
```

**CLI**

```bash
npx startup-builder do Dataset.backfill --data '{"dataset":"dataset_UDQXk0KsJB","source":"source_DIdhfB6mF5","from":"2026-10-22","to":"2026-10-22"}' \
  --idempotency-key ratebook-dataset-backfill-1
```

**MCP**

```json
{
  "name": "do",
  "arguments": {
    "code": "return await $.Dataset.backfill({ dataset: 'dataset_UDQXk0KsJB', source: 'source_DIdhfB6mF5', from: '2026-10-22', to: '2026-10-22' })",
    "idempotencyKey": "ratebook-dataset-backfill-1"
  }
}
```

**SDK**

```ts
import { $ } from 'startup-builder'

const dataset = await $.Dataset.backfill({ dataset: 'dataset_UDQXk0KsJB', source: 'source_DIdhfB6mF5', from: '2026-10-22', to: '2026-10-22' }, { idempotencyKey: 'ratebook-dataset-backfill-1' })
```

To retry, send the same `Idempotency-Key`: the retry returns the first Action and runs nothing twice. A new key runs the call again.