Fundamentals of prompt design
When designing prompts for RAG applications, it’s essential to keep the following fundamentals in mind:
- Be concise and specific: Clearly define the task you want the AI model to perform, and provide only the necessary information to complete the task effectively. For example, saying
Please analyze the given context and provide an answer to the question, taking into account all the relevant information and details
would be less concise and specific than sayingBased on the context provided, answer the following question: [
specific question]
. - Ask one task at a time: Break down complex tasks into smaller, more manageable sub-tasks, and create separate prompts for each sub-task to ensure better results. For example, if you said
Summarize the main points of the context, identify the key entities mentioned, and then answer the given question
, that is multiple tasks you are asking for at the same time. You would likely have better results if you broke this into multiple prompts and said something similar to this:Summarize the main points of the following
context: [context]
Identify the key entities mentioned in the following summary: [summary from
previous prompt]
Using the context and entities identified, answer the following question: [
specific question]
- Turn generative tasks into classification tasks: When possible, rephrase open-ended generative tasks as classification tasks with a limited set of options, as this can lead to more accurate and focused responses from the AI model. For example, instead of saying
Based on the context, what is the sentiment expressed towards the topic?
, you would likely have better results if you saidBased on the context, classify the sentiment expressed towards the topic as either positive, negative,
or neutral
. - Improve response quality by including examples: We’ll build off the one-or-more-shot concept we talked about previously. This fundamental concept focuses on providing relevant examples in your prompts to guide the AI model toward the desired output format and style. As an example, rather than saying
Answer the following question based on the provided context
, you would want to say something similar toUsing the examples below as a guide, answer the following question based on the provided context: Example 1: [question] [context] [answer] Example 2: [question] [context] [answer] Current question: [question]
Context: [context]
. - Start simple and iterate gradually: Begin with simple prompts and gradually add more elements and context as needed to achieve better results. This iterative approach allows you to fine-tune your prompts and optimize performance. For example, the
Summarize the main points of the article, identify key entities, and answer the following question: [question]. Provide examples and use the following format for your answer: [format]. Article: [lengthy article text]
prompt will likely be less effective than prompting with multiple iterations such as the following:- Iteration 1:
Summarize the main points of the following article: [
article text]
- Iteration 2:
Summarize the main points and identify key entities in the following article: [
article text]
- Iteration 3:
Based on the summary and key entities, answer the following question: [question] Article: [
article text]
- Iteration 1:
- Place instructions at the beginning of the prompt: Clearly state the instructions at the start of the prompt, and use clear separators such as
###
to distinguish between the instruction and context sections. This helps the AI model better understand and follow the given instructions. For example, you will have less success with a prompt such as[Context] Please use the above context to answer the following question: [question]. Provide your answer in a concise manner
compared to this prompt:Instructions: Using the context provided below, answer the question in a concise manner. Context: [context]
Question: [question]
.
While the fundamentals of prompt design provide a solid foundation for creating effective prompts, it’s important to remember that different language models may require specific adaptations to achieve optimal results. Let’s discuss that topic next.