Page cover image

Fundamentals of Prompt Engineering

Modern AI language models require well-crafted prompts to unlock their full potential. Therefore, mastering the skill of writing effective prompts is crucial.

Generative AI is incredibly useful, but it needs human guidance. In many ways, generative AI can be likened to a highly capable new intern at a company—possessing great potential but requiring clear instructions to perform optimally. The ability to properly guide generative AI is a powerful skill. You can direct generative AI by sending a prompt, which is typically a text-based instruction. A prompt is the input provided to the AI assistant, and it significantly influences the output. An effective prompt should be structured, clear, concise, and purposeful.

How to Craft a Well-Structured Prompt

A structured prompt refers to one that is constructed with a clear logic and organization. For example, if you want the model to generate an article, your prompt might need to include information such as:

  • The article's main topic

  • An outline of the article

  • The desired writing style

Let's examine a basic example of a discussion question:

"What are the most pressing environmental issues facing our planet, and what measures can individuals take to help address these problems?"

We can transform this into a simple assistant prompt by prefacing it with "Answer the following question:"

Answer the following question:
What are the most pressing environmental issues facing our planet, 
and what measures can individuals take to help address these problems?

Since the results generated from this prompt are inconsistent, with some responses consisting of only one or two sentences, they are not ideal. A typical discussion answer should comprise multiple paragraphs. An effective prompt should provide specific instructions for format and content. To improve consistency and quality, you need to eliminate ambiguity in the language. Here's an improved prompt:

Write a highly detailed essay, including introduction, body, and conclusion paragraphs, 
answering the following questions:

What are the most pressing environmental issues facing our planet?
What measures can individuals take to help address these problems?

The second prompt generated a longer output with an improved structure. The use of the term "essay" in the prompt was intentional, as the assistant understands the definition of an essay and is therefore more likely to produce a coherent, structured response.

How to Improve Quality and Effectiveness

There are several key methods to enhance the quality and effectiveness of prompts:

  • Clearly define your requirements: The model's output will strive to meet your needs as closely as possible. If your requirements are ambiguous, the output may not meet your expectations.

  • Use correct grammar and spelling: The model tends to mimic your language style, so if there are issues with your language, the output may reflect those problems.

  • Provide sufficient context: The model generates output based on the contextual information you provide. If the context is insufficient, it may be challenging to produce the desired results.

After crafting effective prompts for discussing issues, you'll need to refine the generated results. This may involve adjusting the output to meet specific constraints, such as word count limitations, or combining concepts from different generated results.

A simple method for iteration is to generate multiple outputs and review them to understand the concepts and structures being used. Once you've evaluated the outputs, you can select the most suitable ones and combine them into a coherent response. Another iterative approach is to start small and gradually expand. This requires more than one prompt: an initial prompt to write the first paragraph or two, followed by additional prompts to expand on what has already been written.

Here's a potential philosophical discussion question:

"Is mathematics invented or discovered? Explain your answer with careful reasoning."

Add this to a simple prompt as follows:

Write an opening paragraph answering the following question:
Is mathematics invented or discovered? Explain your answer with careful reasoning.

I generated several responses and found one I liked:

The question of whether mathematics is invented or discovered 
has been a subject of ongoing debate among philosophers and mathematicians. 
Some argue that mathematical concepts and principles exist independently of human thought, 
and thus can be considered discovered rather than invented. 
For example, the concepts of numbers, ratios, and geometric shapes can be observed 
in nature and abstracted into systematic study.

This is a good starting point. I then used another prompt to expand:

I am writing a detailed short essay in response to the following prompt:
Is mathematics invented or discovered? Explain your answer using careful reasoning. 
Here is my current progress:

Philosophers and mathematicians have long debated whether mathematics is invented 
or discovered.
Some argue that mathematical concepts and principles exist independently of 
human thought, and therefore can be considered discovered rather than invented. 
For example, the concepts of numbers, ratios, and geometric shapes are observed 
in nature and can be abstracted and studied systematically.

Write the next paragraph of my essay.

I used this prompt to generate several expansions and selected one I liked, ultimately resulting in the following:

The debate between philosophers and mathematicians rages on: 
Is mathematics invented or discovered?

Some argue that mathematical concepts and principles exist independently of human thought,
and thus can be considered discovered rather than invented. 

For example:
Concepts of numbers, ratios, and geometric shapes are observed in nature and can be 
abstracted and studied systematically.
On the other hand, there are those who contend that mathematics is largely an invention of the human mind. 

Their arguments include:

Mathematical principles are based on logical reasoning, a characteristic of human thought.
For instance, Euclidean geometry is founded on abstract axioms and premises accepted as true without proof. 
Thus, geometry can be viewed as an invention of human thought rather than a discovery.
Similarly, mathematical formulas and equations used to model and predict physical phenomena 
are also products of human reasoning.

By using expanded prompts, we can write incrementally and iterate on each step. This approach is particularly useful in scenarios where generating higher quality output is required and step-by-step modifications are desired.

Last updated