Skip to content

decide

decide answers a yes-or-no question about a piece of text. It says yes (true) or no (false), or, when you set a low and a high bar, not sure (unsure).

Terminal window
echo 'Please refund my order.' |
thinkthen decide 'Does the customer request a refund?'

Output

true

Yes: the message asks for a refund.

Terminal window
echo 'Where is my parcel?' |
thinkthen decide 'Does the customer request a refund?'

Output

false

No: the message asks about a delivery, not a refund.

Set a low bar and a high bar. decide says no below the low bar, yes at or above the high bar, and not sure in between.

Terminal window
echo 'I was charged twice for one invoice.' |
thinkthen decide --low 0.2 --high 0.8 \
'Does the customer request a refund?'

Output

unsure

Not sure: a double charge might be a refund request, or might not. Send not sure to a person. Never treat it as a no.

See why

--json prints the details. This jq keeps the two that explain the answer.

Terminal window
echo 'I was charged twice for one invoice.' |
thinkthen decide --low 0.2 --high 0.8 --json \
'Does the customer request a refund?' |
jq -c '{status, probability}'

Output

{"status":"unsure","probability":0.7}

probability is the chance of yes. 0.7 falls between the bars of 0.2 and 0.8, so decide is not sure. JSON output lists every field.

Move the bar

With one bar, --threshold, decide always says yes or no. Raise the bar to 0.8 and the same text is a no, because 0.7 is below it.

Terminal window
echo 'I was charged twice for one invoice.' |
thinkthen decide --threshold 0.8 \
'Does the customer request a refund?'

Output

false

The default bar is 0.5. Lower it to say yes more often. Raise it to say yes only when the model is sure.

Use the answer in a script

--check turns the answer into the exit code.

Terminal window
message='Please refund my order.'
if echo "$message" |
thinkthen decide --check \
'Does the customer request a refund?' > /dev/null
then
echo 'send to the refunds queue'
else
status=$?
case "$status" in
1|3) ;;
*) exit "$status" ;;
esac
fi

Output

send to the refunds queue
Answer Exit code with --check
true 0
false 1
unsure 3

Without --check, decide exits 0 whenever it answers. Exit codes lists every code.

Answer every row of a CSV file
messages.csv
id,text
a1,Please refund my order.
a2,Where is my parcel?
a3,I was charged twice for one invoice.
Terminal window
thinkthen decide 'Does the customer request a refund?' \
--from csv --column text --into is_refund < messages.csv

Output

id,text,is_refund
a1,Please refund my order.,TRUE
a2,Where is my parcel?,FALSE
a3,I was charged twice for one invoice.,TRUE

--column names the column to read, and --into names the new answer column. A CSV file holds TRUE and FALSE, which Excel reads as yes and no. With no bars, the double charge is a yes. File types covers TSV, Excel and other files.

Options
OptionWhat it does
<QUESTION>Question to ask
[FILE]...Input files; default: standard input
--name <NAME>Optional execution identity
--text <TEXT>Judge this text instead of reading input
--threshold <THRESHOLD>Required probability
--low <LOW>Low probability bar
--high <HIGH>High probability bar
--check [=<CHECK>]Return the verdict as an exit code
--true <TEXT>Meaning of a true answer
--false <TEXT>Meaning of a false answer
--column <COLUMN>Field column; repeat; replaces a saved pointer
--details [=<DETAILS>]Add status, probability, error, detail and source columns
--in-place [=<IN-PLACE>]Replace source with backup
--into <INTO>Answer field for JSON Lines; column for tables
--output <OUTPUT>Destination path
--sheet <SHEET>Worksheet

Shared options

If decide can't answer a text, it prints an error and exits with code 2, 4, 5 or 6. Troubleshooting lists each error and its fix.

In code: Python · TypeScript · Go · Java · Kotlin · C# · R · Ruby · Rust · Swift · Zig · C · C++ · DuckDB · SQLite · PostgreSQL

Next: choose picks one answer from your list.