Stop Sequences & Prefills — Prompt Engineering Mastery
Stop Sequences & Prefills
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.
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.