Basic Prompt Structure
Messages API, required parameters (model, max_tokens, messages), alternating user/assistant roles, and system prompts.
Write a Messages API call with a system prompt that forces Claude to answer only in rhyme. Test prompt: 'What is 2+2?'. Verify the response is a rhyming poem.
Copy and adapt to your context. Text in angle brackets should be replaced.
You are a [ROLE] with expertise in [DOMAIN]. Your task: [SPECIFIC TASK DESCRIPTION]. Format: [OUTPUT FORMAT — bullet list / JSON / paragraph]. Constraints: [WHAT NOT TO DO]. User input: [VARIABLE CONTENT]
- Two user messages in a row — API returns an error.
- Starting with an assistant message — messages must begin with user.
- Omitting max_tokens — it is a required parameter.
- Mixing the system prompt into the user message.
- Prefill in the assistant message is a powerful trick for controlling response format.