Last updated on October 24, 2024
In the rapidly evolving field of Generative AI, crafting effective prompts is essential to achieving high-quality outputs. A prompt is the input provided to an AI model, and its structure determines the accuracy, relevance, and format of the response. Whether you're using AI to write content, generate data, or create images, understanding the parts of a prompt can help you guide the model toward producing better results.
In the previous docs, we discussed instruction prompting, role prompting, and shot-based prompting. In this document, we conclude this discussion by summarizing the main parts of the prompt.
We break down the essential parts of a prompt, providing examples and tips on how to use each element effectively:
Prompts are made up of several key components that work together to guide the AI. While not every prompt will contain all these elements, understanding how each part functions can help you create more targeted and effective inputs.
The key parts of a prompt are:
The Directive is the main instruction in the prompt. It tells the AI exactly what task it should perform. Without a clear directive, the AI may provide a generic or irrelevant response.
A directive is a concise instruction or question that gives the AI a clear task to perform. It can range from a request to generate text, solve a problem, or format information in a specific way.
For example, here a prompt with a single instruction:
Tell me five good books to read.
In some cases, the directive may be implied rather than explicitly stated. These types of prompts still guide the AI but rely on context or formatting to convey the task.
Night: Noche Morning:
Best Practices for Directives:
When the task is more complex, providing Examples can help guide the AI in producing more accurate responses. This technique is especially useful in few-shot and one-shot prompting, where a model is given one or more examples of what you expect in the output.
Examples demonstrate the expected format, style, or structure of the output. By including them in the prompt, you can guide the AI’s behavior and help it better understand the desired result.
Translate the following sentences:
Q: I like apples. A: Me gustan las manzanas.
Q: I enjoy walking.
In this example, the AI is shown how to structure the translation, and it will follow the same pattern for the remaining sentences.
Assigning a Role to the AI, also known as a persona, helps frame the response in a specific way. By telling the AI to act as an expert, a professional, or a specific character, you can guide the tone, style, and content of the response.
The role element in a prompt assigns a specific persona or perspective to the AI, encouraging it to tailor its response according to the designated role. This can greatly enhance the accuracy and relevance of the response, especially for tasks requiring domain-specific knowledge or a particular tone.
Here, the AI is instructed to respond as if it were a medical professional:
You are a doctor. Based on the following symptoms, diagnose the patient.
The AI will assume the role of a customer service agent, ensuring the tone is appropriate for business communication:
You are a customer service agent. Write an email apologizing for a delayed order.
Sometimes, it’s important to specify the format in which you want the AI to present its output. Output Formatting ensures that the response follows a particular structure—whether it’s a list, a table, or a paragraph. Specifying the format can help prevent misunderstandings and reduce the need for additional post-processing.
Without clear formatting instructions, the AI may provide a response that is technically correct but not in the desired format. Specifying the structure makes the output easier to use.
It is often desirable for the GenAI to output information in certain formats, for example, CSVs or markdown formats. To facilitate this, you can simply add instructions to do so as seen below:
Case: 2024_ABC_International Client: XYZ Corporation Jurisdiction: EU & USA Filed Date: 2024-09-01 Status: Active Lead Attorney: John Doe Next Hearing: 2024-10-15
Output this information as a CSV.
Case,Client,Jurisdiction,Filed Date,Status,Lead Attorney,Next Hearing 2024_ABC_International,XYZ Corporation,EU & USA,2024-09-01,Active,John Doe,2024-10-15
You can also specify stylistic preferences, such as tone or length, within the output formatting. This allows you to control not just the content but how it’s presented.
For example:
Write a clear and curt paragraph about llamas.
Additional Information, sometimes referred to as context, though we discourage the use of this term as it is overloaded with other meanings in the prompting space[^b]. It provides the background details the AI needs to generate a relevant response. Including this information ensures that the AI has a comprehensive understanding of the task and the necessary data to complete it.
Additional information can include relevant facts, data, or other background information that helps the AI generate a more accurate and contextually appropriate response. This element is especially important for complex tasks that require specific knowledge.
January 1, 2000: Fractured right arm playing basketball. Treated with a cast.
February 15, 2010: Diagnosed with hypertension.
You are a doctor. Predict the patient’s future health risks based on this history.
In this example, the patient’s medical history is crucial to generating a valid prediction.
There is no single “correct” order for arranging the elements of a prompt, but there are guidelines that can help improve clarity and prevent misunderstandings. In general, starting with examples or context and ending with the directive ensures the AI focuses on the task after processing the relevant information.
Now that you understand the different parts of a prompt, you may wonder if there is a common order in which you should arrange them. You should first note that not all of these occur in every prompt, and when they do there is no standard order for them. However, we do have a suggested order. To understand our order, first consider the following two prompts, which each contain a role, an instruction (the directive), and additional information.
You are a doctor. Read this medical history and predict risks for the patient.
January 1, 2000: Fractured right arm playing basketball. Treated with a cast. February 15, 2010: Diagnosed with hypertension. Prescribed lisinopril. September 10, 2015: Developed pneumonia. Treated with antibiotics and recovered fully. March 1, 2022: Sustained a concussion in a car accident. Admitted to the hospital and monitored for 24 hours.
January 1, 2000: Fractured right arm playing basketball. Treated with a cast. February 15, 2010: Diagnosed with hypertension. Prescribed lisinopril. September 10, 2015: Developed pneumonia. Treated with antibiotics and recovered fully. March 1, 2022: Sustained a concussion in a car accident. Admitted to the hospital and monitored for 24 hours.
You are a doctor. Read this medical history and predict risks for the patient.
Although usually both prompts would give approximately the same output, we prefer the second prompt, since the instruction is the last part of the prompt. This is preferable, since with the first prompt, the large language model (LLM) might just start writing more context instead of following the instruction; if given the first prompt, the LLM might add a new line:
March 15, 2022: Follow-up appointment scheduled with neurologist to assess concussion recovery progress
.
This is due to the fact that LLMs are trained to predict the next token (similar to word) in a paragraph.
Recommended Order for Prompts:
In this prompt, the role and task come after the context, ensuring the AI processes the timeline before generating the output.
The order of the elements affects how the AI processes the information. For instance, placing the directive last helps avoid the AI continuing the additional information instead of focusing on the task at hand.
Crafting effective prompts requires an understanding of the key elements that guide AI responses. By mastering the use of Directives, Examples, Roles, Output Formatting, and Additional Information, you can improve the accuracy and relevance of the outputs generated by AI models. Experimenting with different combinations of these elements will allow you to tailor prompts for a wide range of tasks and achieve better results.
Formalizing prompt language can help you, as a developer, to both create more effective prompts with the key components and better engage in prompt engineering discourse.
Some key parts of a prompt discussed in this article are The Directive, Examples, A Role, Output Formatting, and Additional Information
You should put the examples first, then additional information, then the role, directive, and output formatting.
Output formatting ensures that the AI delivers the response in the desired structure, whether it’s a table, list, or paragraph, reducing the need for post-processing.
Yes, many prompts don’t need examples, especially for simpler tasks. However, including examples can guide the AI more effectively for complex requests.
Schulhoff, S., Ilie, M., Balepur, N., Kahadze, K., Liu, A., Si, C., Li, Y., Gupta, A., Han, H., Schulhoff, S., & others. (2024). The Prompt Report: A Systematic Survey of Prompting Techniques. arXiv Preprint arXiv:2406.06608. ↩
Searle, J. R. (1969). Speech acts: An essay in the philosophy of language. Cambridge University. ↩
Xia, C., Xing, C., Du, J., Yang, X., Feng, Y., Xu, R., Yin, W., & Xiong, C. (2024). FOFO: A Benchmark to Evaluate LLMs’ Format-Following Capability. In L.-W. Ku, A. Martins, & V. Srikumar (Eds.), Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) (pp. 680–699). Association for Computational Linguistics. https://doi.org/10.18653/v1/2024.acl-long.40 ↩