Loading pattern...

What is Stop Sequence?

Stop Sequences are strings that tell the AI "stop generating when you hit this text." Like a "stop sign" for generation. Example: AI generates list items "1. Item\n2. Item\n3. Item"—set stop sequence "\n\n" to stop at first double newline. Useful for extracting specific parts of output, preventing rambling, or structured generation. Most APIs support 1-4 stop sequences. Simple but powerful control mechanism.

When Should You Use This?

Use stop sequences when you want AI to stop at a specific point: generating one list item (stop at "\n"), extracting first paragraph (stop at "\n\n"), preventing AI from adding commentary after answer, or structured templates (stop at "---"). Great for precise control without complex prompts. Common in code generation (stop at function end), data extraction, or dialogue systems.

Common Mistakes to Avoid

  • Not testing—stop sequence might appear in desired output, cutting it off
  • Too generic—stop="." cuts off at first period, use specific sequences
  • Forgetting edge cases—what if stop sequence never appears? AI generates max tokens
  • Multiple sequences—be careful they don't conflict or overlap
  • Over-engineering—often simpler to use prompting than stop sequences

Real-World Examples

  • List generation: Stop at "\n\n" to get one item at a time
  • Code: Stop at "```" or "END" to prevent extra commentary
  • Q&A: Stop at "Question:" to get one answer per call
  • Structured: "Output format:\nName: ...\nAge: ...\n---" with stop="---"

Category

Ai Vocabulary

Tags

stop-sequenceoutput-controlllm-parametersgeneration-controlprompt-engineering

Permalink