The Perfect Prompt: Cheat Sheet With 100+ Best Practice Examples - PART 2

The Perfect Prompt: Cheat Sheet With 100+ Best Practice Examples - PART 2

If you haven’t read Part 1 of the The Perfect Prompt Cheat Sheet, you can find it here. In this part, we’ll move on to to:

  1. Prompt templates

  2. RAG — Retrieval Augmented Generation

  3. Formatting and Delimiters

  4. the Multi-Prompt Approach / Prompt Decomposition

Prompt Templates

In many cases, your prompts will follow a particular structure, differing only in certain parameters (e.g. time, location, conversation history, etc.) The prompt can therefore be generalised into a prompt template, with variables replacing the parameters:

Prompt Template

The resulting prompt could then look like this:

Prompt Templates

Example Prompt Snippets

First, define the prompt template with 1 to n variable(s).

Now replace the variables with the current values in each iteration. In Python this might look like this:

The resulting prompt will have the following form:


RAG — Retrieval Augmented Generation

RAG is arguably the most important technique developed in the field of LLMs in the last two years. It allows LLMs to access your data or documents to answer any question, thereby overcoming limitations such as knowledge cut-off in the pre-training data. By accessing a broader set of data, the model’s is up to date can cover a wide range of topics.

Retrieval Augmented Generation (RAG)

Example Prompt Snippets

A typical RAG prompt template tells the model what to do in the RAG application before specifying the output form, examples and tasks:


Formatting and Delimiters

Since models do not re-read prompt, it is essential that they understand it on the first attempt. Structuring your prompt with hashes, quotation marks and line breaks can make it easier for the model to understand what you are trying to convey.

Formatting and Delimiters

Example Prompt Snippets

You can different sections, e.g. by using headlines:

Put data from outside the prompt in quotation marks:

Quotation marks (single, double, triple) can also be used for user input:


Assemble the Parts

Using all the tools above, here is a real-world example of a (near) perfect prompt.

A Complex Prompt

Start by building the prompt in this order:

  • core instruction

  • examples

  • data

  • output format

  • interaction history

Note also how delimiters provide further structure throughout the prompt.

Example Prompt Snippet


Multi-Prompt Approach / Prompt Decomposition

For more complex problems, one prompt is often not enough. Rather than building a single prompt that includes every little sub-step the model needs to perform, it is easier and more efficient to split the prompt. Typically, you first categorise the input data and then select a specific chain to process the data with models and deterministic functions.

Multi-Prompt Approach

Example Prompt Snippets

Break up a single prompt into several prompts, for example by categorising the task first.

You can then select a follow-up prompt based on the result of the classification, before finally evaluating the answer.


Hopefully, this has given you food for thought. I wish you all the very best in your AI projects and hope that you will be successful in your search for the perfect prompt.

Maximilian

Many thanks to Timon Gemmer, Küppers Rocky, Almudena Pereira Salcedo , Ellen John, T. Cooper for help with the cheat sheet and the story!

To view or add a comment, sign in

Others also viewed

Explore topics