Prefill Claude's response for greater output control
When using Claude, you have the unique ability to guide its responses by prefilling the Assistant
message. This powerful technique allows you to direct Claude’s actions, skip preambles, enforce specific formats like JSON or XML, and even help Claude maintain character consistency in role-play scenarios.
In some cases where Claude is not performing as expected, a few prefilled sentences can vastly improve Claude’s performance. A little prefilling goes a long way!
How to prefill Claude’s response
To prefill, include the desired initial text in the Assistant
message (Claude’s response will continue from where the Assistant
message leaves off):
Examples
Example 1: Controlling output formatting and skipping the preamble
{
forces Claude to skip the preamble and directly output the JSON object. This is cleaner, more concise, and easier for programs to parse without additional processing.Example 2: Maintaining character in roleplay scenarios
[ROLE_NAME]
can remind Claude stay in character, even for longer and more complex conversations. This is especially powerful when combined with role prompting in the system
parameter.Prompt library
Get inspired by a curated selection of prompts for various tasks and use cases.
GitHub prompting tutorial
An example-filled tutorial that covers the prompt engineering concepts found in our docs.
Google Sheets prompting tutorial
A lighter weight version of our prompt engineering tutorial via an interactive spreadsheet.