Prompt Recipes
Sam Q.5 min read8 views

Assistant Prefill: 4 Recipes That Ship (2026)

Assistant prefill in 2026: four copy-paste recipes that force JSON, kill the preamble, lock the output shape, and hold a persona, plus where prefill breaks.

A chat bubble on a stark white background with a bold amber curly brace and a blinking cursor typed at the very start of the reply, showing an assistant response that has been prefilled.
A chat bubble on a stark white background with a bold amber curly brace and a blinking cursor typed at the very start of the reply, showing an assistant response that has been prefilled.
On this page

Quick Answer

Assistant prefill means you write the first few characters of the model's reply yourself, in a final assistant message, and the model continues from there. In 2026 it is the cheapest way to force JSON, kill the "Sure, here is..." preamble, lock an output shape, and hold a persona. It works natively on Claude via the Messages API; the four recipes below are copy-paste and ship.

Prefill is one move: put a partial assistant turn at the end of messages. The model treats your text as words it already said and writes the rest. No system-prompt gymnastics, no retries. Anthropic logo It is documented in Anthropic's prompting best practices and is the highest-leverage trick most people never turn on.

Recipe 1: Force JSON with a single brace

Claim. Prefill { and the model cannot open with prose. It has to start the object.

Receipt.

json
{
  "model": "claude-sonnet-5",
  "max_tokens": 400,
  "messages": [
    {"role": "user", "content": "List 3 EU capitals. Keys: city, country."},
    {"role": "assistant", "content": "{"}
  ]
}

The reply comes back as "capitals": [ ... ] }. Prepend the { you sent and you have valid JSON on the first call.

Why it works. The model predicts the next token given everything before it. With { already "said," the highest-probability continuation is more JSON, not "Sure, here is the data."

Failure mode. The model may still close with a trailing note after the object. Add a stop sequence on the closing brace, or instruct "output only JSON." If it already came back malformed, do not prefill twice; run a second-pass JSON repair instead. For richer schemas, pair prefill with structured-output recipes.

Recipe 2: Kill the preamble

Claim. Prefill the first real word of the answer and the throat-clearing disappears.

Receipt.

json
{
  "model": "claude-haiku-4-5",
  "max_tokens": 200,
  "messages": [
    {"role": "user", "content": "Is this refund request in policy? Answer with a verdict then one reason."},
    {"role": "assistant", "content": "Verdict:"}
  ]
}

Output starts at Verdict: In policy. The order shipped 4 days ago.... No "Great question," no restating the prompt.

Why it works. You spent the tokens the model would have used on pleasantries. It resumes mid-answer.

Failure mode. Prefill too much and you put words in its mouth it disagrees with, which skews the answer. Prefill the label, not the conclusion.

Recipe 3: Lock the output shape

Claim. Prefill the header row of a table (or the first bullet) and every response lands in the same shape.

Receipt.

json
{
  "model": "claude-sonnet-5",
  "max_tokens": 600,
  "messages": [
    {"role": "user", "content": "Compare Redis and Postgres for a job queue."},
    {"role": "assistant", "content": "| Factor | Redis | Postgres |\n|---|---|---|\n|"}
  ]
}

The model fills the table instead of writing three paragraphs first. Same shape across a batch of 500 calls, which makes the output parseable.

Why it works. The prefill is the format contract. The model matches it because matching is the likeliest continuation.

Failure mode. If the task genuinely needs prose, forcing a table degrades the answer. Use this only when downstream code parses the output.

Recipe 4: Hold a persona

Claim. Prefill the character's name tag and the model stops breaking role.

Receipt.

json
{
  "model": "claude-sonnet-5",
  "max_tokens": 500,
  "messages": [
    {"role": "system", "content": "You are Ada, a terse senior SRE. Never mention you are an AI."},
    {"role": "user", "content": "The deploy is stuck. What now?"},
    {"role": "assistant", "content": "[Ada]:"}
  ]
}

Every turn re-anchors on [Ada]:, so the model resumes in character instead of drifting into "As an AI assistant...".

Why it works. The name tag is a stronger local signal than the system prompt after a few turns. Prefill re-asserts it on every call.

Failure mode. The tag leaks into the output. Strip the leading [Ada]: in post-processing, or use a stop sequence.

Where prefill breaks

Three hard edges, all documented, all worth knowing before you ship.

  • No trailing whitespace. Anthropic logo Anthropic's API rejects a prefill that ends in a space or newline. End on a real character. "{" is fine; "{ " is an error.
  • Not compatible with extended thinking. When you turn on extended thinking, you cannot also prefill the assistant turn. Pick one: reasoning mode, or a forced opening. For most JSON and format jobs you do not need thinking, so prefill wins on cost.
  • Portability is not free. OpenAI logo OpenAI's Chat Completions does not continue a trailing assistant message the same way; a final assistant turn is treated as prior context, not a seed to extend. If you want the same guarantee on GPT, use response-format JSON mode instead of prefill. The recipes above are written for Claude, where prefill is a first-class control.

Prefill is not a jailbreak and not a hack. It is the model finishing a sentence you started. Start the sentence where you want the answer to begin.

FAQ

What is assistant prefill?
Assistant prefill is adding a final message with role assistant and partial content to the Messages API. The model treats that text as the start of its own reply and continues it, letting you control how the answer begins.

How do I force a model to return only JSON?
Prefill the assistant message with an opening brace {. The model has to continue the object rather than write prose. Prepend the brace you sent to reassemble valid JSON, and add a stop sequence on the closing brace if trailing notes appear.

Does prefill cost extra tokens?
The prefill characters count as input tokens, which is a few cents at most, and they usually save output tokens by removing preamble. Net cost is flat or lower than a normal call.

Can I use prefill with extended thinking?
No. Prefilling the assistant response is not compatible with extended thinking mode. Use one or the other. For format control, prefill without thinking is cheaper and enough.

Why does my prefill throw an error?
The most common cause is trailing whitespace. The prefill content cannot end in a space or newline. End it on a visible character such as {, a letter, or a colon.

Does assistant prefill work on GPT models?
Not identically. OpenAI's Chat Completions treats a final assistant message as context, not a seed to extend. On GPT, use JSON mode or a response-format schema to get the same guarantee.

Cost to test: $0.02 (all four recipes on Haiku 4.5 and Sonnet 5, under a dozen calls).

S

Written by

Sam Q.

Sam Q. writes terse, tested prompt recipes for PromptAttic. Ships them the way you would a commit message: short, verified, no preamble.

FAQ

What is assistant prefill?

Assistant prefill is adding a final message with role assistant and partial content to the Messages API. The model treats that text as the start of its own reply and continues it, letting you control how the answer begins.

How do I force a model to return only JSON?

Prefill the assistant message with an opening brace. The model has to continue the object rather than write prose. Prepend the brace you sent to reassemble valid JSON, and add a stop sequence on the closing brace if trailing notes appear.

Does prefill cost extra tokens?

The prefill characters count as input tokens, which is a few cents at most, and they usually save output tokens by removing preamble. Net cost is flat or lower than a normal call.

Can I use prefill with extended thinking?

No. Prefilling the assistant response is not compatible with extended thinking mode. Use one or the other. For format control, prefill without thinking is cheaper and enough.

Why does my prefill throw an error?

The most common cause is trailing whitespace. The prefill content cannot end in a space or newline. End it on a visible character such as an opening brace, a letter, or a colon.

Does assistant prefill work on GPT models?

Not identically. OpenAI's Chat Completions treats a final assistant message as context, not a seed to extend. On GPT, use JSON mode or a response-format schema to get the same guarantee.