How to Write a Good Prompt? —Part I.
One of the most important aspects of communicating with AI systems is writing effective prompts. A prompt is the input that you give to the AI and that the system responds to. Effective prompts increase the accuracy and relevance of the AI, whether it is text generation, image creation, or any other task. In this post, we will describe the importance of different prompting techniques and provide concrete examples, with a special focus on zero-shot and few-shot cases through a concrete (legal related) example.
Prompting is a key element of interacting with AI systems, especially when working with Large Language Models (LLMs). A well-written prompt can significantly increase the accuracy, relevance, and usefulness of AI responses. A prompt is simply the text or instruction given to the AI system to initiate the process of responding. It can be a question, a request, or any text input that helps the AI understand what to do.
Prompt engineering refers to the design process of determining how best to instruct the language model, providing appropriate context and guidance. Put simply: how do we ask the right question or make the correct request? Experience has shown that the more detailed and specific the input we feed in, the better the answer or solution we get in response. This is so true that recently a powerful new trend in prompt engineering has started to take off: writing so-called mega prompts.
A mega prompt is essentially a very detailed and extensive input or instruction given to the AI Language Model to generate a more complex, probably longer, and more detailed response. While beginners often ask simple questions to the AI and ask a new question after each answer, mega prompts formulate requests as a single, comprehensive instruction. This theoretically allows the AI to better understand the context and scope of the task in just one step. For instance, a mega prompt related to a research project might contain detailed information about the topic, including relevant keywords, concepts, and questions, not just a single question. This allows the AI to provide a more comprehensive and detailed answer based on the extended contextual information.
Of course, not everyone is willing or able to type half a novel to get an answer to a question, and often this is not necessary. In many cases, a few well-structured and well-thought-out instructions can be enough to succeed. Experience has shown that giving prompts to LLMs has such an impact on the quality of the output returned that specific techniques have been developed for writing the most effective prompts. Some of these are considered below.
Before we get started, it is important to note that popular LLMs such as Gemini, ChatGPT and Llama all have different architectures and capabilities. Therefore, prompting techniques need to be adapted to these specificities to achieve the most effective results.
Gemini, for example, is a language model designed specifically for business and technical texts. Accordingly, when working with Gemini, it is important that prompts provide detailed background information and context. This allows the model to better understand the context of the task and provide more accurate answers. In addition, step-by-step guidance can also be useful, especially for complex tasks, as it helps the model to guide the solution process in a logical way.
ChatGPT, on the other hand, is a general-purpose language model that is well suited for natural language interaction and creative text writing. Of course, it is important that the prompt is specific and clearly defined so that the AI understands exactly what the task is. Iterative prompting can also be a useful technique, as it gives users the opportunity to refine their answers and get back more detailed information.
Llama is a language model specifically optimized for handling professional texts and technical documentation. For Llama, structured and well-organized prompts are most effective, as they help the model to process tasks in a logical sequence. In addition, the formulation of precise questions is critical, as they ensure that the AI provides specific and relevant answers.
In addition, finding the best solution may depend on the specific model (e.g. GPT-4 or GPT4o), but also on the task. Therefore, it is very important that any attempt to automate a task is always preceded by extensive experimentation. All the techniques described here are only guidelines and are far from guaranteeing perfect results for any task on their own.
The example task on which the next few techniques will be presented will be an imaginary situation where the goal is a general summary of a legal document. The GPT-4o model was used as a basis for the design of the example prompts.
Expert Prompting
Role assignment in prompt engineering is a technique in which a prompt is formulated based on a specific role or context. Expert prompting puts the AI in a specific perspective, which helps it to better understand the task and provide more relevant answers. For example, if we position AI as a legal expert, its answers will be more detailed and professionally accurate in the legal context. This is useful in several ways:
- Understanding the context: AI responds more accurately and relevantly when it knows the context and the role in which it needs to operate.
- Specific responses: role assignment allows the model’s responses to be more specific and task-appropriate.
- Improved communication: helps ensure that the model’s responses reflect a specific professional language and style, thus increasing the effectiveness of communication.
A very basic prompt for the task could look like the following:
“Summarize the legal text below, taking care not to change the normative content. The summary should be concise and technically correct.”
In contrast, an expert prompt extended with role assignment could be as follows:
“The following legal text should be summarized. You are the legal adviser, and your task is to produce a concise and professionally correct summary that preserves the normative content. The summary should be concise and professionally correct, considering legal terminology and context. It is essential that the information in the summary clearly reflects the legal obligations and provisions of the original text. Please use the following structure: introduction, summary of main points, and conclusion. Make sure that the summary accurately reflects all relevant legal provisions, obligations and requirements. Use legal jargon but aim to make the text clear and understandable. Where relevant, highlight any legal consequences and any deadlines or legal effects in the text.”
István ÜVEGES is a researcher in Computer Linguistics at MONTANA Knowledge Management Ltd. and a researcher at the HUN-REN Centre for Social Sciences, Political and Legal Text Mining and Artificial Intelligence Laboratory (poltextLAB). His main interests include practical applications of Automation, Artificial Intelligence (Machine Learning), Legal Language (legalese) studies and the Plain Language Movement.