Best practices for prompt engineering apply to both the system message and the prompts you send to the AI agents.1. Put instructions at the beginning of the prompt and use markdown headers or code blocks to separate the instruction and contextLess effective ❌:
Copy
Summarize the text below as a bullet point list of the most important points.{text input here}
Better ✅:
Copy
Summarize the text below as a bullet point list of the most important points.Text: """{text input here}"""
2. Be specific, descriptive and as detailed as possible about the desired context, outcome, length, format, style etcLess effective ❌:
Copy
Write a poem about OpenAI.
Better ✅:
Copy
Write a short inspiring poem about OpenAI, focusing on the recent DALL-E product launch (DALL-E is a text to image ML model) in the style of a {famous poet}
3. Articulate the desired output format through examplesLess effective ❌:
Copy
Extract the entities mentioned in the text below. Extract the following 4 entity types: company names, people names, specific topics and themes.
Better ✅:
Copy
Extract the important entities mentioned in the text below. First extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes.
4. Try using zero-shot and few-shot examplesUse zero-shot for simple tasks and few-shot for more complex ones. If neither work, consider fine-tuning the model.Example of Zero-shot:
Copy
Extract keywords from the below text.
Example of Few-shot:
Copy
Extract keywords from the corresponding texts below.
5. Reduce “fluffy” and imprecise descriptions. Be clear and succinct in your instructions.Less effective ❌:
Copy
The description for this product should be fairly short, a few sentences only, and not too much more.
Better ✅:
Copy
Use a 3 to 5 sentence paragraph to describe this product.
6. Instead of just saying what not to do, say what to do insteadAvoid negative instructions, and provide clear guidance on what actions should be taken.Less effective ❌:
Copy
The following is a conversation between an Agent and a Customer. DO NOT ASK USERNAME OR PASSWORD. DO NOT REPEAT.Customer: I can’t log in to my account.Agent:
Better ✅:
Copy
The following is a conversation between an Agent and a Customer. The agent will attempt to diagnose the problem and suggest a solution, whilst refraining from asking any questions related to PII. Instead of asking for PII, such as username or password, refer the user to the help article www.samplewebsite.com/help/faqCustomer: I can’t log in to my account.Agent:
7. Code Generation Specific - Use “leading words” to nudge the model toward a particular patternLess effective ❌:
Copy
# Write a simple python function that# 1. Ask me for a number in mile# 2. It converts miles to kilometers
In this code example below, adding “import” hints to the model that it should start writing in Python. (Similarly “SELECT” is a good hint for the start of a SQL statement.)Better ✅:
Copy
# Write a simple python function that# 1. Ask me for a number in mile# 2. It converts miles to kilometersimport