A developer calling Anthropic's Messages API wants Claude's response to always begin with a valid JSON object and never with an introductory sentence like 'Here is the JSON you requested:'. According to Anthropic's documentation on prefilling Claude's response, how is this achieved, and through what channel is the technique available?
- By adding a `response_format: json` parameter to the request, which is documented as the only supported way to constrain where Claude's output can start
- By appending a stop sequence equal to the word 'Here' so that Claude is blocked from generating that word at the start of its answer
- By fine-tuning a custom version of Claude on examples that start directly with `{`, since the base model cannot be steered to skip a preamble through prompting alone
- By including the desired starting text (for example an opening `{`) as the beginning of the assistant turn itself in the API call, so Claude's generated response continues directly from that point; the documentation notes this prefill technique is API-only and is not supported on the newest Claude models
Why D? And why not the others?
Correct answer: D. By including the desired starting text (for example an opening `{`) as the beginning of the assistant turn itself in the API call, so Claude's generated response continues directly from that point; the documentation notes this prefill technique is API-only and is not supported on the newest Claude models
Anthropic's documentation describes prefilling as placing the desired starting text, such as an opening brace for JSON, directly into the assistant turn of the API request; because Claude's generated content continues from wherever the assistant message leaves off, the model never generates the preamble in the first place, since that starting text was never something it needed to produce itself. This is documented as an API-only capability, available through direct API or SDK usage, and the documentation also notes it is not supported on the newest Claude models, where such requests return an error. The option describing a `response_format: json` parameter is wrong because Anthropic's documentation describes prefill, not a JSON-mode-style response-format flag, as the mechanism for this. The option describing a stop sequence on the word 'Here' is wrong because stop sequences only halt generation once a matching string is produced; they do not control or guarantee what content the model starts with, so a stray rephrasing could still avoid the word while still adding a preamble. The option describing fine-tuning is wrong because prefilling is a prompting-time technique available to any API caller without training a custom model.
Source: Anthropic, 'Prefill Claude's response for greater output control,' Claude Platform Docs (platform.claude.com/docs/en/build-with-claude/prompt-engineering/prefill-claudes-response)