Flashcard: what is a stop sequence in an LLM API call and what is it used for?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
A stop sequence is a string the model halts generation on the moment it produces it, used to enforce structural boundaries in output, distinct from max-tokens which caps length.
Imagine asking a friend to tell you a story but to stop the second they say the end. A stop sequence is exactly that instruction for an LLM. You hand the API a string, and the model writes one token at a time, checking after each step whether the running output now ends with your stop string. The moment it does, generation halts and that stop string is sliced off before the reply is returned. This is different from telling the friend stop after exactly two minutes, which is what max-tokens does. The stop sequence is a content rule. Max-tokens is a length rule. You usually want both: the stop sequence is the intent, max-tokens is the safety net in case the model never reaches the stop string.
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.
6 min: define stop sequence as content-based termination, contrast with max-tokens, walk through three production uses, name provider differences in match semantics, point to stop_reason for debugging.
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.
Confusing stop sequences with max-tokens; one is a content boundary (terminate on string match), the other is a length cap (terminate after N tokens regardless of content).
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.