Choice – pick one of several choices
The Choice node asks Laya to pick exactly one of several choices that you define, for example which department should handle an e-mail or what a ticket is about. Laya returns the picked choice and the probability of every choice. The probabilities always add up to 100 %.
At a glance
- Question type: pick one of 2 to 100 choices
- Laya returns:
choice(the picked name) andprobabilities(one per choice) - Choices from: a list in the node or a variable / JavaScript
- Batch mode: supported
When to use Choice
- The possible answers are different things without an order: departments, topics, products, languages, document types.
- Exactly one answer is correct.
Settings
📷 Image placeholder: Screenshot of the Choice settings panel with the Choices list (three rows Sales / Support / Billing with descriptions and the “Add Item” button).
Input
| Field | Default | Description |
|---|---|---|
| Text | msg.text | The text or object Laya looks at. In batch mode a list or an object of records. |
| Question | Which department is responsible? | The question Laya answers by picking one choice. |
| Choices (Variable) | empty | Optional. Choices from a variable or JavaScript. If this field is filled, the Choices list below is ignored. Leave it empty to use the list. |
| Choices | Sales, Support, Billing | The list of choices. Each row has a Choice (the name Laya returns) and an optional Description. Use Add Item for more rows and the bin icon to remove one. Empty rows are ignored. |
Output
| Field | Default | Description |
|---|---|---|
| Result | msg.laya | Laya’s answer, unchanged. See Result. |
Options
| Option | Default | Description |
|---|---|---|
| Batch | off | On: Text holds many records. See Batch mode. |
| Min Confidence (optional) | empty | Laya’s own threshold min_confidence. If answer_confidence is below this value, Laya adds "low_confidence": true to the answer. Empty means off. Not available in batch mode. |
Connection options: Model, Server URL, API Key, Timeout
| Option | Default | Description |
|---|---|---|
| Model | Auto | Laya model. Auto picks by language. |
| Server URL | http://127.0.0.1:8000 | Address of the Laya server. |
| API Key (optional) | empty | Vault item with the key, only if the server uses LAYA_API_KEY. |
| Timeout (sec) | 30 | Maximum wait for Laya. |
These options are the same for all Laya nodes. Details in the overview.
Defining the choices
Option A – In the list
Enter one choice per row. The Description is optional but strongly recommended: it tells Laya what the choice means and improves accuracy noticeably.
| Choice | Description |
|---|---|
| Sales | offers, prices, new licences, contracts |
| Support | login problems, error messages, how-to questions |
| Billing | invoices, payments, double charges, refunds |
The name in the Choice column is exactly what Laya returns in choice, so use names that you want to branch on later. The names may be in any language, also different from the text.
Option B – From a variable or JavaScript
Fill Choices (Variable) when the choices are not fixed, for example when they come from a database or a previous step. Two formats are accepted.
A list of names
msg.categories = ["Payment", "Delivery", "Technical problem"];
An object: name → description (the description may be empty)
msg.categories = { "Payment": "invoices, charges, refunds", "Delivery": "parcels, tracking, delays", "Technical problem": ""};
Then set Choices (Variable) to Message scope with categories. You can also type the JSON directly into the field with Custom scope.
If Choices (Variable) points to a message field that does not exist, the node stops with an error instead of silently falling back to the list. That way a missing variable never goes unnoticed.
Result
Example for “You charged my March invoice twice. I want my money back right now!”:
{ "type": "choice", "choice": "Billing", "probabilities": { "Sales": 0.0338, "Support": 0.1038, "Billing": 0.8624 }, "confidence": 0.71, "answer_confidence": 0.8624, "action": { "act_probability": 1.0 }, "model": "laya-rl-agent", "usage": { "truncated": false, "...": "…" }, "routing": { "model": "english", "...": "…" }}
| Field | Meaning |
|---|---|
choice | The picked choice, exactly as written in the list. |
probabilities | Probability of every choice. They add up to 1. |
answer_confidence | Probability of the picked choice. Use it to decide whether you trust the answer. |
low_confidence | Only present when Min Confidence is set and the answer is below it. Then it is true. |
usage.truncated | true if the text was too long and its end was not read. |
Branching with a Switch node
Connect a Switch node and add one condition per choice:
msg.laya.choice == "Sales"msg.laya.choice == "Support"msg.laya.choice == "Billing"
To send uncertain answers to a human first, put this condition at the top of the Switch:
msg.laya.answer_confidence < 0.7 // or, with Min Confidence = 0.7:msg.laya.low_confidence == true
Detecting close calls
If the two highest probabilities are close (for example 0.45 and 0.42), Laya was torn. You can detect this in a Function node:
var p = Object.values(msg.laya.probabilities).sort(function (a, b) { return b - a; }); msg.closeCall = (p[0] - p[1]) < 0.1; // true → let a human decidereturn msg;
Batch mode
With Batch on, every record in Text gets the same question and choices.
Input
msg.text = { "M1": "Please refund my double payment.", "M2": "The app crashes when I log in."};
Result
msg.laya.M1.choice // "Billing"msg.laya.M2.choice // "Support"
Up to 64 records go into one request. More are split automatically.
Min Confidence must be empty in batch mode. Compare answer_confidence yourself instead.
Tips
- Write descriptions like keywords. “invoices, payments, double charges” works better than a long sentence.
- Cover everything. Laya always picks one choice, even if none fits. Add a choice like “Other: none of the above” so unrelated messages have somewhere to go.
- Keep it short. Up to about 20 choices work well. With more, split into two Choice nodes: first the area, then the topic within the area.
- Make choices distinct. Overlapping choices (“Billing” and “Payments”) split the probability and lower the confidence.
Errors
| Message | Cause and fix |
|---|---|
Please enter between 2 and 100 choices | The list has fewer than two filled rows, or more than Laya accepts. |
Choices: "…" appears twice | Two rows have the same name. Names must be unique. |
Choices: an entry has no name | A row has a description but no choice name. |
Choices (Variable) is empty. Fill it or clear the field to use the list | Choices (Variable) points to a message field or JS expression without a value. |
Choices: object is not valid JSONChoices: list is not valid JSON | The JSON typed into Choices (Variable) has a syntax error. |
Min Confidence must be between 0 and 1 | Use for example 0.7, not 70. |
Laya returned no choice | Unexpected answer from the server. Check the Laya server log. |
Connection, timeout, API key and batch errors are the same for all nodes. See Laya package – overview and setup.