# Data format

> Decision rows, question types, hard and soft labels, datums and limits: the data for custom projects.

Part of the Endor docs. Index of every page: https://endor.thetokencompany.com/llms.txt. HTML version: https://endor.thetokencompany.com/docs/data-format.

This data is for [custom projects](https://endor.thetokencompany.com/docs/training): datasets, evaluations and training calls. A continuous model needs none: it learns from its decisions.

## Decision row

A row is a TypeSafe decision request with labels:

```json
{
  "id": "t-1",
  "state": {"body": "I was billed two times for my March invoice."},
  "questions": {
    "department": {"type": "choice", "instructions": "Which team must handle `body`?",
                   "criteria": {"billing": "Payments, refunds", "technical": "Bugs, outages"}},
    "urgent": {"type": "noul", "instructions": "Does the customer need an answer today?"}
  },
  "labels": {"department": "billing", "urgent": true},
  "weight": 1.0
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `state` | string, object or array | yes | The input. All questions use the same state. |
| `questions` | object | yes | One or more questions, by name. |
| `labels` | object | no | The correct answer for each question name. Training skips questions without a label. An evaluation scores the labeled questions of a row, and answers every question of a row without labels. |
| `id` | string | no | Your row id. |
| `weight` | number ≥ 0 | no | The weight of the row in training. Default: 1. |

## Question types

| `type` | `criteria` | Option ids |
|---|---|---|
| `noul` (yes/no) | optional: `{"true": ..., "false": ...}` | `"false"`, `"true"` |
| `choice` | `{"option_id": description or null}`, 1 to 255 options | the keys, in order |
| `score` | a list of level descriptions of one scale, lowest level first, 2 to 10 levels (not a list of things to check) | `"0"` to `"n-1"` |

Each question can also have `instructions` (text or JSON). Labels, training targets and answers use the option ids. Some base models have stricter rules (see [Base models](https://endor.thetokencompany.com/docs/base-models)).

## Labels

A hard label gives one correct option. A soft label gives a probability for each option.

| Type | Hard label | Soft label |
|---|---|---|
| `noul` | `true` or `"true"` (`false` or `"false"`) | `0.8` (probability of yes) or `{"true": 0.8, "false": 0.2}` |
| `choice` | `"billing"` | `{"billing": 0.7, "technical": 0.3}` |
| `score` | `2` (level index) or `"2"` (its option id) | `[0.1, 0.6, 0.3]` or `{"0": 0.1, "1": 0.6, "2": 0.3}` |

A soft label must include all options. The values must be 0 or more, and their sum must be 1 (± 0.02).

## Files

`endor.data.load_rows(path)` reads `.jsonl` (one row on each line) or `.json` (an array). It also accepts rows with one question. The SDK names that question `decision`:

```json
{"state": "I was charged twice", "question": {"type": "noul", "instructions": "Is this a billing issue?"}, "label": true}
```

```python
import endor

client = endor.EndorClient()
info = client.datasets.upload("train", endor.data.load_rows("train.jsonl"))
print(info.n_rows, info.question_types)
```

The upload checks all rows first. If a row is not valid, the upload fails with `422 invalid_row`, `param` gives the row (`rows[12]`), and the message gives the field and what fits there, for example `rows[12]: labels.anger: '5' is not an option of this question (options: 0, 1, 2)` or `rows[3]: questions.urgent: a question needs a type: noul, choice or score`. A body that isn't valid JSON fails with `400 invalid_input`. Endor keeps no rows from a failed upload. Rows sent with an evaluation are checked the same way.

## Datum

Training calls use datums. A datum is one state, one question, one target and a weight:

```json
{"state": "I was charged twice",
 "question": {"type": "noul", "instructions": "Is this a billing issue?"},
 "target": {"label": "true"},
 "weight": 1.0}
```

The target is `{"label": "<option id>"}` or `{"probs": {"<option id>": p}}`. It is not the same shape as a row's label: a soft label is the probability map itself, and a soft target puts that map in `probs`.

| | A row's `labels` value | A datum's `target` |
|---|---|---|
| Hard | `"billing"` | `{"label": "billing"}` |
| Soft | `{"billing": 0.7, "technical": 0.3}` | `{"probs": {"billing": 0.7, "technical": 0.3}}` |

`endor.data.rows_to_datums(rows)` makes one datum from each labeled question, with the target made from the label.

## Limits

| Item | Maximum |
|---|---|
| Rows in a dataset | 50,000 |
| Datasets in an organization | 1,000 |
| Dataset storage in an organization | 200 GB |
| Questions in a decision request | 64 |
| Options in a `choice` | 255, or less on some base models |
| Levels in a `score` | 10 (minimum 2) |
| Datums in a training call | 1,024 (the SDK splits larger batches) |
| Request body | 64 MB for a dataset upload, 32 MB for an evaluation or a training call (gzip accepted) |

## Other pages

- [Overview](https://endor.thetokencompany.com/docs/index.md): What Endor does: you train decision models on your labeled data in custom projects with the SDK, Endor runs the GPUs, and you call them by name. Continuous models are for invited organizations.
- [Quickstart](https://endor.thetokencompany.com/docs/quickstart.md): Start here: install the SDK, measure base models on your data, train a model in a custom project, evaluate it, promote it and call it.
- [Core concepts](https://endor.thetokencompany.com/docs/concepts.md): Organizations, continuous models and their production and preview versions, names, base models, custom projects, datasets, runs, evaluations and futures.
- [Custom projects](https://endor.thetokencompany.com/docs/training.md): Custom projects (custom_models in the SDK and API): train a model with the SDK, save, promote to production, call, download; the training loop in detail.
- [Continuous models](https://endor.thetokencompany.com/docs/continuous-learning.md): Continuous models (projects in the SDK and API), only available to invited organizations: create one, call its production version or its preview, auto-promote, promote and roll back versions, feedback, price.
- [Decisions](https://endor.thetokencompany.com/docs/decisions.md): Decisions with the SDK and over HTTP, model names, giving feedback on them, TypeSafe clients, cold starts, errors.
- [Base models](https://endor.thetokencompany.com/docs/base-models.md): The 18 base models: limits, rules, prices and cold starts.
- [Billing & limits](https://endor.thetokencompany.com/docs/billing.md): Prices, the prepaid balance, usage and limits.
- [API reference](https://endor.thetokencompany.com/docs/api.md): Each /v1 endpoint: method, path, body fields, response fields and errors.
- [Python SDK](https://endor.thetokencompany.com/docs/sdk.md): The Python SDK (0.9.0): client, continuous models (client.projects) and versions, custom projects (client.custom_models), datasets, runs, evaluations, futures, data helpers, recipes, errors, CLI.
- [Updates](https://endor.thetokencompany.com/docs/updates.md): Changes to the API and SDK, newest first, and when old names and endpoints stop working.
- [Index](https://endor.thetokencompany.com/llms.txt): every page and the API schema.
