> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pult.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Triage

> Typed questions about each new item, and rules in your code that act on the answers once they've earned it.

Triage reads each new item and answers questions you ask about it. The answers are typed: a probability, one of your options, or a position on your scale. Rules in your code decide what to do with them, and new rules only watch until the numbers show they agree with your team.

```ts theme={null}
import { choice, inbox, noul, run, setState, tag, triage } from "pult"

export const reports = inbox("reports", {
  states: ["open", "actioned", "dismissed"],
  // ...
  triage: triage({
    instructions:
      "Users report comments on our code hosting platform. " +
      "Judge the reported comment itself.",
    questions: {
      valid: noul(
        "Does `body` break the rules: spam, scams, harassment or porn?",
      ),
      category: choice(
        {
          spam: "Advertising, scams or links that try to sell something",
          harassment: "Insults or attacks aimed at people",
          fine: "Nothing wrong with it",
        },
        "What is wrong with `body`?",
      ),
    },
    rules: [
      {
        name: "Dismiss reports on harmless comments",
        when: (a) => a.valid < 0.1,
        then: setState("dismissed"),
      },
      {
        name: "Hide obvious spam",
        live: true,
        when: (a) =>
          a.category === "spam" && a.valid > 0.95 && a.confidence > 0.9,
        then: [run(message.actions.hide), tag("spam")],
      },
    ],
  }),
})
```

## Questions

Triage sees the item's title, its data and the text of its blocks, with [sensitive values](/build/blocks#sensitive-values) left out. `instructions` gives it context. Refer to fields of your data by name in the questions.

* `noul(prompt, criteria?)` answers yes or no as a probability between 0 and 1.
* `choice(options, prompt)` picks one option. Options are a list, or an object of option to description; describing options helps a lot.
* `score(levels, prompt)` rates the item against your levels, lowest first. The answer is a number from 0 (the first level) to the last level's position, weighted by how sure it is: with `["low", "medium", "high"]`, 1.7 leans high.

The answers' types follow your questions, so `a.category` above is `"spam" | "harassment" | "fine"`. `a.confidence` is the lowest confidence across the `choice` and `score` answers.

## Rules

Rules run in your app, top to bottom. The first rule whose `when` matches decides, and `then` is one decision or a list:

* `setState(state)` moves the item. Moving it to a closed state counts as handled by triage.
* `tag(name)` tags it.
* `run(action, input?)` runs an action. Only actions that are harmless or marked `automatable: true` can be run, never ones that need an approval; `pult check` catches the rest.

## Watching, then acting

A rule without `live: true` only watches. Pult records what it would have done and compares that with what your team actually does with the item: an agreement when they end up in the same place, a disagreement when they don't. Each rule's agreement rate shows under Rules in the inbox. Turn a rule live once it has earned it.

When a live rule closes an item and someone moves it back, that's recorded as an override and counts against the rule.

## Replay

You can try rules out before shipping them. Change a rule, reload your app, and press Replay under Rules: your app runs its current rules against the stored answers for the last 500 items, and Pult compares the outcome with what people actually did. Nothing is asked again and nothing changes.

## In the console

Items show triage's read at the top: the answers, which rule matched, and whether it acted or only watched. Items triage closed on its own are under Handled by triage in the sidebar, so someone can glance over them.


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