Iterative Prompt Development: Iteratively analyse and refine your prompts
Tags: chatgpt, ai, beginners, prompts
Published: 2023-05-21 13:07:43



Note: This is a documented version of ChatGPT Prompt Engineering for Developers course. You can find the course [here](https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/1/introduction).

Note: This article is pretty boring. I have added a general summary here for all those who don't have time to read this. 

In this article, we will see how to iteratively analyse and refine prompts to generate marketing copy from a product fact sheet. We will start with a simple prompt that generated a long, rambling text. We then iteratively will refine the prompt to limit the number of words, focus on the relevant details, and include the product IDs. Finally, we will add a table of dimensions. By following this iterative approach, we will be able to generate a concise and polished output that meets the needs of the marketing team. This is based on the example that is mentioned in the course.


Note: Before reading this please try to read two another articles which is part of this course. It will give you a general guidelines on how to interact with LLM in a better way.


- [Writing Effective Prompts for Large Language Models: Two Prompting Principles and Their Related Tactics.](https://dev.to/shanshaji/writing-effective-prompts-for-large-language-models-two-prompting-principles-and-their-related-tactics-151a)
- [Principle 2 of Writing Effective Prompts for Large Language Models: Give Them Time to Think](https://dev.to/shanshaji/principle-2-of-writing-effective-prompts-for-large-language-models-give-them-time-to-think-25j3)


Note: In this Article, you'll learn how to iteratively analyse and refine prompts. 


**We will iteratively analyse and refine our prompts to generate marketing copy from a product fact sheet.**

```
fact_sheet_chair = """
OVERVIEW
- Part of a beautiful family of mid-century inspired office furniture, 
including filing cabinets, desks, bookcases, meeting tables, and more.
- Several options of shell color and base finishes.
- Available with plastic back and front upholstery (SWC-100) 
or full upholstery (SWC-110) in 10 fabric and 6 leather options.
- Base finish options are: stainless steel, matte black, 
gloss white, or chrome.
- Chair is available with or without armrests.
- Suitable for home or business settings.
- Qualified for contract use.

CONSTRUCTION
- 5-wheel plastic coated aluminum base.
- Pneumatic chair adjust for easy raise/lower action.

DIMENSIONS
- WIDTH 53 CM | 20.87”
- DEPTH 51 CM | 20.08”
- HEIGHT 80 CM | 31.50”
- SEAT HEIGHT 44 CM | 17.32”
- SEAT DEPTH 41 CM | 16.14”

OPTIONS
- Soft or hard-floor caster options.
- Two choices of seat foam densities: 
 medium (1.8 lb/ft3) or high (2.8 lb/ft3)
- Armless or 8 position PU armrests 

MATERIALS
SHELL BASE GLIDER
- Cast Aluminum with modified nylon PA6/PA66 coating.
- Shell thickness: 10 mm.
SEAT
- HD36 foam

COUNTRY OF ORIGIN
- Italy
"""

Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

Technical specifications: ---{fact_sheet_chair}---
```

As the prompt is bit big. When I unleashed this on GPT-3, it erupted with a whopping 369 words!😁. I won't be sharing the output here as it's a long text. To limit the number of words to certain limit we can tell GPT to generate at most x amount of words.

The new prompt will be:

```
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

Use at most 50 words.

Technical specifications: ---{fact_sheet_chair}---
```

In this prompt we are mentioning the number of words to GPT to limit the output.

Issue 2 of the generated output:  Text focuses on the wrong details.

```

Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.

Use at most 50 words.

Technical specifications: ---{fact_sheet_chair}---

```

Here in this prompt we are asking the model to focus on the aspects that are relevant to the intended audience. Here we need to generate the description for furniture retailers.

Output: 


![Limit Words Generated](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmr80bt78590avh9y1hj.png)

We can further improve this prompt to attach the product ids in the description. The updated prompt will be:

```
"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.

At the end of the description, include every 7-character 
Product ID in the technical specification.

Use at most 50 words.

Technical specifications: ---{fact_sheet_chair}---
"""

```

Output: 

![Output with product id](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kv1yu4ui2z4rwc0rq8w.png)

Issue 3 - Description needs a table of dimensions

We can ask the model to generate a table for us along with the description. Here we will be generating a table of dimensions.

```
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.

At the end of the description, include every 7-character 
Product ID in the technical specification.

After the description, include a table that gives the 
product's dimensions. The table should have two columns.
In the first column include the name of the dimension. 
In the second column include the measurements in inches only.

Give the table the title 'Product Dimensions'.

Format everything as HTML that can be used in a website. 
Place the description in a <div> element.

Technical specifications: ---{fact_sheet_chair}---
```

Output generated is in HTML. I am not going to add the screenshot here as the output is a bit long. You can copy and paste this prompt to know how the output will look like. 





Here is another example of how the iterative approach can be used to improve the quality of generated outputs. Let's say you want to write a poem about a flower. Your first prompt might be something like this:


```
Write a poem about a flower.
```

This prompt is too general and will likely result in a poem that is not very specific or creative. To improve the prompt, you could add more details about the flower, such as its colour, shape, or smell. You could also specify the tone of the poem, such as whether you want it to be happy, sad, or reflective.

```
Write a happy poem about a red lily.
```

This prompt is more likely to result in a poem that is both specific and creative. Once you have written the poem, you can then evaluate it and see if it meets your needs. If not, you can iterate on the prompt and try again until the desired output is achieved.