ChatGPT to NotionChatGPT to Notion

Prompt Engineering Tips and Best Practices

on 10 days ago

Prompt Engineering Tips and Best Practices

Start Simple

When designing prompts, remember it's an iterative process that requires extensive experimentation to achieve optimal results. Using simple platforms like OpenAI or Cohere is an excellent starting point.You can begin with basic prompts and gradually add more elements and context as you aim for better results. Version controlling your prompts during this process is crucial. As you read this guide, you’ll see many examples where specificity, conciseness, and clarity typically yield better outcomes.When tackling a large task involving multiple subtasks, try breaking it down into simpler subtasks and build up as you achieve better results. This avoids introducing excessive complexity at the start of the prompt design process.

Instructions

You can use commands to instruct the model to perform various simple tasks, such as "write," "classify," "summarize," "translate," "sort," etc., to design effective prompts for different simple tasks.Keep in mind that you still need to conduct extensive experiments to see which approach works best. Try different instructions with varying keywords, contexts, and data to determine what suits your specific use case and task. Generally, the more specific and relevant the context is to the task at hand, the better the results.Others recommend placing instructions at the beginning of the prompt. It’s advisable to use clear delimiters like "###" to separate instructions from context.For example:

plaintext

`### Instructions ###
Translate the following text into Spanish:

Text: "hello!"`

Output:

plaintext

¡Hola!

Specificity

Be extremely specific about the instructions and tasks you want the model to perform. The more specific and detailed the prompt, the better the results—especially when you have expected outcomes or a desired generation style. There’s no specific token or keyword that guarantees better results; what matters more is having a well-formatted and descriptive prompt. In fact, providing examples in the prompt is highly effective for obtaining output in a specific format.When designing prompts, also consider their length, as there are limits. You need to balance how specific and detailed to be. Including too many unnecessary details isn’t necessarily helpful; details should be relevant and aid in completing the task. This is something you’ll need to experiment with extensively. We encourage lots of experimentation and iteration to optimize prompts for your application.For example, let’s try a simple prompt to extract specific information from text:

plaintext

`Extract place names from the following text.

Desired format:
Locations:

Input: "While these developments are encouraging for researchers, many mysteries remain. Neuroimmunologist Henrique Veiga-Fernandes at Lisbon's unknown Champalimaud Center says: 'We often have a black box between the brain and the effects we see around us.' 'If we want to use this in a therapeutic context, we actually need to understand the mechanisms.'"`

Output:

plaintext

Locations: Lisbon, Champalimaud Center

Avoid Vagueness

In prompts that prioritize detail and formatting, it’s easy to fall into the trap of trying to be overly "clever," which can create vague descriptions. It’s usually best to be specific and direct. This is analogous to effective communication—the more direct, the more effective the message.For example, suppose you want to understand the concept of prompt engineering. You might try:

plaintext

Explain the concept of prompt engineering. Keep the explanation brief, just a few sentences, and not too descriptive.

The above prompt is unclear about the exact number of sentences or style. You might still get a good response, but a better prompt is specific, concise, and direct, such as:

plaintext

Explain the concept of prompt engineering in 2–3 sentences for high school students.

Focus on What to Do, Not What to Avoid

Another common tip in prompt design is to avoid saying "what not to do" and instead focus on "what to do." This encourages specificity and emphasizes details that lead the model to generate good responses.Here’s an example with a movie recommendation chatbot, where my initial instructions (focusing on what to avoid) failed:Original Prompt (Failed Case):

plaintext

`Here’s a agent for recommending movies to customers. Do not ask about interests. Do not ask for personal information.

Customer: Please recommend movies based on my interests.
Agent:`

Output:

plaintext

Of course, I can recommend movies based on your interests. What genre of movies do you like? Do you prefer action, comedy, romance, or other genres?

Improved Prompt (Successful Case):

plaintext

`Here’s a agent for recommending movies to customers. The agent is responsible for recommending movies from global hit lists. It should avoid asking users about their preferences or personal information. If the agent has no movie recommendations, it should respond, "Sorry, no movie recommendations found today."

Customer: Please recommend a movie based on my interests.
Agent:`

Output:

plaintext

Sorry, I don’t have any information about your interests. However, here’s a list of currently trending global movies: [movie list]. Hope you find something you like!

Prompt Engineering Tips and Best Practices