Stop Sequences

Stop sequence

Part of: Reading Model Outputs

You ask a model to fill in one Q&A pair, but it cheerfully rolls right past it, inventing a second question, a third, a whole imaginary interview. You only wanted the first answer. The clean fix isn't a longer prompt; it's a tripwire. Tell the API: the moment you generate the string "Q:", stop. That tripwire is a stop sequence , and it gives you surgical control over where output ends. What it is A stop sequence is a string you hand the API that says: "if you're about to produce this, halt immediately." The moment the model generates that string, generation stops, and (on most APIs) the stop string itself is not included in the returned content. You get everything up to it, cleanly cut. You can supply one or several. They're a deliberate boundary you define, as opposed to the model's own natural ending. When a stop sequence fires, the response's finish reason becomes stop sequence (or similar), telling you the halt was triggered by your tripwire rather than a natural stop or the length cap. How it works Here's the idea simulated in plain Python, split the model's would-be output at the first stop string: The model would have kept going into a second question, but the stop sequence

Challenge: Earliest-Wins Stop Sequence Cutter