Response Prefill
PromptingDefinition
A technique where you begin Claude's response by adding a partial assistant turn before the API call. Claude continues from that starting point, allowing precise control over response format, structure, and starting content. Useful for forcing JSON or specific syntax.
Example Usage
Prefill with '{"result":' to force Claude to start its response mid-JSON, guaranteeing the output begins with your desired format.
In Depth
Response prefill was a technique where a developer supplied a partial assistant turn — the beginning of Claude's response — as the last entry in the messages array before sending the API request. Claude would then continue generating from that starting point, giving precise control over the opening format of the response.
Why it was useful. Prefill offered a lightweight way to force a specific response opening without defining a full tool schema. The canonical use case was JSON extraction: prefilling with {"result": told Claude unambiguously to produce an object, reducing the chance of it starting with prose like "Here is the JSON you requested:". Similarly, prefilling with a < character could force an XML-structured response.
Current status: removed on modern models. Last-assistant-turn prefill returns HTTP 400 on Claude Opus 4.6, Opus 4.7, Opus 4.8, Sonnet 4.6, and Fable 5. Sending a messages array whose final entry has role: "assistant" on any of these models will fail immediately. This is not a deprecation with a grace period — it is a hard error on currently deployed models.
What to use instead. The replacement for prefill's core use case — guaranteeing response shape — is structured output. Define the desired schema as a tool and set tool_choice to force its use; the tool_use block's input field is always valid JSON. For API-level schema enforcement without the tool-use overhead, use output_config: {format: {type: "json_schema", schema: {...}}}. Both approaches are more robust than prefill was, because they enforce schema validity rather than merely steering the opening string.
What is still supported. Few-shot examples placed *earlier* in the messages array — real prior user/assistant turns as demonstrations — are unaffected. Only the final entry having role: "assistant" is disallowed. XML tags in the prompt remain fully supported and can steer Claude toward a particular response structure without triggering a 400 error.
Exam context. The CCA-F exam may present prefill as a technique in a code sample or question stem. Recognize it, know it is removed on current models, and identify the correct modern replacement. Any question asking "which technique forces a specific response format" should be answered with tool-based structured output, not prefill. The tool_choice Options & Forced Tool Selection guide covers the full tool-forcing workflow.
How It's Tested & Common Confusions
- Error recognition: Given a code snippet that appends
{"role": "assistant", "content": "{"}to the messages array, identify that this will return HTTP 400 on current models. - Migration scenario: "A pipeline uses prefill to guarantee JSON output. It must be migrated to a current model. What is the correct replacement?" — tool-forcing with a JSON schema.
- True/false: "Response prefill is a supported technique for controlling output format on Claude Sonnet 4.6" — FALSE.
- Distractor trap: Confusing prefill (removed) with few-shot examples in prior turns (still supported) — they are distinct features.
Frequently Asked Questions
Does removing prefill affect few-shot examples in prior turns?
No. Few-shot examples placed as earlier user/assistant pairs in the conversation history are fully supported and unaffected. Only the final `messages` entry having `role: "assistant"` (the actual prefill pattern) is rejected. Place examples in the system prompt inside `<examples>` tags or as prior turns, not as the last message.
Which models still support prefill?
Prefill returns HTTP 400 on Opus 4.6, Opus 4.7, Opus 4.8, Sonnet 4.6, and Fable 5 — the entire current model lineup. There is no current production model that accepts it. Migrate all pipelines that relied on prefill to tool-based [structured output](/glossary/structured-output) or `output_config` JSON schema enforcement.
Can XML tags in the prompt approximate what prefill did?
[XML tags](/glossary/xml-tags) can strongly steer Claude's response format — asking it to reply inside `<output>` tags or to start with a JSON object — but they are prompting guidance, not a hard contract. For a guaranteed parseable JSON response, use structured output via tool-forcing, which gives you schema validation rather than just probabilistic steering.