🧠 Advanced

🟢 Parts of a Prompt

Last updated on August 7, 2024 by Sander Schulhoff

Takeaways
  • Understand the basic parts of a prompt
  • Understand how to order these parts

What are the Parts of a Prompt?

Recall that a prompt is just an input to a Generative AI model, that is used to guide its output. There are many ways of creating a prompt and we have just covered a few such ways, including Few-Shot Prompting and Role Prompting. On this page, we will provide you with the elements of a prompt that consistently appear across all prompting techniques. We draw this information from The Prompt Report, the most comprehensive survey on prompting ever written. It is important to know these components of a prompt so that you can effectively swap them in and out and know how to diagnose issues with your prompt.

Parts of a Prompt

There are a few different parts of a prompt that you will see over and over again. They are the following:

  • The Directive
  • Examples
  • A Role
  • Output Formatting
  • Additional Information

We have covered roles and examples in previous lessons. However, we have not discussed the Directive, Output Formatting, or Additional Information.

The Directive

The Directive is the core intent of the prompt, sometimes simply called the "intent". This will often just be the main instruction or question in the prompt.

For example, here a prompt with a single instruction:

Astronaut

Prompt


Tell me five good books to read.

Directives can also be implicit, as in this one-shot case, where the directive is to perform English to Spanish translation:

Astronaut

Prompt


Night: Noche Morning:

Output Formatting

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:

Astronaut

Prompt


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.
Robot

AI Output


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

Style Instructions

Style instructions are a type of output formatting used to modify the output stylistically rather than structurally. For example:

Astronaut

Prompt


Write a clear and curt paragraph about llamas.

Additional Information

It is often necessary to include additional information in the prompt. For example, if the directive is to write an email, you might include information such as your name and position so the GenAI can properly sign the email. Additional Information is sometimes called ‘context‘, though we discourage the use of this term as it is overloaded with other meanings in the prompting space.

How to Order Parts of the Prompt

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.

Astronaut

Prompt


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.
Astronaut

Prompt


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 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.

Here is our recommended order of parts for prompts:

Astronaut

Prompt


Examples

Additional Information (sometimes called context)

Role, Directive, Output Formatting

Conclusion

Understanding the structure and components of a prompt is crucial in effectively utilizing language models. The key parts of a prompt include The Directive, Examples, A Role, Output Formatting, and Additional Information. Not all prompts will contain all these elements, and their order can vary. However, it's generally preferable to place the directive after any additional information/context to ensure that the model focuses on executing the directive rather than extending the additional information. As the field of prompt engineering continues to evolve, these principles provide a solid foundation for crafting effective prompts.

FAQ

Why is it important to formalize the language we use to discuss prompting?

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.

What are the key parts of a prompt?

Some key parts of a prompt discussed in this article are The Directive, Examples, A Role, Output Formatting, and Additional Information

How do you order the parts of a prompt?

You should put the examples first, then additional information, then the role, directive, and output formatting.

Footnotes

  1. 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. 2 3

  2. You may notice that some text is copied verbatim from The Prompt Report. This content was written by Sander Schulhoff (the author of this page).

  3. Searle, J. R. (1969). Speech acts: An essay in the philosophy of language. Cambridge University.

  4. 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

  5. e.g. the context is the tokens processed by the LLM in a forward pass

Edit this page
Word count: 0

Get AI Certified by Learn Prompting


Copyright © 2024 Learn Prompting.