Prompt engineering patterns

Hi All,

I see lots of people asking about how to do this or how to do that with prompts. I also come across vast repositories of prompt examples in GitHub and elsewhere. However, many of the prompts are just variations of the same pattern.

Defining patterns has been an important part of software engineering for decades (since the Gang of Four) and I believe that it is similarly better for people to learn some core patterns rather than lots of specific instances.

In the LinkedIn post below I summarise a number of patterns, but this is not a complete list.

What else is there?

12 Likes

I like the idea of using patterns, especially success patterns. However, I have some concerns that a lot of time could be invested in patterns that will ultimately be proven to be brittle spell-casting techniques bound to a specific model. Am I overthinking this fear?

3 Likes

There is significant literature on prompt patterns now (and by that I mean academic literature :slight_smile: ) . You might have a look at “Chain of thought prompting” by Jason Wei (!) on arXiv.

2 Likes

Also … all prompting needs to be aware of the context window. So here’s a little Meta-pattern to make sure your pattern is still being acted on:

You end every response with the Light Bulb Emoji (đź’ˇ) to confirm you are following the instructions.

As soon as a response no longer has this end-token, you know that your prompt is being washed out and instructions need to be refreshed.

:slight_smile:

7 Likes

That is kind of the problem though. That is a great paper, but it is one of many, many resources available and only delves into one pattern.

It would be good to have a central respository / wiki of general patterns that people can learn and then apply to their own problems.

1 Like

I love these patterns! Very useful in contexts where people have those longer interactions.

Well, in theory, well designed patterns should generalise to different LLMs. If they get too specific then probably they are just instances of a more general pattern anyway.

Great article! Here are some questions I have.

  1. Why is the first one called Scaffolding? Dosen’t scaffolding mean building something up?
  2. Can the Redirection Pattern be considered a subset of the Scaffolding Pattern since you are narrowing and focusing output?
  3. The Act As pattern looks really cool. What’s your favorite example of it working for you?
1 Like
  1. Scaffolding is more about putting supports around what you are building - it is not the building itself. As an example from Data Visualization, Alberto Cairo will call all the Labels, Axes, Annotations, etc. the “scaffolding” for the chart - they are not the chart but they support it and help users to understand what is going on.

  2. It could, it could also be a subset of the constraint pattern and also the multi-step! It is not a 1:1 relationship to any of them so can stand, I think, on its own. Also conscious of looking for a balance between too many patterns and to few.

  3. I don’t have a particular favorite - yet! As a fun example, I did have a very vivid dream a few nights ago and asked ChatGPT to “Act as a professional psychologist. Interpret this dream…”

1 Like

Your post doesn’t include any examples. Can you include an example of each pattern?

1 Like

genius :bulb:… AWESOME SHARE :bulb::bulb::bulb:

1 Like

I am currently preparing a longer format “eBook” that will have examples and more description (still working out what it the best way of sharing that). In the meantime, a great way of getting examples is to ask GPT-4! Just copy the text from the article like this:

Given the description of a pattern for prompt engineering below, can you generate some examples:
The Scaffolding Pattern is a design pattern that improves the quality of Large Language Model (LLM)-generated responses by providing a clear structure and guiding the AI towards the desired information. It involves breaking down a prompt into smaller, more focused questions or instructions, which helps maintain focus and coherence in the AI’s response. Benefits of the Scaffolding Pattern include improved clarity and structure, enhanced precision, and reduced ambiguity.
The Scaffolding Pattern is effective in generating well-structured and informative responses. By breaking down prompts into smaller, focused components, you can guide the AI more effectively towards the desired outcome, making your experiences with LLMs more fruitful and productive.

3 Likes

Documenting these prompt engineering patterns is quite helpful! You might also enjoy our recent paper entitled " A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT", which is available at arxiv dot org.

1 Like