10-element complex prompt structure template
A recommended guided structure for building complex prompts combines these elements in order: (1) user role in Messages API, (2) task context, (3) tone context, (4) detailed task description and rules, (5) examples in XML tags, (6) input data in XML tags, (7) immediate task description, (8) precognition/step-by-step thinking, (9) output formatting, (10) prefilling assistant response. Not all prompts need every element; the ordering matters for some elements but not others. Best practice is to use many elements to get a prompt working first, then refine and slim down afterward.
Task context positioning in complex prompts
Task context that establishes Claude's role or goal should be placed early in the prompt body, as the second element after confirming the user role is established in the Messages API.
Tone context in complex prompts
Tone context specifies how Claude should communicate (e.g., 'friendly customer service tone'). This element is optional and depends on the task requirements.
Detailed task description and rules positioning
Detailed task descriptions, rules, and fallback behaviors should be included in complex prompts to clarify what Claude should do and provide an 'out' if Claude doesn't have an answer. This should be laid out logically and shown to others for clarity.
Immediate task description positioning
The immediate task description or request that tells Claude what to do right now should be placed toward the end of a long prompt, not at the beginning. This element should include variable substitutions (using f-string syntax) and keep the user's query close to the bottom. It generally does not hurt to reiterate Claude's immediate task.
Prefilling Claude's response in Messages API
Prefilling can be used to steer Claude's behavior or response by starting off the answer with some words. If prefilling is desired, it must be put in the assistant role in the Messages API call, not in the user message. This element is optional depending on the task.
Career coach chatbot example - full prompt
A complete example of a complex prompt for a career coach named Joe. The prompt combines task context ('You will be acting as an AI career coach named Joe created by the company AdAstra Careers'), tone context ('friendly customer service tone'), task rules (stay in character, handle unclear questions), examples showing how to respond, input data (conversation history and user question in XML tags), immediate task ('How do you respond to the user's question?'), precognition ('Think about your answer first before you respond'), and output formatting ('Put your response in <response></response> tags'). Prefilled response starts with '[Joe] <response>' to guide behavior. Input data uses variables like {HISTORY} and {QUESTION} to be dynamically substituted.
Legal services complex prompt example
A complex prompt for legal document analysis demonstrates flexible element ordering. Task context: 'You are an expert lawyer.' Input data in XML tags contains legal research organized by search result ID. Examples show citation format using brackets with search ID numbers. Task description asks to answer a legal question with output limited to a couple paragraphs, with option to demur if insufficient information. Precognition asks Claude to pull relevant quotes into <relevant_quotes> tags before answering. Output formatting specifies putting the response in <answer> tags. Prefilling starts with '<relevant_quotes>' to guide the response structure.
Prompt element ordering flexibility
Not all prompt elements require a fixed order. The complex prompt template provides a recommended ordering, but prompt engineering involves scientific trial and error. Prompt creators should mix and match elements and move things around to see what works best for their specific needs, especially for industry-specific prompts. Experimentation is encouraged.
Industry-specific prompts use same structure
Prompts within specific professions (legal, financial, medical) can be quite complex due to needs to parse long documents, deal with complex topics, format output in specific ways, and follow multi-step analytical processes. These industry-specific prompts are similarly structured to the general complex prompt template but may reorder elements based on needs.
Ten prompt elements for complex legal analysis
When building complex prompts from scratch, structure them with ten elements: (1) user role message, (2) task context describing the role Claude should take, (3) tone context (if important), (4) input data in XML tags, (5) examples of ideal responses in XML tags, (6) detailed task description and rules, (7) immediate task description or final request, (8) precognition or step-by-step thinking instruction, (9) output formatting, and (10) prefilling Claude's response if needed. These elements can be combined in a logical sequence where later elements reinforce and clarify earlier ones.
Order of prompt elements in complex prompts
In a complex prompt, place task context early in the body for immediate framing. Input data can go after context. Examples should be provided prominently. Detailed task description and rules come after examples. Immediate task description or reiteration of what Claude should do should go toward the end, along with the user's query. Precognition or step-by-step thinking instructions should be placed toward the end, right after the final immediate task request. Output formatting instructions should go near the end rather than at the beginning. Prefilling of Claude's response is placed in the assistant role of the API call.
Reiterate immediate task at end of complex prompt
In long prompts, it is generally good practice to reiterate to Claude its immediate task toward the end of the prompt rather than only stating it at the beginning. This placement yields better results. Similarly, the user's query or question should be placed close to the bottom of the prompt to ensure it is fresh in Claude's context window.
Conditional inclusion of optional prompt elements
When assembling a prompt from multiple elements, only include optional elements if they are needed for the specific task. For example, tone context may not be necessary for all tasks. The same applies to immediate task description and prefilling. Structure the prompt construction logic to conditionally add elements only when they have content, avoiding unnecessary padding of the final prompt.