Wetel
Go back

Getting structured data out of a conversation: order numbers, dates and categories

Picture a clerk at a service desk with a paper form. The customer tells a long story: they ordered a jacket last week, maybe the week before, the number is somewhere in an email, it came in the wrong size, and also they moved house. The clerk’s job is not to retell the story. It is to write one order number in one box, tick one category, and, if the number is missing, ask for it before filling in anything else.

An AI employee doing order support has the same job between two steps of a workflow: the customer writes in sentences, and the next step, a lookup in your order system, needs a field. This post covers how to get that field out reliably in Wetel, what goes wrong, and where a person on your team checks before anything is written.

Why a model’s free text is a poor input for the next step

Because a later step needs one exact value, and a model asked for one value sometimes answers with a sentence. A lookup expects 48213. A model asked “what is the order number?” may reply “The order number appears to be 48213”, or “Could you confirm the order number?”, or, when the conversation is about a refund, a friendly refund confirmation it was never asked to write.

The docs describe both failures. A narrow extraction step can drift into answering what the conversation is about: asked only for a booking date, a model can produce “Your booking is confirmed!”. And an off-task reply where a number was expected breaks the next step’s JSON with a confusing “did not render to valid JSON” error.

Prompt wording alone does not close this. The docs say it plainly: no prompt guarantees full compliance on every call, and if the same mistake keeps recurring, change the structure of the workflow instead of patching the prompt again.

The structural options on the llm step

Wetel’s llm step has options that throw away the model’s wording and keep only the value you asked for. Each one replaces the model’s raw text in outputVar with something a later step can rely on.

Two settings go with them:

Here is the docs’ own worked example: a step that matches the slot a customer asked for to an internal numeric id.

{
"id": "extract_slot_id",
"type": "llm",
"label": "Match Requested Slot to Internal ID",
"config": {
"outputVar": "slotId",
"promptTemplate": "You are a scheduling assistant's internal matching step. You are not talking to the user — output only a number.\n\nThe user asked for this slot: \"{{userMessage}}\". Available slots are: {{availableSlots}}. Respond with ONLY the numeric id of the best-matching slot from the list, and nothing else. If none match, respond with 0.",
"extractFirstInteger": true,
"streamOutput": false
}
}

A stray reply like “I think slot 4 works best” still leaves slotId holding the number 4.

When the value must match a list you already fetched

If an earlier step already fetched the records, let the findId template helper look up the id, not the model. Asked to find a record and output its id, a model can confuse a different field’s digits for the id: a room code POD-401 read as id 401. findId does the same lookup with no model involved, tolerates small differences such as a trailing plural, and returns 0 when nothing matches or more than one record could match. It never guesses.

When you need several fields at once

Ask one step for a JSON object with all the fields, then check them in a later step. The docs suggest this for independent fields, since each llm step is another model round trip. Two cautions: matchAnyOf cannot be used on a step that must output JSON, and models often wrap JSON in a code fence, so tell the model Output raw JSON only, no markdown code fence and strip a fence in whatever reads it. The docs describe no option that forces a reply to match a schema, so treat every field as unchecked until a later step has checked it.

Frame the step as a pipeline step, not the assistant

Tell the extraction step plainly that it is not talking to the customer. This is the single change the docs recommend for every extraction step from the start. Their example prompt:

You are a data extraction step in an automated pipeline, not the assistant
talking to the user — you must NOT generate a reply, confirmation,
explanation, or any commentary. Output ONLY the requested value, nothing
else. Extract ONLY the appointment date from this message: "{{userMessage}}".
Respond with ONLY the date in YYYY-MM-DD format, nothing else.

Three parts do the work: say it is not talking to the user, forbid any reply or commentary, and restate the exact output format at the end.

Two more habits:

What to do when nothing is found

Check the value with a condition step, and on the false branch ask the customer one specific question. The docs’ order example does exactly this: extract the order id, check it, look the order up only if one was found, and otherwise reply:

I couldn’t find an order number in your message — could you share your order ID so I can look it up?

In short: an llm step extracts the order id, a condition step checks that it is greater than zero, and the workflow looks the order up if it is, or asks the customer for the order number if it is not.

flowchart LR
E["llm: extract order id<br/>(extractFirstInteger)"] --> C{"condition:<br/>orderId > 0"}
C -- true --> L["look up the order"]
C -- false --> Q["response: ask for<br/>the order number"]

The check is the expression from the docs:

{ "expression": "orderId > 0" }

Write it as > 0, not as a comparison with the string '0'. The value extractFirstInteger stores is a number, and a condition step compares without converting types, so '0' != 0 is true and a “nothing found” value would walk straight through a string check. > 0 also fails closed if the value ever turns out to be text. For extractAlphanumericId, the docs’ gate is != "NONE".

Two condition details help here. If the expression names a variable that is not in the context at all, the step takes the false branch rather than failing the run. So write every gate with the outbound, consequential branch on true: an unanswerable check then takes the branch that does nothing. And a condition cannot read nested properties, only flat variables, which is one more reason to extract into a plain outputVar.

Check before anything is written

Put the check before any step that writes to another system, and add a person where a wrong value would be costly. Looking up an order with a wrong number is cheap: the lookup finds nothing, and you ask again. Issuing a refund, changing an address or cancelling an order against the wrong record is not.

So, in rising order of care:

  1. Always a condition gate before the write, as above.
  2. Read the value back when it is cheap to do so: “I read your order number as 48213. Is that right?”
  3. An approval step, when the write is consequential. You add it to the workflow; it is not on by default. The run pauses, a workspace owner sees the request, and approves, rejects with a comment, or corrects a field you allowed them to edit before the workflow carries on. Requests expire after 72 hours by default and then follow an explicit expired path. Owners can be notified in the app; email notice is not available yet.

This is the supervisor initialling the clerk’s form: a wrong number can be corrected in the request. Designing approval steps people actually read covers how to word one.

How to check what was extracted

Every run leaves a record of each step, including what the extraction step stored. When a customer says “it looked up the wrong order”, that record shows the value the step produced and which branch the condition took. When a condition took the false branch because a variable was missing, the run’s context lists the missing names. What is a run record, and how do I read one? walks through it.

We publish no accuracy figure for extraction, and you should not assume one. Test each extraction step against varied, real phrasing from your own customers, not just your first example. Before you change a classification step’s prompt or model, the docs suggest saving a real run as a regression scenario and replaying it against your draft, because a change can quietly alter where messages are routed.

A checklist for every extraction step

For every field and option, read the LLM step reference.


Share this post:

Next Post
What is a sub-agent, and when would I use one?
Previous Post
How do my other systems find out what an AI employee did?