Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 4.7 — Extraction and Classification
LLM Engineering · Example 2 of 2

Classification with unknown, a threshold and a reason

Confidence is an integer from 0 to 100, so the output is the same in every language.

Extraction pulls fields out of text and classification picks one label from a list. Both go wrong the same way: a model asked to fill every field will invent a value. Give it an honest way out (null or unknown), and check values against the source.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write normalise(s) that lowercases a string and removes spaces and dashes, and supported(value, source) that returns True when the normalised value is inside the normalised source.

02

Write route(label, confidence) that returns "auto" if the label is not unknown and the confidence is at least 70, and "human" otherwise.

Explain it without notes

01

Why does a required field in a schema encourage hallucination?

02

What is an evidence check, and what are its limits?

03

How would you design the label list for a classifier?

04

How do you use a confidence value responsibly?

Classification with unknown, a threshold and a reason
Sign in to run this example in your browser.

Expected output

I was charged twice              -> billing
The app crashes on start         -> bug
Maybe dark mode, or fix login?   -> needs review (feature, confidence 55)
hello                            -> unknown (the model said so)
Refund me                        -> unknown (label "refund" is not allowed)
???                              -> unknown (reply was not JSON)