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) and probabilities (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.
  • Several answers may apply at the same time (“complaint” and “refund”)? Ask one yes/no question per item with Noul or Advanced.
  • The answers form a scale from “little” to “a lot” (urgency, anger)? Use Score.

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

FieldDefaultDescription
Textmsg.textThe text or object Laya looks at. In batch mode a list or an object of records.
QuestionWhich department is responsible?The question Laya answers by picking one choice.
Choices (Variable)emptyOptional. Choices from a variable or JavaScript. If this field is filled, the Choices list below is ignored. Leave it empty to use the list.
ChoicesSales, Support, BillingThe 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

FieldDefaultDescription
Resultmsg.layaLaya’s answer, unchanged. See Result.

Options

OptionDefaultDescription
BatchoffOn: Text holds many records. See Batch mode.
Min Confidence (optional)emptyLaya’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
OptionDefaultDescription
ModelAutoLaya model. Auto picks by language.
Server URLhttp://127.0.0.1:8000Address of the Laya server.
API Key (optional)emptyVault item with the key, only if the server uses LAYA_API_KEY.
Timeout (sec)30Maximum 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.

ChoiceDescription
Salesoffers, prices, new licences, contracts
Supportlogin problems, error messages, how-to questions
Billinginvoices, 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", "...": "…" }
}
FieldMeaning
choiceThe picked choice, exactly as written in the list.
probabilitiesProbability of every choice. They add up to 1.
answer_confidenceProbability of the picked choice. Use it to decide whether you trust the answer.
low_confidenceOnly present when Min Confidence is set and the answer is below it. Then it is true.
usage.truncatedtrue 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 decide
return 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

MessageCause and fix
Please enter between 2 and 100 choicesThe list has fewer than two filled rows, or more than Laya accepts.
Choices: "…" appears twiceTwo rows have the same name. Names must be unique.
Choices: an entry has no nameA row has a description but no choice name.
Choices (Variable) is empty. Fill it or clear the field to use the listChoices (Variable) points to a message field or JS expression without a value.
Choices: object is not valid JSON
Choices: list is not valid JSON
The JSON typed into Choices (Variable) has a syntax error.
Min Confidence must be between 0 and 1Use for example 0.7, not 70.
Laya returned no choiceUnexpected 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.


Was this article helpful?
© 2026 Robomotion Help by aeovi.com