# n8n

> The n8n-nodes-curva community node routes each item by its typed answer, sends unsure ones to a Needs review branch, and feeds corrections back.

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

The `n8n-nodes-curva` community node puts Curva in an n8n workflow. Its headline operation,
**Route**, sends each item down the branch of its answer, and every answer below your confidence
bar to a **Needs review** branch, where a human decides and the node's **Feedback** operation
teaches Curva.

The package is [`n8n-nodes-curva` on npm](https://www.npmjs.com/package/n8n-nodes-curva).

## Install

1. In n8n (self-hosted): **Settings → Community Nodes → Install**, enter `n8n-nodes-curva`.
2. Start a Curva server: `curva serve` (default `http://localhost:7777`; from n8n in Docker use
   `http://host.docker.internal:7777`).
3. Add a **Curva API** credential: the base URL, and a `curva_…` key if the server has keys
   (`curva keys create --name n8n`).

## Route

Configure one question:

- **Choice**: instructions and options (key + description). Each option key becomes an output
  branch, in order, plus `none_of_these` when **None of These** is on (the default).
- **Yes / No**: branches `Yes` and `No`.

**Min Confidence** (default 0.8) decides what a human sees: answers below it leave on the last
branch, **Needs review**. The **State** is the whole item, some of its fields, or an expression.

Every routed item keeps its data and gains a `curva` field:

```json
{ "curva": { "id": "dec_…", "question": "department", "answer": "billing", "confidence": 0.93,
  "probabilities": { "billing": 0.93, "technical": 0.04, "sales": 0.01, "none_of_these": 0.02 },
  "calibrated": false, "abstain": false } }
```

The branches update as you edit the options: like n8n's Switch node, the node computes its outputs
from its own parameters.

## Close the loop with feedback

End the Needs review branch with a Curva node on **Feedback**. Its defaults read the decision id
and question key from the item's `curva` field; set **True Label** to the human's answer (an
option key, `true`/`false`, or a level index). From 30 labels for a question in a project, Curva
calibrates its confidences for your data whenever that makes them more accurate; see
[Calibrate with feedback](/curva/guides/feedback/). **Calibration Report** shows the before and after.

## Several questions: Decide

**Decide** takes questions as JSON in the [HTTP API](/curva/reference/http-api/) format and attaches
all answers to the item as `curva.answers`, exactly as the server returns them. Use it when one
item needs a score, a yes/no and a choice at once, and route afterwards with an IF or Switch node.

## Check an action or screen a text

Before a workflow takes an action, or before an AI node reads text from outside, call Curva's
built-in check or screen with an **HTTP Request** node: `POST {base}/v1/decide` with the
**Curva API** credential's key as a Bearer header and a JSON body:

```json
{"ask": "check", "state": {"action": {"tool": "refund", "amount": 500}, "policy": "Refunds above $200 need a manager's approval."}}
{"ask": "guard", "state": {{ JSON.stringify($json.body) }}}
```

In the screen body, `JSON.stringify` keeps quotes and newlines in the text from breaking the JSON.

Branch with a **Switch** node: for the check, `{{ $json.answers.check.abstain }}` is true → a
person, then `{{ $json.answers.check.choice }}` is `allow` or `block`; for the screen,
`{{ $json.answers.verdict.abstain }}` is true or `{{ $json.answers.verdict.choice }}` is `review`
→ a person, `block` → stop. The fields and the default policy are in
[Check an action or screen a text](/curva/guides/any-http-tool/#check-an-action-or-screen-a-text).

## Example workflow

Import [`n8n-ticket-triage.json`](/curva/examples/n8n-ticket-triage.json)
with **Workflows → Import from File**: sample tickets → Route (`billing`, `technical`, `sales`,
`none_of_these`, Needs review) → queues, with the review branch ending in Feedback.

## Options

**Model** (an id, or JSON for a fallback list, council or cascade), **Project** (calibration
namespace), and under **Options**: config, debias, [images](/curva/guides/images/), privacy and think. With
**On Error → Continue**, a failed item goes to the last output with an `error` field.
