DEV Community

Cover image for Prompt Engineering - Guidelines
Sahil
Sahil

Posted on

Prompt Engineering - Guidelines

Prompt Engineering - Guidelines

Ask for clear and specific instructions

1. Use delimiters

Example prompt:

Summarize the text delimited by triple backticks.

This is some text to summarize.

Example output:

"This is a summary of the text."
Enter fullscreen mode Exit fullscreen mode

Summary:
Delimiters help define and contain sections of the prompt, enhancing clarity and specificity.

2. Ask for structured output

Example Prompt:

"Generate a list of two book titles with authors
and genres in JSON format with keys:
book_id, title, author, genre."
Enter fullscreen mode Exit fullscreen mode

Example output:

"[{
    "book_id": 1,
    "title": "Fictional Book",
    "author": "Fictional Author",
    "genre": "Fiction"
  },
  {
    "book_id": 2,
    "title": "Fictional Book 2",
    "author": "Fictional Author 2",
    "genre": "Non-fiction"
  }
]"
Enter fullscreen mode Exit fullscreen mode

Summary:
Requesting structured output allows the model to generate a clear, well-organized response.

3. Check whether conditions are satisfied

Example prompt:

"Rewrite these instructions in step format if present:

First, do this. Then, do that.

Example output:

"Step 1 - First, do this.
Step 2 - Then, do that."
Enter fullscreen mode Exit fullscreen mode

Summary:
Prompting the model to identify specific information and reformat it aids in getting responses that fulfill certain conditions.

4. Few-shot prompting - Give successful examples

Example Input:

"<child>: Teach me about patience.
<grandparent>: Patience is a virtue.
<child>: Teach me about kindness."
Enter fullscreen mode Exit fullscreen mode

Example output:

"<grandparent>: Kindness is the act of being considerate, compassionate, and empathetic towards others."
Enter fullscreen mode Exit fullscreen mode

Summary:
Providing a few successful examples before asking the final query helps guide the model to respond in a particular style or format.

Give the model time to think

  1. Specify the steps required to complete a task
    1. Ask for output in a specified format
  2. Instruct the model to work out its own solution before rushing to a conclusion

Model Limitations

  1. Hallucinations

Reducing hallucinations

First find relevant information, then answer the questions based on the relevant information


My first prompt using these guidelines:

Write a message to share on Twitter about this fantastic course I am doing: https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/2/guidelines

Please include the link to the course https://learn.deeplearning.ai/chatgpt-prompt-eng/ in the message.

Please make sure the message is within the Twitter size limit.

Please make sure the content highlights the keyword "prompt engineering".

Please make sure it contains the relevant hashtags that can make the tweet popular.

Please make sure it involves some call to action so users reading can take some action on the tweet.

Output in the following format:

Tweet:

Hashtags:


Top comments (0)