The 5 best techniques for effective prompts

The 5 best techniques for effective prompts

Google unveiled at the start of the year a complete 68 -page guide to write effective prompts for its Gemini family.

Over the months and observations of researchers in artificial intelligence, the art of prompting is refined. To share the latest advances with the greatest number, Google published a complete guide on the best prompt techniques at the start of the year. Written by Lee Boontra, Software Engineer Tech Lead at Google, it is considered an effective prompting bible by many developers. The JDN retains for you the 5 most effective and/or innovative tips to improve your prompts. Note that the advice applies as much to the models of the Deepmind family (GEMINI therefore) as to other LLM.

1. Configure these three inference variables well

These are the most important variables to control creativity, hallucinations or the precision of an LLM. The variable Max Tokens Allows you to control the maximum number of tokens generated by an LLM. A reduced value adapted to your use cases makes it possible to limit costs and reduce response time. But according to Google, a value calibrated in adequacy with the expected output of the model makes it possible to limit the appearance of parasitic text at the end of the release. (“In conclusion, we can say that …”). For example for a configuration in classification mode a value less than 10 tokens depending on the case of use is a good practice.

There temperaturefor its part, makes it possible to control the determinism of the response generated by the model. Clearly, a temperature close to 0 will tend to generate factual or even expected responses (perfect for the use of an LLM on binary issues such as mathematical operations for example). A high value (greater than 1) makes it possible to obtain much more creative results (ideal for the generation of a fictitious history for example). Hallucination is also possibly increased tenfold.

Unlike the temperature which overall controls the random character, Top-k and Top-P act more precisely on the selection of words. TOP-K limits the choice to the most likely K Words (for example, TOP-3 means to choose from the 3 words most likely to be generated), while TOP-P dynamically selects words whose cumulative probability does not exceed a given threshold (for example, TOP-0.9 means to take the words that represent together 90% of the total probability). For specific tasks requiring rigor (analysis, data extraction), use low values: top-k around 10 and top-P around 0.5. For creative tasks (writing, content generation), increase the values: top-k around 50 and top-P close to 0.95 or 1.

2. Use the Few-Shot Prompting

It is the simplest alternative to fine-tuning. The Few-Shot prompting makes it possible to guide the model to understand the expected exit from examples. It is therefore advisable to provide at least an expected exit example (One-Shot). Several examples (Few-shot therefore) will however give a better understanding of the model with potentially more reliable results. Google recommends giving between three and five examples of outings. The examples must be original, diversified and written without fault. Only one error can confuse the model.

Example of a good few-shot prompt with 2-shot:

"Parse a customer's pizza order into valid JSON:


EXAMPLE:

I want a small pizza with cheese, tomato sauce, and pepperoni.

JSON Response:

{

"size": "small",

"type": "normal",

"ingredients": (("cheese", "tomato sauce", "peperoni"))

}


EXAMPLE:


Can I get a large pizza with tomato sauce, basil and mozzarella

{

"size": "large",

"type": "normal",

"ingredients": (("tomato sauce", "bazel", "mozzarella"))

}

Now, I would like a large pizza, with the first half cheese and

mozzarella. And the other tomato sauce, ham and pineapple.

JSON Response:"

3. Use Step-back promiting

More flexible than the Chain-of-Thought, the Step-back promiting allows the model to reason better to solve a complex problem. Concretely, the approach consists in asking the model at first the approach he would adopt to solve the problem. And secondly to solve the problem using the approach envisaged in the first outing. Starting with a higher level of abstraction, the model can activate wider basic knowledge, identify fundamental principles and develop a deeper understanding of the context.

Example to solve a mathematical problem.

Prompt 1: ‘What approach should it be mobilized to solve the following problem? “

Prompt 2: “From the above approach, solve the following mathematical problem.”

The technique requires two calls to the model but makes it possible to solve much more complex problems than with a single prompt. The technique is notably recommended for simple and not optimized LLM for reasoning (Llama 4, GPT-4O, Phi, Mistral 7B, etc.).

4. Repeat yourself with the self-consistancy

Here again, the self-consistancy requires several laps to operate and a higher final cost. It can be used to solve problems with great complexity. The fairly simple process consists in submitting the same prompt to the LLM several times, using a high temperature adjustment to encourage the generation of various reasoning paths and perspectives on the problem. Then, the answer is extracted from each result generated, and the most frequent response is selected as being the most consistent and therefore the most correct statistically. The technique makes it possible to drastically reduce the risk of hallucinations and to increase the level of battery on complex tasks.

For example, the model can be asked to classify the content of a telephone transcription to detect the dominant feeling.

Prompt 1: “Here is the content of a telephone discussion below. This conversation is rather positive or negative? Reply only and only” positive “or” Negative “.”

We repeat the prompt 3 times with a temperature of 1.5. Then, a majority vote is made among these different classifications. The answer that appears most frequently in all generations is considered to be the most self-consistent response and therefore the most likely to be correct.

Final prompt: “What is the dominant answer? Returns only and only the answer that comes up most often. Answer: answer1, response2, response3”

5. Test with the automatic prompt engineering or ape

Automatic prompt is one of the many techniques to automate the creation of a simple but effective prompt. The principle is simple: from a reference prompt, the model is asked to generate a dozen variants capable of performing the same task. Each of these prompts is then tested individually, and the responses generated are compared to one or more reference human responses. Each response is automatically evaluated using standardized metrics such as blue (lexical precision) and red (information recall). The prompt whose output obtains the scores closest to the human reference is selected as the most efficient.

Bonus: Use a spreadsheet

It is certainly one of the best advice and one of the simplest. To learn and understand the functioning of the prompt engineering, Lee Boontra recommends using a spreadsheet to list the prompt and their efficiency. The specialist recommends list the name of the prompt, the displayed objective, the temperature used, the top-k, the top-p, the tokens limit, the prompt, the output and finally a simple evaluation of the results (“OK outlet, not ok, sometimes ok, for example).

Example :

Prompt name

Target

Temperature

Top-k

Top-P

Tokens limit

Prompt used

Output

Assessment

Summary of article

Summarize an article of 1000 words

0.7

50

0.9

500

Summarizes this article concisely …

The article explains that …

OK OK

The use of the spreadsheet thus makes it possible to follow the impact of changes in your prompt on the output and to learn at the same time.

Jake Thompson
Jake Thompson
Growing up in Seattle, I've always been intrigued by the ever-evolving digital landscape and its impacts on our world. With a background in computer science and business from MIT, I've spent the last decade working with tech companies and writing about technological advancements. I'm passionate about uncovering how innovation and digitalization are reshaping industries, and I feel privileged to share these insights through MeshedSociety.com.

Leave a Comment