Short intro to prompt engineering by examples

The art of asking the AI assistant to get the right answer

Sparisoma Viridi
AIDI.id
8 min readJun 18, 2024

--

https://chatgpt.com/share/c67c65d3-f325-42af-99ff-64783706e1d4

The fact that machines are trained to think, learn, and communicate like humans, is one of the most exciting recent advancements in the realm of AI or artificial intelligence (Crabtree, 2024), where one of the type of AI that can mimic human intelligence is LLMs or large language models, that use statistical models to analyze vast amounts of data, learning the patterns and connections between words and phrases (Priest, 2024). LLM-based applications are able to perform numerous tasks including writing essays, creating poetry, coding, and even engaging in general conversation, where Probably the most famous example of a large language model to date is OpenAI’s GPT-4, which powers ChatGPT (Haritonova, 2024).

Unfortunately, most users still struggled to understand how the prompt’s text related to the LLM’s responses and often followed the LLM’s suggestions verbatim, even if they were incorrect, which resulted in difficulties when using the LLM’s advice for software tasks, leading to low task completion rates (Khurana et al., 2024). Then, the ability to effectively prompt LLMs has become an invaluable skill (Bsharat et al., 2024). The process of carefully crafting prompts or instructions with precise verbs and vocabulary to improve machine-generated outputs in the way that are reproducible is known as prompt engineering, where you might once have done it when you have refined a prompt while asking ChatGPT (Grant, 2024) or other AI assistant. Balancing precision and creativity are required in effective prompt engineering, since a well-crafted prompt can coax out insightful, coherent, and entertaining content from the AI model, while poorly crafted prompts can produce unpredictable, inaccurate, or harmful responses (Schmitt, 2024).

In this story some examples of using LLMs are given as an introduction to prompt engineer.

Access ChatGPT

If you are already familiar with ChatGPT and know how to access it, you may skip this part.

Visit https://chatgpt.com/ to begin interact with one of the famous LLM.

You can sign up or continue with Google.

Let us choose continue with Google by assuming that most of us at least have Google account.

Now, you are in. Perhaps some steps are required, e.g. authentication process with other device. Just follow the suggested steps.

On the right there history of your previous conversation with ChatGPT. If it is your first time to log in, the list should be empty. You can start to ask question to ChatGPT.

Just ask anything

Since topic of this story related to prompt engineering, let us try to ask what what prompt engineering is.

Try to have more broaden meaning relating to other engineering.

Or even narrow the scope to what is yours.

Now you can get any answers you want by customizing the questions.

Provide sufficient elements

In order to instruct AI models to provide coherent and contextually relevant responses in diverse applications, provide sufficient elements of prompt engineering, so that the models can efficiently convey the task or query, which the main elements are (Jacob, 2024)

  • Role
    A role denotes the position where the prompt assumes an individual, which helps the AI create a response relevant to that persona.
  • Task
    Task refers to a clear outline of what specific action or response the AI is expected to generate.
  • Question
    A question is a way of asking the AI to offer more information or provide answers in a particular area, keeping in mind its focus and restricting its feedback.
  • Context
    Further contextual information helps adapt the AI-generated response to the relevant scenario, enhancing the material’s relevance and accuracy.
  • Example
    Adding examples to the prompts is an effective learning strategy, which further attracts the AI’s attention and sets clear expectations for the type of information required.

Let us now use one and later some of the elements together.

Use only the question element first, e.g. How to repair a malfunctioned rice cooker? The result is as follow.

It gives Basic Troubleshooting, Deeper Troubleshooting, Reassembly and Testing, Professional Repair, and Preventive Maintenance.

Let add role element, e.g. as a ordinary person without electronics and electrical knowledge.

Now it gives Basic Troubleshooting Steps, Common Issues and Simple Fixes, When to Seek Professional Help, and Preventive Maintenance. There are not any Deeper Troubleshooting, Reassembly and Testing parts as in previous answer. Those to parts are not for the given role.

Let us now add context element the the question, e.g. Phillips HD415/85 as the type of rice cooker.

It gives basically the same as previous answer, but with additional information Additional Tips part suggesting to refer the the manual of Philips HD415/85 model or contact customer service.

Now add example element, e.g. the error information is E4.

It gives addition parts, which are Dealing with E4 Error and If the Error Persists, but have not yet given any specific clue about the error.

Finally add the task element, e.g. Please give the source of error and steps to fix it in only two paragraphs.

Now we get the brief and concise answer that E4 error message for Phillips HD415/85 rice cooker is related to temperature sensor or overheating protection mechanism.

Let us change the role element a little bit, e.g. I have a few knowledge about electronics and can solder components and wires.

It now does give a beneficial information to fix it, which is similar as in a technical article (Danil, 2024). I have actually performed the reparation but not using the article but with help from some circulated YouTube videos.

OOT: That activity might be later presented in a story :-).

Best practices

There are specific best practices that have proven to be effective in the field of prompt engineering (Dieruf, 2023)

  • Be Clear and Specific
    Do not leave room for misinterpretation, give a clear and specific prompt will lead to more accurate and useful outputs.
  • Use Context and Examples
    Context provides the background information needed for the AI to understand the prompt more holistically, while examples serve as guides, showing the AI the kind of output you’re expecting.
  • Experiment with Phrasing
    Perform experiment with various ways of wording your prompts can help you discover the most effective way to communicate your request to the AI, leading to better results.
  • Start Simple, Iterate Complexity
    After the AI consistently produces satisfactory responses with simple queries, gradually increase the complexity of your prompts.
  • Control Ambiguity
    Too much ambiguity can lead to inconsistent and unpredictable responses, but some are necessary since they can spark creativity.
  • Combine Multiple Prompts
    For complex tasks using a combination of prompts can be more effective.
  • Document Successful Prompts
    For future prompt engineering activities document every successful prompts, which can later serve as a reference, helping to identify patterns and strategies that work well.

Closing

After reading this story you are able to

  • ask ChatGPT any question,
  • refine the question by adding elements, e.g. role, context, example, and taks,
  • limit the answer length,
  • compare the result with search engine results, and
  • perform further study to enhance your skill in performing prompt engineering.

Unfortunately, for this problem in fixing malfunctioned Phillips HD415/85 rice with E4 error message for a person with components and wires soldering ability, it is easier to dive the information using Google search instead of discuss it with ChatGPT.

The discussion with ChatGPT for this story is available on https://chatgpt.com/share/033156c6-ad90-4cee-8e67-c81d0ccb33fd.

I would like to thank to I Made Wiryana from Universitas Gunadarma for encouraging me to learn AI with the story of his Cooperative and Collaborative Lab and Andrei Ramani from Universitas Jember for discussion about LLMs and opportunity to access the server.

--

--