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.

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. 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.
{
"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.
{
"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.
{
"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.
{
"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'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
assistantturn. 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's Chat Completions does not continue a trailing
assistantmessage 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).
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.
Related recipes
Claude Structured Output: 3 Prompt Recipes That Ship (June 2026)
Three production-grade Claude structured output recipes for June 2026. Invoice extraction on Sonnet 4.6, support triage on Haiku 4.5, NL to SQL on Opus 4.7. Real cost per call. Three failure modes the docs do not warn you about.
Multi-step JSON repair: make any model return valid JSON on the second try
Step one: ask for JSON. Step two: if JSON.parse throws, send the broken string plus the parser error back and ask only for a corrected version. Don't re-explain the task. Models fix syntax far more reliably than they self-correct semantics. Two steps, near-zero unparseable output.
Chain of Thought Prompting: 6 Examples That Ship (2026)
Five paste-ready chain-of-thought prompting examples for 2026, each with its failure mode, plus when reasoning out loud makes the answer worse.


