# Calibrate confidence & abstention thresholds

URL: https://docs.hanzo.ai/docs/guides/kai/abstention-thresholds

> Use Kai's normalized confidence score to act automatically on settled decisions and escalate uncertain cases to human review or Zen.

**An uncalibrated classifier fails silently on ambiguous inputs.** Kai returns both `answer_confidence` (`p_max`) and normalized `confidence` (`(n·p_max - 1)/(n - 1)`), so one abstention threshold works identically across 3-class and 30-class decisions.

## Architecture & contract

When `confidence` is `0`, every option is equally likely; when `confidence` is `1`, one option carries all probability mass. Set a conservative threshold (such as `>= 0.70`) for automated actions and route everything below it to a human queue or `zen6`.

**Primary endpoint:** `POST /v1/decisions` · \*_Status:_\* `shipped` · \*_Level:_\* `practitioner`

## Run it across all four surfaces

**CLI**

```bash
hanzo decisions create --model kai --data '{
  "state": "Please check whether our EU VAT exemption applies to last month and also reset Alice login.",
  "questions": {
    "route": {
      "type": "choice",
      "instructions": "Pick the single primary queue for this ticket.",
      "criteria": {
        "tax_compliance": "VAT, W-8, W-9, and tax exemptions",
        "account_access": "Password, SSO, and login resets",
        "billing": "Invoices and payment retries"
      }
    }
  }
}' | jq '.answers.route | if .confidence >= 0.7 then {action: "auto", queue: .choice} else {action: "escalate", confidence: .confidence} end'
```

**SDK**

**TypeScript**

```ts
import { Configuration, AiApi } from 'hanzoai';

const ai = new AiApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await ai.postDecisions({
  model: 'kai',
  state: 'Check our EU VAT exemption and also reset Alice login.',
  questions: {
    route: {
      type: 'choice',
      instructions: 'Pick the single primary queue.',
      criteria: {
        tax_compliance: 'VAT and tax exemptions',
        account_access: 'Password and login resets',
        billing: 'Invoices and payment retries',
      },
    },
  },
});
const ans = data.answers.route;
const action = ans.confidence >= 0.7 ? ans.choice : 'human_review';
console.log({ action, confidence: ans.confidence, probs: ans.probabilities });
```

**Python**

```python
import os
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import AiApi

api = AiApi(ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"])))
res = api.post_decisions({
    "model": "kai",
    "state": "Check our EU VAT exemption and also reset Alice login.",
    "questions": {
        "route": {
            "type": "choice",
            "instructions": "Pick the single primary queue.",
            "criteria": {
                "tax_compliance": "VAT and tax exemptions",
                "account_access": "Password and login resets",
                "billing": "Invoices and payment retries",
            },
        }
    },
})
ans = res["answers"]["route"]
print("auto:" + ans["choice"] if ans["confidence"] >= 0.7 else "escalate:human_review")
```

**HTTP**

```bash
curl -s https://api.hanzo.ai/v1/decisions \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kai",
    "state": "Check our EU VAT exemption and also reset Alice login.",
    "questions": {
      "route": {
        "type": "choice",
        "instructions": "Pick the single primary queue.",
        "criteria": {
          "tax_compliance": "VAT and tax exemptions",
          "account_access": "Password and login resets",
          "billing": "Invoices and payment retries"
        }
      }
    }
  }' | jq '.answers.route | {choice, confidence, action: (if .confidence >= 0.7 then "auto" else "escalate" end)}'
```

**MCP**

```bash
curl -s -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "ai",
      "arguments": {"op": "post_decisions", "input": {"model": "kai", "state": "Ambiguous mixed ticket", "questions": {"route": {"type": "choice", "instructions": "Queue?", "criteria": ["tax", "account", "billing"]}}}}
    }
  }'
```

## Verify the outcome

- Multi-intent tickets should drop below `0.70` confidence and trigger `escalate`.
- Single-intent tickets should exceed `0.85` confidence and route automatically.

## Production guardrails

- Tune thresholds empirically on held-out org datasets (`/v1/eval/datasets`) rather than guessing.
- Pin `routing.calibration` beside your thresholds so calibration shifts drop to `shadow`.

## Next steps & Hanzo University

- [Decisions API Reference](https://docs.hanzo.ai/docs/decisions) · [Teach Kai Your Business](https://docs.hanzo.ai/docs/training/kai-capabilities)

- **[KAI 201 — Kai Decision Intelligence](https://hanzo.university/kai-decision-intelligence)** ([Launch interactive lab on hanzo.app/learn](https://hanzo.app/learn/kai-decision-intelligence))
