AI & LLMs

Stop Sequence

A string that tells the model to stop generating as soon as it produces it.

A stop sequence is a string you specify that halts generation the moment the model emits it — the text up to (but not including) the stop sequence is returned. It is how you bound output and parse structured completions.

Worked example: when prompting in a “User:/Assistant:” format, setting the marker that begins the user’s turn (the line break before “User:”) as a stop sequence makes the model stop before it hallucinates the user’s next turn; a blank line can end a single block. Gotcha: the stop sequence is consumed, not returned, and matching is exact — a stray space or different casing will not trigger it — so design the prompt so the stop token appears reliably.