Triage a support inbox
At the end, every message in your inbox has a queue, and the messages ThinkThen is not sure about wait in a file for a person.
1. Put the messages in a file
Section titled “1. Put the messages in a file”Write one message per line as JSON, each with an id and a text:
{"id":"a1","text":"Please refund my order."}{"id":"a2","text":"Where is my parcel?"}{"id":"a3","text":"I was charged twice for one invoice."}2. Write the questions in a toolbox
Section titled “2. Write the questions in a toolbox”A toolbox file holds several named questions. refund is a yes-or-no question with a low and a high bar, so a message between them comes back not sure. topic picks one queue. field says which part of each line to read.
{ "field": "/text", "questions": { "refund": { "function": "decide", "question": "Does the customer request a refund?", "threshold": {"low": 0.2, "high": 0.8} }, "topic": { "function": "choose", "question": "What is the message about?", "choices": ["billing", "shipping", "other"] } }}3. Ask both questions about every message
Section titled “3. Ask both questions about every message”annotate asks every question in the toolbox about each message. --into triage adds the answers to each line under triage, and jq shows them:
thinkthen annotate --into triage \ triage.json messages.jsonl > triaged.jsonljq -c '{id, triage}' triaged.jsonlOutput
{"id":"a1","triage":{"refund":true,"topic":"billing"}}
{"id":"a2","triage":{"refund":false,"topic":"shipping"}}
{"id":"a3","triage":{"refund":"unsure","topic":"billing"}}
The first message asks for a refund and the second doesn't. The double charge falls between the bars, so its refund answer is "unsure".
4. Send each message to its queue
Section titled “4. Send each message to its queue”The model only answers. Your code decides the route, here in route.jq:
.triage as $t| if any($t.refund, $t.topic; . == null or . == "unsure") then "\(.id) person" elif $t.refund == true then "\(.id) refunds" else "\(.id) \($t.topic)" endjq -r -f route.jq triaged.jsonlOutput
a1 refunds
a2 shipping
a3 person
When both answers arrived, a refund goes to the refunds queue and anything else goes to its topic. If either answer is not sure or failed, the message goes to a person, never to a queue by default.
5. Hand the not-sure messages to a person
Section titled “5. Hand the not-sure messages to a person”Keep the not-sure and failed lines in their own file. Each line keeps its text, so the person reads the message itself:
jq -c 'select(any(.triage.refund, .triage.topic; . == null or . == "unsure"))' \ triaged.jsonl > person.jsonljq -r .text person.jsonlOutput
I was charged twice for one invoice.
The double charge is the one message a person reads.
Check the result
Section titled “Check the result”- Every
idappears once in step 4. A line withnullfor an answer failed; Troubleshooting lists each error and its fix. - Read ten messages from each queue. If a queue holds messages that belong elsewhere, reword the question or add a choice, and run it again.
- Measure answers against your own labels before you trust the bars.
Break a problem into decisions shows how to split a job like this one into small questions.