# Dataset health

On this page you check a dataset for items that would not train as you expect, decide what to do about
each finding, and see which findings come from a [similarity scan](./similarity-scans.md).

**Where to find it.** In the app, a dataset's page has a **Health** card, folded by default (**Show details**
opens it, **Re-check** counts again), a **Health** filter on the item list, and a health column whose chip names an item's worst
finding and opens it: a triplet opens; a chat opens in the review of that check (a blocking one in the review of
every chat that won't train as written), and copies, conflicting answers and conversations open their groups. A
chat or triplet page lists that item's checks, with the fixes that apply, **Keep as is** and **Acknowledge**. Groups
of copies and conversations, near-duplicate groups, suggested negatives and **Find similar** open as
dialogs, and conversations also have a page of their own. Opening a check from the card (or its **Review**
button) lists the items it flags, and **Review one by one** steps through them, chats and triplets alike,
blocking ones first, with "N resolved · M left" counting the items that left the list during this pass. The
count starts again at 0 when the page is reloaded. **Back to dataset health** returns to the dataset page with
that check's row open. Everything the app does here goes through the routes on this page, which is also the
whole story for an API key. One thing has only part of a screen: the app fixes many chats at once only for
`delete_last_turn` (a list filtered to the `ends` check offers **Delete the last turn in N chats**; `merge_turns`
in bulk is a route only). The list of validation items that have a near-duplicate in training opens from the
**New run** page's leakage line, and also from this card: when the dataset's latest run validated on a tag and the
latest finished scan found open near-duplicates for it, the Warnings group has a row for them with **Review N**
(nothing is drawn for no run, an automatic split, no finished scan or a count of 0, because none of those is a
finding). When the count is 0 but some validation items have a copy you kept in training (**Keep both**, or a group
you kept), the card says so in one neutral line instead, "No open near-duplicates between validation and training. You
kept N as is." (queries in an embedding dataset: "You kept both copies of N"), and the **New run** page says the same in
place of "found no near-duplicate". The **Health** filter shows beside each state and scan status the number of items it matches, and a check
whose acknowledgement still covers its items reads "... · acknowledged". In a text dataset it also lists the
preference-pair checks ("Rejected reply nearly the same as the chosen one", for example) and a **Preference pairs**
group, **Has a rejected reply** and **No rejected reply**; in an embedding dataset, when that leakage row exists, it
lists **Validation query near-duplicates training**, which keeps the validation triplets the scan paired with a
training one. A run also refuses a chat that cannot train (below).

Every check is a **pattern or count rule**. It looks at structure, counts and text shapes, never at
whether an answer is good, and a finding never contains your text: it names offsets and counts.

## The card {#the-card}

```text
GET /api/v1/projects/{owner_slug}/{project_number}/datasets/{dataset_number}/health
```

For a chat dataset or an embedding dataset, it returns one row per check that has open findings, blocking
checks first, then warnings by count, then notes; the checks you acknowledged; how many checks passed;
a token histogram; coverage; the latest scan line; and `calibrated: false` for the scan-backed checks.

It also carries what the **Health** filter and the leakage review need, each only when it is known:

- `state_counts`: how many items each filter state matches (`blocking`, `warning`, `none`,
  `acknowledged`). Each number is the total the item list answers for that filter alone, over the live
  items.
- `scan_counts`: the same for the scan statuses (`new`, `open`, `resolved`). It is `null` while no scan has
  finished, because those filters match nothing and a zero would read as "no findings".
- `validation_tag`: the name of the tag your **latest training run** on this dataset froze as its
  validation set. A dataset has no validation tag of its own: you choose one for each run, so this is the
  last run's choice. It is `null` when there is no run, when the latest run validated on an automatic split
  or a saved view instead, and when that tag has been deleted. An earlier run's tag is not carried forward.
- `leakage`: for that tag, how many validation items have an open near-duplicate in the training items
  (`count`, `capped`, `scan_number`, `checked_at`), read from the latest finished scan the way the New run
  estimate reads it, and `kept`, the validation items with a copy you chose to keep on the training side (see
  [Similarity scans](./similarity-scans.md#run-estimate-leakage)). It is `null` without a `validation_tag` or
  without a finished scan: not checked, never zero.
- `pair_counts` (a chat dataset; `null` for an embedding dataset): how many chats each preference-pair filter
  matches: `has_rejected` and `no_rejected` (the `pair` filter), and `same`, `empty`, `too_long`, `shortened` and
  `near` (the `pair_check` filter). Each number is the total the item list answers for that filter alone, over the
  live chats. `near` is `null` while the small-edit line is not recorded. See
  [Preference pairs](../training/preference-pairs.md#find-and-count-pairs).

Each check has a stable key and a severity:

- **`error`** blocks training. An item with an error cannot train as written.
- **`warn`** is worth reading. You can acknowledge it or keep an item as it is.
- **`info`** is a note.

### Chat checks

| Key | Severity | What it looks for |
| :-- | :-- | :-- |
| `reply` | error | No assistant message |
| `system` | error | Two system messages at the top, one after the first user turn, or no user message |
| `tokens` | error | A special token of the chat template written inside a message |
| `ends` | warn | The last message is a user message |
| `turns` | warn | Two user or two assistant turns in a row |
| `length` | warn | A chat over 2,048 tokens, chat template included |
| `think` | warn | A `<think>` block, or text ending in `</think>`, in an assistant reply that is not the last |
| `short` | warn | An assistant reply under 5 words that trains (a reply switched to context only, `weight` 0, is not trained and is not counted) |
| `pii` | warn | An email address, a phone number or a Brazilian identity document (CPF, CNPJ, CNH, PIS or NIS, voter registration, RG) |
| `dup` | warn | The same messages as another chat, after trimming surrounding spaces |
| `conflict` | warn | The same user turns with a different reply |
| `convo` | warn | The start of a longer chat, both saved by auto-save |
| `thin` | warn | A tag on under 5% of the items |

### Triplet checks

| Key | Severity | What it looks for |
| :-- | :-- | :-- |
| `pos` | error | No positive |
| `idpos` | error | The positive equals the anchor |
| `same` | error | The positive equals the negative |
| `crossneg` | error | The negative is a positive of the same anchor in another triplet |
| `multipos` | info | An anchor with more than one positive |
| `neg` | info | No negative |
| `length` | warn | A passage over 512 tokens |
| `pii`, `thin` | warn | As for chats |
| `near`, `label`, `far` | info, warn, warn | Written by a [scan](./similarity-scans.md) |

Honest limits of these checks:

- `length` counts tokens in a re-check, never when an item is written, so it reports nothing until a
  re-check has counted the item. `histogram.counted` says how many items the histogram covers. A token
  count that was not made is `null`, never zero.
- `pii` is a pattern check, not a detector: it finds text shaped like an email address, a phone number or a
  Brazilian identity document (next item) and says where, never what. We measured it on public test sets of generated text with labelled
  addresses and numbers (English, Portuguese and four other languages). It found 92% to 100% of the
  labelled email addresses. It found 93% to 100% of the labelled phone numbers, and 71% of the German
  ones: a number written as plain digits with no separator is missed (a number with an extension, such as
  `123-456-7890x123`, is found with its extension). Its phone hits are still noisy. Depending on the set,
  29% to 100% of what it reported as a phone number was one according to the labels. It no longer
  reports dates, timestamps, year ranges, decimals, IP addresses, Brazilian postal codes, an estimate with a decimal range (`14.7 (13.4-15.7)`) or a space-grouped count followed by a parenthesised decimal or percentage (`26 061 (15.0%)`) as phone numbers, and a CPF is no longer
  reported as a phone number, but numbers of a similar shape are still reported: invoice and order codes, ISBN codes, four-part version numbers, other amounts
  written with spaces, ranges written with whole numbers and bank account numbers (the labels miss a few real
  numbers, so these are floors). On ordinary chat text with no contact details it still flagged about 4
  chats in 1,000, mostly numbers in tables and code. These sets are generated text, not your data, so
  read the figures as limits of the pattern, not as a forecast. It will miss personal data written
  another way, so do not read a clean result as proof that a dataset holds none, and do not read a hit as
  proof that it does. A hit stored before the patterns last changed stays as it was until a
  [re-check](#recheck) recomputes the item.
- `pii` looks for Brazilian identity documents: the CPF, CNPJ (the numeric number and the alphanumeric one), CNH, PIS
  (also PASEP, NIS and NIT), voter registration (título de eleitor) and RG. A number is reported only when its check
  digits are valid, which every one of them has except the RG. A CPF or CNPJ written with its usual dots, dash or slash
  (`123.456.789-09`, `12.345.678/0001-95`) is found by itself; written as plain digits it is found only right after its
  word (`CPF`, `CNPJ`) on the same line, and a PIS, CNH or voter registration always needs its word (`PIS`, `NIS`,
  `CNH`, `carteira de habilitação`, `título de eleitor`). A word counts only as a whole word: `CPFL`, `RGE`, `nisso`,
  `pista` and `Nissan` are not document words, `CNH Industrial` is a company, and `PIS/COFINS` is a tax (`PIS/PASEP` is
  the document). The RG has no national check digit: it is found only after `RG` (in capitals: a lowercase `rg` is the
  search tool ripgrep and is not read), `identidade`, `registro geral` or `documento de identificação` (in any case) and
  in the usual shape of 7 to 9 digits (`12.345.678-9`, `12345678`, `12345678-X`, with its check character), so a number
  after that word is reported unless another label stands between the word and the number (`RG e CEP: 01310100`, a
  protocol, a date, a phone number): then it is that other thing. When two documents follow one joint label (`CPF e RG:
  ... / ...`) and the numbers are as many as the labels, each number is read as the document its position names. A
  number that is a valid CNH and also passes the CPF digits (about 1 in 10) is a CNH after the word `CNH` and a CPF
  otherwise. It does not find a plain number with no word before it, a word more than a few characters or a line away, a
  number cut off, masked or mistyped, a passport or a document of another country. A number that passes the check digits
  is reported whether or not it belongs to anyone: about 1 random number in 100 written like a CPF passes, and about 1
  in 10 after the word `PIS`. We measured the CPF and CNPJ on public labelled data: on a generated set it found all
  1,603 labelled CPF and 1,601 labelled CNPJ with no false report (that set writes valid digits and a word before most
  numbers, so read it as a format result), and on a generated banking chat it found 76 of 78 labelled CPF (97%; it
  missed one cut off and one with no word before it) and 6 of its 82 reports were valid CPFs that the labels call a Pix
  key. No public labelled set covers the CNH, PIS, voter registration or RG, so we measured all six on two sets of 8,100
  short Portuguese texts we generated, with invented numbers, one for each of two random seeds (chats, notes, e-mails,
  contract clauses, forms and lists; no customer data). Written the way described above (the word near it, a usual
  shape, a valid number), every one was found in both sets: 530 of 530 CNH, 500 of 500 PIS, 505 of 505 voter
  registrations and 585 of 585 RG (each at least 99.2%, 95% confidence), and 1,080 of 1,080 CPF and 585 of 585 CNPJ.
  Written another way they mostly are not found: a number with no word before it, the word after it or on another line,
  a word we do not list (`carteira de motorista`, `Título:`) or a shape we do not list. Of 2,550 texts with no document
  in them (wrong check digits, masked numbers, repeated digits, phone numbers, postal codes, bank accounts, order
  numbers, dates, words with no number) none was flagged, in either set. An earlier version of these rules (until
  November 18, 2026) also reported `RGE` followed by a number, the tax name `PIS/COFINS` next to an 11-digit number and
  any number after `RG` (`RG e CEP: 01310100`), read a CNH as a CPF, and missed the second document after a joint label;
  on the second set, which was generated after those fixes, none of 100 `RG e CEP` lines, 100 `PIS/COFINS` lines or 400
  lines with a word that only starts like a document word was flagged. A document word followed by a random number is
  still reported when the number happens to pass the check digits. Of the reports in the second set, the share that was
  right was 99.9% for the CPF, 99.5% for the CNPJ, 100% for the CNH, 98.3% for the PIS, 100% for the voter registration
  and 100% for the RG, but that share depends on the mix of texts we chose. **These sets measure the detector, not how
  customers actually write these numbers: do not read any figure in this paragraph as a real-world rate.** We wrote the
  texts after reading the rules, so neither set is a blind test. On 4,821 ordinary chats and 5,141 finance documents it
  reported no identity document, and neither did it on Brazilian text we wrote full of numbers that are not documents
  (phone numbers, postal codes, bank accounts, order and invoice numbers, dates). These sets are generated text, not
  your data. A hit stored before a change of these rules stays as it was until a [re-check](#recheck) recomputes the
  item; nothing is rewritten on its own.
- `near`, `label` and `far` use the scan's flag lines, which are starting values and **not calibrated**.
  A `far` finding says the positive scores unusually far from its anchor, and a `label` finding says the
  negative scores nearly as close as the positive: neither says the label is wrong, and `far` is a warning,
  never a block. The `far` line is 0.40 for a scan started now (0.50 before November 18, 2026); each scan
  keeps the line it was started with ([why](./similarity-scans.md#what-a-scan-finds)).
- A count is over live items that are not excluded from training, from results at each item's current
  revision. Items are checked as they are written; `checked_at` is when the last re-check finished and is
  `null` if none has, which does not mean unchecked.

### Data we measured on

The measurements above used public datasets of generated text; none is customer data. We used each as published, only to measure. The second and third also gave the labelled CPF and CNPJ for the identity-document figures. The CNH, PIS, voter registration and RG figures come from texts with invented numbers that we generated ourselves for this measurement; they are not customer data and not a public dataset.

- [gretelai/synthetic_pii_finance_multilingual](https://huggingface.co/datasets/gretelai/synthetic_pii_finance_multilingual), Apache-2.0
- [ai-safety-brazil/pii-br-synthetic](https://huggingface.co/datasets/ai-safety-brazil/pii-br-synthetic), CC BY 4.0 (by AI Safety Brazil, used unchanged to measure)
- [guardion/BR-Agentic-PII-Benchmark](https://huggingface.co/datasets/guardion/BR-Agentic-PII-Benchmark), MIT
- [OpenAssistant/oasst1](https://huggingface.co/datasets/OpenAssistant/oasst1), Apache-2.0 (ordinary chat text, to count false flags)

## Re-check {#recheck}

`POST .../health/recheck` starts a re-check of every item and answers `202` with the operation (a queued
or running one is returned as it is). Read progress with `GET .../operations/{operation_id}`. Inside five
minutes of the last re-check it answers `429 recheck_cooling_down` with `retry_after`.

## One item {#one-item}

`GET .../items/{item_number}/checks` returns that item's findings, with the offsets and counts that
trip each check, the checks it passes, the checks you kept, and any scan findings about it. When the
dataset has acknowledged a warning this item trips, that issue also carries `acknowledgement`: `id`,
`reason`, `note`, `created_at` and `reopened`. The **Checks** card draws the badge **Acknowledged** with
**Undo**, which is `DELETE .../health/acknowledgements/{id}` and brings the warning back as open. The
field is `null` when no acknowledgement covers the item at its current revision: an item you edited since
is not covered while it still trips, and an acknowledgement that a new or edited item reopened still
covers this one and reads `reopened: true`.
`POST .../items/checks/preview` checks an item you have not saved yet, with the same rules: send a chat's
`messages`, or a triplet's `anchor`, `positive` and `negative`, in the body. Nothing is stored. The answer lists the
`issues`, the checks it `passed`, and in `not_checked` the ones a draft cannot have (those that compare it with other
items, and its length), which run once it is saved. The app's new chat and new triplet pages show this as their
**Checks** card while you type. In a review queue (**Review one by one**), **E** excludes the item from training and
opens the next one. Filter the
item list by health in the same search you use for tags, and in a
[saved view](./chats.md#saved-views):

```json
{"health": {"states": ["blocking"], "checks": ["reply", "system"]}}
```

`states` is any of `blocking`, `warning` (not kept), `none` and `acknowledged` (the items an
acknowledgement covers as they are now: an item you edited since, so that it no longer trips the check, drops
out without undoing the acknowledgement); `checks` is any of the
keys above. `scan_status` reads the stored scan findings: `open` means a scan-backed issue at the item's current
revision, `new` an item of a finding the scan before the latest did not have (every finding is new when no scan
precedes it), `still_open` an item of a finding both the latest scan and the one before it have (none when no scan
precedes it), and `resolved` an item of a finding the scan before had and the latest lacks, only for a check the
latest scan ran (a scan of anchors only does not rescan `label`, `far` or `neg`, so those are not "resolved").
`leakage_tag` (a tag name, your validation set) keeps the items carrying that tag that the latest finished scan found
nearly duplicating a training item (an item without the tag that trains), the same pairs the leakage review lists for
that tag; a pair you kept with **Keep both** is left out until either item is edited. For your latest run's tag
(`validation_tag`), the list's total is the `leakage.count`. A tag no item carries matches none. A
dataset with no finished scan matches no item. Different fields narrow together; values inside one field are
alternatives. Send `"sort": "blocking_first"` to list the items a check stops from training first, then
the warnings you have not kept, then the rest, newest first in each (`400 invalid_cursor` if you reuse the cursor
with another sort, and `400 unsupported_filter` beside `pair: "has_rejected"`). A key the dataset's kind does not have
is `400 unsupported_filter`. A list row carries `issues` (up to three, worst first) and `issue_count`;
reading one item does not.

## Keep as is {#keep}

`POST .../items/{item_number}/checks/{check_key}/keep` (optional `note`) says this item trips a warning
or note and you mean it to. Only a warning or a note stored on the item can be kept: an error answers
`400 check_not_keepable`, and so does a check that compares items (act on its group instead). A check
the item does not trip is `409 check_not_open`. Keeping writes a history event and no revision, and
editing the item ends the decision. `DELETE` on the same path is Undo.

## Acknowledge {#acknowledge}

Acknowledging says that a **warning** is intended across the dataset:

On a chat or triplet page, the confirm names the other items the acknowledgement covers ("this one, #1088 and #1142", or
"... and 5 more" when there are more than five) and asks the server to check that list when you confirm: if it changed since
you looked, nothing is acknowledged, the list is read again and you are told. The item's History then carries a line for it
("acknowledged the warning for 3 triplets, ..."), with the reason, your note, and "reopened" or "undone" when it no longer
applies.

```json
{"check_key": "short", "reason": "intended", "note": "Short answers are the point."}
```

`reason` is `intended` or `check_wrong`; `note` is up to 280 characters. Post it to
`POST .../health/acknowledgements`; `DELETE .../health/acknowledgements/{id}` is Undo. An error or a
note cannot be acknowledged (`400 check_not_acknowledgeable`), and neither can a check no item trips
(`409 check_not_open`). An acknowledged warning leaves the card's rows and is listed under
`acknowledged`. An acknowledgement covers each item as it was when you acknowledged it. If another
item that trains later trips the same check (a new item, a re-check finding, or an item restored from
Trash, included again or whose import finished), or an item you acknowledged is edited and still trips
the check, it comes back with its whole count and `reopened: true`. An edit that makes an item pass
the check just resolves that item and reopens nothing. For `thin`, a tag you had not acknowledged that
becomes thin reopens it; an acknowledged tag that grows past the threshold is resolved. An item that
stops training (moved to Trash, left out of training, or still being imported) never reopens it.
A reopened entry says why in `reopened_by`: `{item_number, at, cause}`, the number of the item that
reopened it, when (the edit time for `edited`) and the cause (`edited`, `new`, `restore`, `import` or
`tags`). It is `null` when it was not recorded (an acknowledgement reopened before this was kept, or
`thin`, which names no item) and once that item no longer trips the check. It is never a guess.
Acknowledging a check again covers everything that trips it now and replaces the earlier acknowledgement of that check,
which is closed (it reads `undone` among the decisions) instead of staying listed as reopened.
Each run records the warnings you had acknowledged when it started, in its
`training_config.acknowledged_checks`.

## Groups {#groups}

`POST .../groups/search` lists groups of items, largest first, 20 a page (`cursor` for more):

- Chats: `copies` (the same messages), `conversations` (a chat that is the start of a longer one) and
  `conflicts` (the same user turns, different replies).
- Triplets: `multipos` (an anchor with several positives). Other kinds answer
  `400 unsupported_group_kind`.

A member shows its item number, name, source, creation time, tags and the newest frozen version that
holds it, and a group says which of tags, description and source differ among its members.
`POST .../groups/apply` acts on a whole kind at once: `copies` with a rule for the copy that stays in every
group (`keep_in_version`: the copy a saved version holds, else the oldest; `keep_oldest`; `keep_newest`), or
`conversations` with `keep_longest`. For copies, `keep` (up to 1,000 item numbers) names the copy to keep in the
groups where you picked one; the rule chooses in the others. It moves the others to **Trash**, in parts of 1,000 items under one `batch_id`, and
**deletes nothing**. Send `to: "exclude"` instead (the default is `"trash"`) and the same chats are left out
of training and stay in the dataset; an exact copy excluded this way reads "Exact copy" in the Excluded list.
Send `expected_count`; if the groups changed since you looked, the answer is
`409 selection_changed` with `current_count`. To retry a call whose answer was lost, send the same body with the
`batch_id` you chose and the preview's `expected_plan`: once that batch exists, the repeat changes nothing more and
answers `changed: 0` (chats added since were never in the plan you confirmed). Undo with the items API's bulk restore (a move to Trash) or bulk
include (an exclusion) and `selection.batch_id` (see [Act on many chats at once](./chats.md#bulk-actions)), or
with [Undo a batch](./chats.md#undo-a-batch), which also takes back a tag merge.

### In the app {#groups-in-the-app}

**Duplicate chats** shows one group at a time, with the messages its copies share. A text longer than 2,000 characters
says how much is shown ("Showing 2,000 of 9,412 characters"), with a link to the chat. The main button names how many
copies it leaves out of training, read from the [preview](#group-apply-preview) before you click, and the click sends that
plan back: if anything changed meanwhile, nothing moves and the dialog says "This changed since you looked. Review it
again." In every group the copy that stays is your pick, else a copy with a rejected reply (so its preference pair is not
dropped), else the rule you chose, and the tags only a leaving copy had are added to the copy that stays; the summary says
how many before you click. **Not duplicates, keep all** [keeps every copy](#group-decisions) of the group you are looking
at, as you see it, and offers **Undo**; a copy edited or added later shows the group again. **Show decided groups** brings
the groups you kept back into the list. The toast after the change has **Undo**, which goes through
[Undo a batch](./chats.md#undo-a-batch): it brings the copies back, takes back the tags it added, and says how many changes
it left alone because they changed since. **Anchors with more than one positive** shows each anchor and its positives with
the same 2,000-character line. **Keep only the longest of each** (conversations) previews first and asks with that count.

### Preview, then apply {#group-apply-preview}

`POST .../groups/apply/preview` takes the same body as `groups/apply` and shows what it would do, writing nothing. It
needs only `data:read`; `expected_count` is optional there, and `limit` (1 to 1,000, default 100) and `cursor` page the
list. It answers a plan, like the [item bulk previews](./chats.md#preview-a-change): `selected` (every chat in the groups),
`eligible` (the chats that would move: send it as `expected_count`), `not_eligible` (why the others stay: `kept_by_rule`,
`kept_by_pick`, `kept_with_rejected_reply`, or `decided` for a group you kept whole), `plan` and `data`, one row per chat,
ordered by `group_key` and item number, with its `revision`, whether it `stays`, its `effect` and `reason`, and
`has_rejected_reply`. `groups` counts the groups considered, the groups skipped because you decided them, the groups where
your pick named the chat that stays, the rejected replies that would leave and the kept chats that would gain tags.

Send `plan` as `expected_plan` on `groups/apply`: if anything it would change is different now (a chat was edited, a
group grew), the answer is `409 plan_changed` with `current_count` and `current_plan`, and nothing is written. Two options
shape the result, in the preview and in the write alike:

- `prefer_rejected_reply` (copies only): keep a copy that has a rejected reply over one that has none. The order is your
  pick (`keep`), then this, then the rule.
- `merge_tags`: copy to the chat that stays every tag a leaving chat holds and it does not. Tags are copied, never moved;
  the chats that leave keep theirs. A merge that would put more than 32 tags on a kept chat refuses the whole call with
  `409 tag_limit_reached` and `over_limit_item_numbers`, in the preview too. The merge is recorded as a `tagged` entry
  in each kept chat's history.

### Keep a whole group {#group-decisions}

`POST .../groups/decisions` records "these are not duplicates, keep them all" for one live group. Send `kind` (`copies`,
`conflicts`, `conversations`, or `multipos` for triplets), `decision: "keep_all"` and `item_numbers` (2 to 1,000): exactly
the current members of one group of that kind, as `groups/search` shows them. Optional: `revisions` (each chat's
`revision` as you read it, in the same order, so a chat edited meanwhile is `409 revision_conflict` naming it) and a `note`
of up to 280 characters. The answer is `201` for a new decision and `200`, with the same `id`, when that group was already
kept. A set of numbers that is part of a larger group, or the old shape of a group, is `409 group_changed`; numbers that
are no group of that kind are `400 not_a_group`. Errors cannot be kept. `DELETE .../groups/decisions/{id}` is Undo.

The decision covers those chats **at those revisions**, and nothing else. Edit a covered chat and the decision ends for
it; a copy that arrives later is not covered, so the group shows again. Sending a covered chat to Trash or excluding it only
stops it counting. While a group is covered its chats count as kept: the card reports them in `kept_count`, they leave
the `warning` list, [the group lists](#groups) hide the group (`decided`: `hide`, the default, `include` or `only`; a group
and each member carry the decision), their checks read `kept`, `groups/apply` leaves the group whole, and a later
[scan](./similarity-scans.md) does not flag those pairs again.

### Decisions you made {#decisions}

`GET .../decisions` lists what you decided on the dataset, newest first: Keep as is (`keep`), acknowledgements
(`acknowledgement`), group decisions (`group`) and decisions about suggestions (`suggestion`). Filter with `type` and
`state` (both can repeat), `check` (a check key; a value that is not shaped like one, lower-case letters, digits and `_`, is
`400 invalid_check`) and `item_number`; `limit` is up to 100 (default 25), with a `cursor`. A
decision's `state` is `active`; `reopened` (an acknowledgement a new or edited item reopened, or a group with a member the
decision does not cover); `stale` (a covered chat was edited); or `undone`. Without `state`, everything except `undone` is
listed. `covers` names the first 50 chats with the revision each was decided at (`item_count` is how many in all); it is
`null` for a decision made before revisions were stored, and that decision holds as before. `links.undo` is the path
that undoes it, or `null` when it is undone.

### Read a group {#group-reads}

Every group has a `key`: an opaque, stable name for that group (it does not change while the group's copies stay as
they are, and two datasets never share one). Do not parse it. Send keys back in `keys` (1 to 20) to read exactly those
groups again, for example after a decision or an apply; `missing_keys` names the ones that no longer exist (resolved,
or no longer a group). Every member also carries its `revision`, the item's current content revision, and, in a text
dataset, `has_rejected_reply`. A group lists `rejected_reply` in `differs` when some of its members have a rejected reply
and some do not. A triplet has no rejected reply: its members carry no `has_rejected_reply` at all (absent, never `null`).

The text of the members is left out unless you ask for it. Send `content` (`{"max_chars": 2000, "max_messages": 20}`,
both optional) to read it:

```json
{"kind": "copies", "content": {"max_chars": 600}}
```

A chat member then carries `messages` (`role`, `text`, `has_image`), `messages_total` and `rejected_reply`; a triplet
carries `anchor`, `positive` and `negative`. A text is `{"value", "chars", "truncated"}`: `chars` is its full length in
characters and `value` is cut to `max_chars` characters, never inside one, so `truncated` tells you when to open the
item for the rest. A `rejected_reply` (or a `negative`) of `null` means the item has none. Exact copies share their
messages, so the group carries `content` once and each member only its own `rejected_reply`. The text is bounded:
a page that asks for it holds at most **5 groups** (`limit` defaults to 5, and a larger one is `422`), at most **10 members**
of a group carry text and a page carries at most **200,000 characters** of text in all. A member past a bound has no
`content`; the group counts them in `content_omitted`, and `content_budget_reached` says the character budget ended the
text. The text is the item's current one, read with the member, so it is the revision the member shows. It is never in an
error message.

## Fixes {#fixes}

`POST .../items/{item_number}/fixes` applies one fix to one item through the normal edit path: a new
revision, an edit event and a fix event. Send `fix` and `expected_revision`.

- Chats: `merge_system_top`, `move_system_top`, `remove_message`, `strip_template_tokens`,
  `delete_last_turn` (only when the chat ends on a user message), `merge_turns`,
  `remove_earlier_reasoning`.
- Triplets: `remove_negative`, `clear_positive` (the triplet stays blocked by `pos`),
  `negative_to_positive` (creates a triplet with the same anchor and the old negative as its positive)
  and `add_suggested_negative`.

`remove_message` takes the `index` of the message to remove. The `system` finding in `GET .../items/{item_number}/checks`
carries the position it needs: `detail.index` for a system message after the first user turn, and `detail.extra_top` for the
second of exactly two system messages at the top (three or more name none: merge them). A finding stored before this
field existed has no `extra_top` until a re-check writes it again.

A fix that no longer applies is `409 fix_not_applicable`; a changed item is `409 revision_conflict`
with `current_revision`. That route acts on one item at a time.

**Many chats at once.** `POST .../items/bulk/fix` applies one of two fixes to a selection of chats: `delete_last_turn`
(the chats the `ends` check flags) or `merge_turns` (with `turns`). Send the same `selection` as the other
[bulk actions](./chats.md#bulk-actions), item numbers or a `filter` with `expected_count`, and the returned
`batch_id` with the same body again while `remaining` is above 0: one call fixes at most 100 chats. A fix applies
only to a chat the matching check flags now, that is live, not kept as is and not already fixed in this batch
(applying `delete_last_turn` twice would delete a second turn); the others are counted in `skipped` and left as
they are. `merge_turns` does not merge across a system message, so a chat the `turns` check flags only because
of one is always `skipped`. In bulk, `merge_turns` also skips a chat whose merge would lose something: two turns
in a row where one trains and the other is switched off (the merged reply keeps one setting), or a second turn that
carries an image (the merged message keeps the first one's). Fix those chats one at a time. Each repeat call
starts after the last chat its batch fixed, so a chat that cannot be fixed is counted in `skipped` once over the
whole series and the loop always ends, however many such chats come first. The
answer is `{"changed", "remaining", "batch_id", "skipped"}`. It is for text datasets only: a triplet dataset answers
`400 fix_not_for_this_dataset`. Each changed chat is a new revision, as for a single fix.

## Suggestions from a scan {#suggestions}

These read the **latest finished** [scan](./similarity-scans.md) and answer `409 no_scan` when there is
none.

- `POST .../suggestions/near-duplicates/search`: near-duplicate groups, highest score first, with a
  `threshold` from 0.80 to 1.00. A threshold below the line the scan used is
  `400 threshold_below_scan`: scan again to look lower. The answer includes the scan's score histogram.
  Each member carries its `revision` and, in a text dataset, `has_rejected_reply`, and `content` reads the members'
  current text, bounded exactly as for [groups](#group-reads) (5 groups a page, 10 members a group, 200,000 characters
  a page).
- `POST .../suggestions/decisions` records your decision about a group (`not_duplicates`,
  `keep_together`, `keep_both`, and for triplets `skipped_negative` or `not_negative`), with two to 50 item
  numbers (one triplet for `skipped_negative`; for `not_negative` exactly two, the triplet first and the
  candidate second). A group you decided is left out of the near-duplicate list from then on
  (a `keep_both` group only once every pair in it is kept), and a later scan keeps a `not_duplicates` pair
  apart. `keep_together` changes nothing in the dataset or in a scan: it only says you looked. `keep_both`
  is stored for each pair with the scan it answered (`scan_number`, the latest finished scan if you omit
  it): the next scan does not flag that pair again, and editing either item ends the keep.
  Every kind is stored with the revision of each item it answered, so editing an item ends any of them for it.
  `DELETE .../suggestions/decisions/{id}` is Undo (the id of a [group decision](#group-decisions) is `404` here).
- `POST .../suggestions/negatives/search` (triplets): up to ten mined hard negatives per triplet, each
  with its share of the positive's score, and whether it is pre-selected (not when it is 95% or more of
  the positive's score). Send `item_number` for one triplet's suggestions alone: its row, or an empty
  page when it has none (`without_candidates` still counts the whole dataset). Answer a candidate with
  **Not a negative** (`kind: not_negative`) when it actually matches the anchor: it is not suggested for
  that triplet again, and a triplet whose candidates were all answered that way counts as one with none.
  **Skip the rest** is still one decision for the whole triplet (`skipped_negative`). In the dialog, `A` adds the current
  candidate as the negative, `N` says it is not one, `S` skips the rest of its triplet and `J` moves to the next triplet.
  A `not_negative` decision answers `400 invalid_decision` when the pair is not one the latest usable scan mined for that
  triplet, or when the dataset has no usable scan.
- `POST .../suggestions/leakage/search` (read only): for a validation tag (its name), the validation items that have a
  near-duplicate among the training items, strongest first. The body is `{"validation_tag", "scan_number",
  "limit", "cursor"}` (`scan_number` defaults to the latest finished scan). Each row names the validation
  item and the training item by number, with the score of the scan's group, never any text. The answer
  carries `total_pairs`, `validation_items`, `capped` and `calibrated: false`; an unknown tag is
  `404 tag_not_found`. It is the list behind the `leakage` line of a run estimate (see
  [Similarity scans](./similarity-scans.md#run-estimate-leakage)). A pair you kept with **Keep both** (a
  `keep_both` decision for the two items, stored for that pair and the scan it answered) comes back after the
  open pairs with `kept` (`decision_id`, `created_at`, `scan_number`; `null` for an open pair), and the
  next scan does not flag it again. `total_pairs` and `validation_items` count open pairs only, `kept_pairs`
  counts the others, and the run estimate's `leakage.count` is of open pairs too. Editing either item ends the
  keep. Pages stay in step while you answer them: excluding or keeping pairs between two pages makes
  `next_cursor` skip no open pair, and a cursor stays on the scan its first page read (sending it with
  another `scan_number` is `400 invalid_cursor`). The training side is every other live item not excluded from training, and the number is
  an upper bound: an item your run's own tags or saved view leave out is still counted as training here.
- `POST .../items/{item_number}/similar`: the 20 closest items in the latest finished scan. An item
  added or edited since the scan answers `409 item_not_in_scan`.

**The neighbours follow the dataset's item list as it is now, not as the scan found it.** The near-duplicate groups,
the 20 closest items of **Find similar**, the triplets asked about by the negative suggestions and the
near-duplicate line on an item's checks are filtered when you read them, against each item's current state. An item in
Trash (or purged, or still inside a running import) is not listed, and it is listed again when you restore it; a
group left with fewer than two items is not shown, and `total_groups`, `total` and the pages are counted after the
filter (Find similar returns the 20 closest items that are visible today). An item **excluded from training** stays in
the list and carries `excluded: true`, drawn with the same "Excluded from training" note as the item list, because you may be
looking for the copy you already excluded. The scan's own report (its findings and counts) stays as the scan found
them. The validation leakage list is the one exception: it counts only items that train, as the run does.

### Similar items on the dataset list {#similar-list}

On an item's page, **Find similar** opens the Similar items card in place. On a triplet dataset's list, each row's
**Find similar** shows the list itself "similar to" that item: the item first, then its closest items in the order
the server ranked them, each with its similarity (a cosine similarity from the latest scan, not a probability), its
source and its text, and **Exclude** to leave one out of training. Over the rows, the scan they came from (with
**Rescan**), what was compared (for a triplet, choose the anchor or the positive; for a chat, what the scan
embedded), and **Back to all chats** (for triplets, **Back to all triplets**). The view is in the page address (`?similar=N`, and `&role=positive` for a
triplet's positive), so it can be bookmarked or shared with a teammate who can open the dataset; a chat dataset's list
shows the same view at the same address. With no finished
scan, or for an item added or edited after it, the list says so, in the card's words. It reads the same two
routes an agent would: `POST .../items/{item_number}/similar`, then the item search with
[`item_numbers`](./chats.md).

## Starting a run {#starting-a-run}

A text run refuses a selection (including owner-chosen validation chats outside it) that holds a chat with an error that would stop it training:
`400 chat_structure_invalid` with the counts of `reply`, `system` and `tokens` problems. The estimate
shows the same line as the readiness check `structure`. Excluding the chats is the way out. An embedding run has
the same check for triplets: its preview and its create refuse a selection holding a triplet that would not train as
written with `400 triplet_structure_invalid` and the counts `count`, `pos` (no positive), `idpos` (a positive identical to
the anchor), `same` (the same text for the positive and the negative) and `crossneg` (a negative that is another positive
of the same anchor); its estimate shows the same `structure` line. Fix or exclude the triplets.

## Access {#access}

Reads need `data:read`; every change needs `data:write`. Acknowledging, keeping and fixing move no money
and change no account, so an API key may do them. A missing or foreign project, dataset, item or
decision is the same `404 not_found`. Messages never contain an item's text, name or tags.
