# Calibrate with feedback

> Send Curva the true answer whenever you learn it. From 30 labels per question it calibrates when that helps, so probabilities match accuracy on your data.

Source: https://docs.tarkova.com/curva/guides/feedback/

## How it works, step by step

1. **Decision kept** (Decision id, Raw probability, Per model): Curva stores each answer's raw probabilities with the question and the model. Calibrators are always fit on these raw numbers, never on already adjusted ones. In the example: A test team sends 60 tickets and asks "The billing desk should handle this ticket." The model says yes at about 0.998 on billing tickets, but this team sends free-plan billing tickets elsewhere, which the model cannot know.
2. **Feedback stored** (/v1/feedback, Choice, Score, Noul, Text, Number): You send the true answer for one question of one decision. A second label for the same pair replaces the first. An unknown decision gets 404 and a label that is not a valid answer gets 422. Multi questions take no feedback yet. In the example: All 60 labels go in. 15 of them disagree with the model: the free-plan billing tickets.
3. **30 labels** (min_labels 30, Project, Exact question, Same model): Labels count per project, per exact question and per model, so a reworded question or another model starts again. Below 30, no calibrator is tried. From 30, each new label refits it, at most once every 5 seconds. In the example: At label 29 the reply says calibrated: false. At label 30 it says calibrated: true.
4. **Fit a calibrator** (Platt, Temperature, Bias scaling): A yes/no answer or an extracted value gets Platt scaling, two numbers that also fix a lean to one side. Choice and Score get temperature scaling, plus a bias per option when that wins on held-out labels, for up to 20 options. In the example: billing_desk fits Platt with a 0.48 and b -2.03.
5. **Held-out test** (5 folds, Log loss, Brier, Raw vs fitted): Curva fits on four fifths of the labels and scores the last fifth, five times over. The calibrator must clearly beat the raw probabilities on log loss and on Brier score, and the labels must show the raw numbers really are off. In the example: It passes. On the same tickets in shuffled order, the report's held-out ECE falls from 0.24 to 0.14, and accuracy on answers above 0.9 rises from 70% to 97%, while the share above 0.9 falls from 78% to 48%.
6. **Kept or dropped** (Kept, Dropped, calibrated flag): A calibrator is not always kept. If it does not win the test, the question has none, its answers stay raw and they say calibrated: false. That is the normal result for a model that is already well calibrated. In the example: A second question on the same 60 tickets, "The ticket is about money", was right on all 60 labels. It kept no calibrator and still says calibrated: false.
7. **Later answers** (Adjusted, calibrated: true, Cache too): Each new answer from that model on that question passes through the kept calibrator and comes back with calibrated: true. The raw numbers stay stored for the next refit, which can replace the calibrator or drop it. In the example: A ticket that got 0.9995 before the labels gets 0.84 after, from the cache, with no new model call. That is closer to the 50% these labels show when the model says yes, and not all the way there.

Calibration is what turns a model's raw confidence into a probability you can act on. It needs
one thing from you: the true answer, whenever you learn it.

## 1. Keep the decision id

Every decision has an `id` (`dec_…`). Store it next to whatever you did with the answer.

```python
d = client.decide(ticket, questions, project="support")
save(ticket_id, d.id)
```

## 2. Send the true answer

When an agent closes the ticket, a reviewer corrects a label, or the outcome is otherwise known:

```python
client.feedback(decision_id, "team", "billing")
```

| Question type | Label |
|---|---|
| Choice | the option key, e.g. `"billing"` |
| Score | the level index, e.g. `2` |
| Noul | `True` or `False` |

Sending feedback again for the same decision and question replaces the earlier label. An unknown
decision or question gets 404, and a label that isn't a valid answer gets 422.

Over HTTP:

```bash
curl -s localhost:7777/v1/feedback -H 'content-type: application/json' \
  -d '{"decision_id": "dec_…", "question": "team", "label": "billing"}'
# {"decision_id": "dec_…", "question": "team", "labels": 31, "min_labels": 30, "calibrated": true}
```

## 3. Answers become calibrated

From **30 labels** for the same exact question in a project, Curva fits a calibrator and refits it
as labels arrive. When it makes the answers more accurate on labels it hasn't seen, that
question's answers come back with `calibrated=True`; otherwise they stay raw (`calibrated=False`),
because the model is already well calibrated. See [Calibration](/curva/concepts/calibration/).

:::note[Exact question]
Calibration is keyed by the question's type, wording and options. Changing the wording starts
a fresh calibration. See [why](/curva/concepts/calibration/#why-per-exact-question).
:::

## 4. Check the report

```python
report = client.calibration("team", project="support")
print(report["before"]["ece"], "→", report["after"]["ece"])
print(report["after"]["accuracy_when_automated"], report["after"]["automated"])
```

`before` is the raw model; `after` is held out (each half of the labels calibrated by a fit on
the other half). Both include `accuracy`, `ece`, `brier`, `automated` and
`accuracy_when_automated` (at 0.9 confidence), plus `reliability` bins for a calibration curve.
`calibrator` shows the fitted parameters.

## Putting it together

A common pattern is to automate confident answers and learn from the rest:

```python
from curva import Choice

q = {"team": Choice("Which team?", {"billing": "", "technical": "", "sales": ""}, min_confidence=0.9)}
d = client.decide(ticket, q, project="support")

if d["team"].abstain:
    team = ask_a_human(ticket)                  # a person decides...
    client.feedback(d.id, "team", team)         # ...and Curva learns from it
else:
    route(ticket, d["team"].choice)
```

Also send feedback for a sample of automated answers, so the calibration covers the whole
confidence range, not only the unsure cases.

## Learn by example

Feedback adjusts how sure Curva is. With `learn=True` it also changes what the model answers:

```python
d = client.decide(call_text, q, project="front-desk", learn=True)
client.feedback(d.id, "desk", "reception")      # the true answer, whenever you know it
```

A decision sent with `learn` keeps its state on the server. Once it has feedback, the state and
its true answer are shown to the model as an example the next time the same question is asked in
the same project with `learn`. Curva picks up to four per question: answers the model got wrong
first, then one for every label, then the newest. `d.lessons` says how many were shown.

In one live test a front desk sent all "gate pass" calls to reception, which the model could not
know: 2 of 6 new calls were right before, 6 of 6 after four labelled calls
(`@groq/qwen/qwen3.8-27b`, 12 October 2026, 6 calls each).

What to know:

- It is off unless you ask. Without `learn`, the state is never stored, as before.
- A state is kept only when it is at most 2,000 bytes of JSON, and for 180 days.
- `curva lessons forget [--project <p>]` deletes the kept states.
- Not available with `privacy="strict"`, images or `explain`.
- The examples change what the model says, so confidence is calibrated again from the feedback
  that follows.
