[ ABORT TO HUD ]
SEQ. 1
SEQ. 2

Stop Sequences & Prefills

🏗️ Prompt Engineering Mastery20 min250 BASE XP

Controlling the Narrative

Stop Sequences are a developer's strongest tool for preventing hallucination and managing costs. By defining a list of strings (e.g., ["</json>", "User:"]), you tell the model to instantly stop computing tokens as soon as it predicts those exact characters. This is essential for ensuring a model doesn't continue with unnecessary conversational filler after completing a structured task.

The Power of Assistant Prefilling

You can steer Claude's starting point by including a final assistant message that is not yet complete. For example, by prefilling the assistant reply with { "analysis": , you force Claude to bypass the common "Sure, here is your analysis" introduction and immediately begin generating valid JSON. This technique significantly improves reliability for automated pipelines.

SYNAPSE VERIFICATION
QUERY 1 // 3
What is the financial benefit of 'stop_sequences'?
None
The generation terminates instantly, and you are only billed for compute up until that cutoff
It makes tokens cheaper
It hides the response
Watch: 139x Rust Speedup
Stop Sequences & Prefills | Prompt Engineering Mastery — Claude Academy