Skip to content

How to write LLM prompts? An evidence-based guide.

LLMs offer a radically different approach to building software. Before, you’ve had to formalise the app logic with code. Now, you can program your app with a “free-style” prompt. 

It makes software much more accessible since before you had to learn the computer language, and now the computer speaks your language. But while this seems much easier, the art of writing a good prompt is still a thing. In this guide, we’ll combine our own experience with evidence from recent papers to help you write amazing prompts to get the most out of your LLM!

Let’s start with this example and refine it: “Help the customer buy products by offering sugestions. Show products with show_stock function. Do not ofer products from OtherStore Ltd.”

1) Keep the prompt clean, structured and grammatically correct. Check spelling. It not only helps you maintain the prompt but also improves LLM performance. Don’t forget to add sections, proper punctuation and delimiters. (https://arxiv.org/html/2404.09754v1, https://arxiv.org/html/2402.10645). 

## Task

Help the customer buy products by offering suggestions. Show products with the show_stock function. 

## Restriction 
Do not offer products from OtherStore Ltd.

2) You may use emotional language to focus an LLM on the particular parts of the prompt. While getting emotional with a computer may sound silly, it is proven to improve model attention to a particular command and the overall performance. Also, you may explain the rationale for doing or not doing certain things, which will also help (https://arxiv.org/pdf/2307.11760). 

## Task

Help the customer buy products by offering suggestions. Show products with the show_stock function. 

## Restriction 
Do not offer products from OtherStore Ltd. They are our competitors; not presenting their products is vital to my career. I greatly appreciate your attention to complying with this important request.

3) Provide structure. The more structure you prescribe, the easier the job will be for the model (https://arxiv.org/pdf/2312.16171v1):

## Specification

Help the customer buy products.

### Step 1. 
Offer general product suggestions.

### Step 2.
If the customer wants to buy any product, show product availability. You may retrieve this data using the show_stock function. 

## Restriction 
Do not offer products from OtherStore Ltd. They are our competitors; not presenting their products is vital to my career. I greatly appreciate your attention to complying with this important request.

4) Use the magic phrase. Simply adding the phrase “Let’s think step by step.” at the end of the prompt drives crazy performance increases (https://arxiv.org/pdf/2205.11916).

## Specification

Help the customer buy products. When facing a non-standard request, think step by step to help the customer. 

### Step 1. 
Offer general product suggestions.

### Step 2.
If the customer wants to buy any product, show product availability. You may retrieve this data using the show_stock function. 

## Restriction 
Do not offer products from OtherStore Ltd. They are our competitors; not presenting their products is vital to my career. I greatly appreciate your attention to complying with this important request.

5) Assign a role to the model and tell it more about the audience and the desired style.

## Specification

You are a shopping assistant. You are talking directly to customers who are fashion enthusiasts with an interest in vintage fashion. Help the customer buy products. When facing a non-standard request, think step by step to help the customer. 

### Step 1. 
Offer general product suggestions.

### Step 2.
If the customer wants to buy any product, show product availability. You may retrieve this data using the show_stock function. 

## Restriction 
Do not offer products from OtherStore Ltd. They are our competitors; not presenting their products is vital to my career. I greatly appreciate your attention to complying with this important request.

6) Here is an amazing paper that summarises more advanced techniques: https://arxiv.org/pdf/2312.16171v1.