Some key rules for AI prompt engineering I’ve learned through experience
Prompting is an important part of any AI implementation, especially RAG AI. The difference between good prompts and okay prompts can determine whether your project succeeds or fails. For advanced RAG AI implementations such as GraphRAG, prompts are even more crucial as there are more of them, and a problem in any step of the chain can be fatal.
Automation of Prompt Evaluation is Key
Above all, remember that there is no magic bullet for prompts and what works today might break tomorrow. The key is to automate the evaluation of a prompt as much as possible. My preferred method is to take the query and outputs, feed them into a separate LLM, and ask it to evaluate whether the output is properly answering the query. You can quickly pull together a test set of 10 or 100 queries, automate this test, and check the results. This test is best run daily if you are using a Software as a Service (SaaS) model as model behavior can change more often than expected.
In addition to ensuring the prompt is still performing, once you have automation set up, you can try different approaches with your prompt and have an objective measure of their effectiveness. I can’t stress enough how important this piece is.
General Prompting Advice
The “best” prompt varies extensively based on the data being used and the desired results. Here is some general advice:
If you have specific output needs, provide examples.
- Usually, two or three examples is best. This is called a “few shot” prompt.
- Make it clear to the model that these are examples.
- Examples are best when close to the subject matter. For instance, while dealing with a project about makeup, I once kept an example from a prompt from a project I did involving MDMA therapy for PTSD sufferers because the output format was the same. Queries about makeup started randomly mentioning MDMA! Even when you tell the model something is just about the formatting, it still can contaminate the results.
- Some people use 10 or even 20 examples. In testing, this can work well, but one limited resource in AI is Max Tokens, and having 10 or more examples often uses up too many tokens better used for other things. It also increases costs.
Less is more. You want to maximize signal to noise, but of your query more is noise than you think.
- Max tokens is a big issue in prompting. In most state-of-the-art models, there are limits of 8,192 tokens, meaning that the total input and output can’t be more than 8,192 tokens. This is separate from Context Window, which are often much larger on models. So, every example used makes for less space available for output. Also, these models charge by the token, so each additional example might add 1% to your costs.
- Avoid filler words such as “please” or “I would like to.” These are only noise.
- “Do’s” are much more effective than “Don’ts.” Try to rework any negatives as positives. For instance, one AI was insisting on putting footnotes to videos at the bottom instead of adding them inline. I repeated over and over in the prompt not to do that, but it continued. When I got rid of all those “don’ts,” it started to work fine based on the examples.
- When prompts aren’t giving you what you want, there’s the temptation to add to the prompt. This is worth a try, but if the prompt gets lengthy, try radically simplifying the prompt. I spent days trying to have an AI give me good tags from extracted websites and videos using examples and complex rules. The prompt that ultimately gave the best results for my use case was: “Please pull out up to 7 one or two-word tags to describe this content. Provide each tag on a new line.”
Clearly separate different parts of the prompt.
- If I have examples, I will add two lines. The first a demarcation “————” and the second a line saying “Example:”. After the example, I will also put a demarcation “———“. These separations help keep the prompt from getting confused.
Use Chain-of-Thought prompting.
- Chain of Thought prompting is when you guide the prompt through the steps in your example. For instance, in math, saying “—–Example: What is 2+2? -> Step 1: start with 2. -> Step 2: add two more -> step 3: four apples.”
- This applies more towards any reasoning and hasn’t been as useful in RAG AI implementations. But when I have steps I need the LLM to take, it is awesome.
Things I Advise Against Using (Most of the Time)
Repetition in prompts.
- I’m always tempted to repeat myself in prompts thinking it will make the AI more likely to do what I ask. Experience has shown me that the opposite is true. Asking once is more important.
- Instead of repeating, strengthen your existing phrase. Instead of “show the exact spot in the video” say “you MUST show the exact spot in the video.”
Role-based prompting: This is where you assign a role, like “You are MentorBot…”.
- In RAG AI, my objective evaluations show it is not as effective as simply giving examples.
- In interactive work with Chat-GPT, it can be highly effective if you need the AI to think in multiple ways. For example, giving it two different roles, one as the inventive type and one as the cautious type, having them generate ideas and then comparing them.
Asking the AI to improve the prompt.
- Often, I will take a prompt, put it into the AI, tell it what I want to achieve, and ask it how I can improve the prompt. Without fail, this has been a step backward as the AI-generated prompt does not score as well on objective evaluation measures.
- One big exception to this is if you have large amounts of clear inputs and desired outputs. In that case, you can automate the prompt generation process and have the AI iteratively adjust the prompt for better performance1.
Conclusion
Mastering the art of prompt engineering is crucial for the success of AI, especially RAG AI implementations. By automating prompt evaluation, and avoiding common pitfalls, you can significantly enhance the performance and reliability of your AI models. Always be open to iterating and refining your prompts, as continuous improvement is key to adapting to changing model behaviors and achieving optimal results.
Footnote:
- The usual model training issues apply here with possible overfitting based on a defined sample, so best to follow having separate training, validation, and test sets.

Leave a Reply