Skip to main content

Stop Sequences & Prefills — Prompt Engineering Mastery

[ ABORT TO HUD ]
SEQ. 1
SEQ. 2

Stop Sequences & Prefills

📐 Prompt Engineering Mastery⏱ 20 min⭐ 250 BASE XP⌨ HANDS-ON LAB

Controlling the Narrative with Stop Sequences

Stop Sequences are a developer's precise tool for bounding custom text formats and managing costs. By defining stop_sequences (e.g., ["</report>", "END_BLOCK"]), you instruct Claude to halt generation the instant it emits those characters, returning stop_reason: "stop_sequence".

Deprecation of Assistant Prefills & Migration to Structured Outputs

In legacy Claude 3.x/4.5 models, developers included a trailing partial assistant message (prefill) such as {"status": to skip conversational intros. Starting with Claude 4.6 and across all Claude 5.x models (Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5), assistant message prefill is deprecated and removed—sending a trailing assistant turn returns an HTTP 400 Bad Request error. Instead, Anthropic provides native token-level constrained decoding via output_config.format (type: "json_schema"), guaranteeing 100% schema-valid JSON with zero preamble.

⌨ HANDS-ON LABEnforce Zero-Preamble JSON with Structured Outputs
⭐ +150 XP

Assistant message prefill was removed in Claude 4.6/5.5+ (returning HTTP 400). Guarantee zero-preamble, schema-valid JSON on Claude Sonnet 5.5 using output_config.format and stop_sequences.

1POST to /v1/messages on claude-sonnet-5-5 using output_config.format with type 'json_schema' to enforce strict JSON output.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 1 — type "hint" if stuck
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