Complex Prompts for Legal Services
Example
Prompts within the legal profession can be quite complex due to the need to:
- Parse long documents
- Deal with complex topics
- Format output in very specific ways
- Follow multi-step analytical processes
Let's see how we can use the complex prompt template to structure a prompt for a specific legal use-case.
Below, we've detailed out an example prompt for a legal use-case wherein we ask Claude to answer questions about a legal issue. (We suggest you scroll down to the very bottom first to understand what inputs we're asking Claude to process before studying the prompt that we've written). We've changed around the ordering of a few elements to showcase that prompt structure can be flexible!
Prompt engineering is about scientific trial and error. We encourage you to mix and match, move things around (the elements where ordering doesn't matter), and see what works best for you and your needs.
User: You are an expert lawyer.
Here is some research that's been compiled. Use it to answer a legal question from the user.
<legal_research>
{{LEGAL_RESEARCH}}
</legal_research>
When citing the legal research in your answer, please use brackets containing the search index ID, followed by a period. Put these at the end of the sentence that's doing the citing. Examples of proper citation format:
<examples>
<example>
The statute of limitations expires after 10 years for crimes like this. [3].
</example>
<example>
However, the protection does not apply when it has been specifically waived by both parties. [5].
</example>
</examples>
Write a clear, concise answer to this question:
<question>
{{QUESTION}}
</question>
It should be no more than a couple of paragraphs. If possible, it should conclude with a single sentence directly answering the user's question. However, if there is not sufficient information in the compiled research to produce such an answer, you may demur and write "Sorry, I do not have sufficient information at hand to answer this question.".
Before you answer, pull out the most relevant quotes from the research in <relevant_quotes> tags.
Put your two-paragraph response in <answer> tags.
Assistant: <relevant_quotes>
Complex Prompt Elements
Build complex prompts by combining these 10 elements in order:
Open your CLAUDEMESSAGES() prompt with "User:".
User:This is mandatory! Prompts to Claude using CLAUDEMESSAGES() always need to begin with this.
Give Claude context about the role it should take on or what goals and overarching tasks you want it to undertake with the prompt.
You are an expert lawyer.It's best to put context early in the body of the prompt.
If important to the interaction, tell Claude what tone it should use.
This element may not be necessary depending on the task.
If there is data that Claude needs to process within the prompt, include it here within relevant XML tags. Feel free to include multiple pieces of data, but be sure to enclose each in its own set of XML tags.
Here is some research that's been compiled. Use it to answer a legal question from the user. <legal_research> {{LEGAL_RESEARCH}} </legal_research>
When input data is long, it's best to put it before the instructions.
Provide Claude with at least one example of an ideal response that it can emulate. Encase this in <example></example> XML tags. Feel free to provide multiple examples. If you do provide multiple examples, give Claude context about what it is an example of, and enclose each example in its own set of XML tags.
When citing the legal research in your answer, please use brackets containing the search index ID, followed by a period. Put these at the end of the sentence that's doing the citing. Examples of proper citation format:Examples are probably the single most effective tool in knowledge work for getting Claude to behave as desired. Make sure to give Claude examples of common edge cases. If your prompt uses a scratchpad, it's effective to give examples of how the scratchpad should look. Generally more examples = more reliable responses at the cost of latency and tokens. We have only one example here to make the prompt easier to read.
Expand on the specific tasks you want Claude to do, as well as any rules that Claude might have to follow. This is also where you can give Claude an "out" if it doesn't have an answer or doesn't know.
Write a clear, concise answer to this question:It's ideal to show this description and rules to a friend to make sure it is laid out logically and that any ambiguous words are clearly defined.
"Remind" Claude or tell Claude exactly what it's expected to immediately do to fulfill the prompt's task. This is also where you would put in additional variables like the user's question.
It generally doesn't hurt to reiterate to Claude its immediate task. It's best to do this toward the end of a long prompt. This will yield better results than putting this at the beginning. It is also generally good practice to put the user's query close to the bottom of the prompt.
For tasks with multiple steps, it's good to tell Claude to think step by step before giving an answer. Sometimes, you might have to even say "Before you give your answer..." just to make sure Claude does this first.
Before you answer, pull out the most relevant quotes from the research in <relevant_quotes> tags.
If there is a specific way you want Claude's response formatted, clearly tell Claude what that format is.
Put your two-paragraph response in <answer> tags.
This element may not be necessary depending on the task.
A space to start off Claude's answer with some prefilled words to steer Claude's behavior or response.
Assistant: <relevant_quotes>
"Assistant:" is only necessary if you want to prefill Claude's response. Otherwise, it can be left off.
Examples
You are an expert lawyer. Here is some research that's been compiled. Use it to answer a legal question from the user. <legal_research> {{LEGAL_RESEARCH}} </legal_research> When citing the legal research in your answer, please use brackets containing the search index ID, followed by a period. Put these at the end of the sentence that's doing the citing. Examples of proper citation format: <examples> <example> The statute of limitations expires after 10 years for crimes like this. [3]. </example> <example> However, the protection does not apply when it has been specifically waived by both parties. [5]. </example> </examples> Write a clear, concise answer to this question: <question> {{QUESTION}} </question> It should be no more than a couple of paragraphs. If possible, it should conclude with a single sentence directly answering the user's question. However, if there is not sufficient information in the compiled research to produce such an answer, you may demur and write "Sorry, I do not have sufficient information at hand to answer this question.". Before you answer, pull out the most relevant quotes from the research in <relevant_quotes> tags. Put your two-paragraph response in <answer> tags.
<relevant_quotes>
You are an expert lawyer. Here is some research that's been compiled. Use it to answer a legal question from the user. <legal_research> </legal_research> When citing the legal research in your answer, please use brackets containing the search index ID, followed by a period. Put these at the end of the sentence that's doing the citing. Examples of proper citation format: <examples> <example> The statute of limitations expires after 10 years for crimes like this. [3]. </example> <example> However, the protection does not apply when it has been specifically waived by both parties. [5]. </example> </examples> Write a clear, concise answer to this question: <question> </question> It should be no more than a couple of paragraphs. If possible, it should conclude with a single sentence directly answering the user's question. However, if there is not sufficient information in the compiled research to produce such an answer, you may demur and write "Sorry, I do not have sufficient information at hand to answer this question.". Before you answer, pull out the most relevant quotes from the research in <relevant_quotes> tags. Put your two-paragraph response in <answer> tags.
Response will be generated by the LLM