In a few-shot prompt that extracts structured fields from invoices, why is a distinctive stop sequence (like a custom END_INVOICE marker) better than a paragraph break or the natural end of response?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
You're an LLM engineer designing a few-shot prompt that extracts structured fields (vendor, total, line items) from invoice text. You're picking how the model should signal the end of each extracted record. Walk through why a distinctive stop sequence (like a custom END_INVOICE marker) is better than a paragraph break or relying on the model's natural end of response, and what properties make a stop sequence robust.
A marker like END_INVOICE is collision-safe, self-anchoring through few-shot demos, decoupled from format changes, and composable across tasks. Pair it with the API's stop_sequences for byte-level enforcement.
Imagine you are training a friend to read invoices and write down what they see. You could tell them 'stop when you reach a blank line' but invoices have blank lines inside them. Instead you say 'when you are done with each invoice, write THE END on its own line'. Now you have a clear signal that will not be confused with anything inside the invoice. You also show them ten example invoices that all end with THE END, so they pick up the habit. And you tell the machine reading their notes to ignore anything after THE END. Three layers, one clean signal.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: four properties of a good terminator (collision-safe, self-anchoring, decoupled, composable) + the three-layer contract (few-shot, model, API) + parser as safety net.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Using a paragraph break as the terminator on a structured-extraction prompt, then watching extractions get truncated whenever the model produces a blank line inside a multi-line address or line-item block.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.