Key principles of prompt engineering

ChatGPT Prompt Engineering for Developers

Fouad Trad

Machine Learning Engineer

Clear and precise prompts

A visual diagram showing a bakery and a house with two possible routes between them. One if simple and short (effective), and the other is complicated and long (ineffective).

ChatGPT Prompt Engineering for Developers

Key principles

 

  • 🎬 Appropriate action verbs
  • 💬 Detailed and precise instructions
  • ❗ Well-structured delimited prompts
ChatGPT Prompt Engineering for Developers

Using action verbs

  • Guide model what to do

Table for the verbs to use including write, complete, explain, describe, or evaluate.

ChatGPT Prompt Engineering for Developers

Avoid ambiguous verbs

  • Confuse model's understanding

Table for the verbs to use including write, complete, explain, describe, or evaluate, and the verbs to avoid using such as understand, think, feel, try, and know.

ChatGPT Prompt Engineering for Developers

Effective prompt with verbs

prompt = "Think about the issue of 
deforestation."
response = get_response(prompt)
print(response)
Deforestation is a significant 
environmental issue involving 
permanently removing
or destroying forests and woodlands. 
It has far-reaching impacts on the 
environment, ecosystems, wildlife, 
and human communities. [...]
prompt = "Propose strategies to 
reduce deforestation."
response = get_response(prompt)
print(response)
Reducing deforestation requires 
a comprehensive and multi-dimensional 
approach involving various stakeholders. 
Here are several strategies 
that can help address the issue:
Strengthen Forest Governance
Promote Sustainable Land Use [...]
ChatGPT Prompt Engineering for Developers

Formulating detailed instructions

 

Provide specific, descriptive, and detailed instructions regarding:

  • 📖 Context
  • 📏 Output length
  • 🖌 Format and style
  • 👥👥 Audience
ChatGPT Prompt Engineering for Developers

Effective prompt with instructions

Ineffective prompt: "Tell me about dogs."

Effective prompt

prompt = "Write a descriptive paragraph about the behavior and characteristics of 
Golden Retrievers, highlighting their friendly nature, intelligence, 
and suitability as family pets."
print(get_response(prompt))
Golden Retrievers are beloved worldwide for their exceptional behavior, remarkable 
characteristics, and friendly nature. They are highly intelligent, trainable, and 
adaptable, making them great companions for families, including those with children.
ChatGPT Prompt Engineering for Developers

Limiting output length

max_tokens:

  • Limit on number of tokens
  • Output cannot bypass it
  • Might lead to incomplete or cut responses

Prompt:

  • Limit on words, sentences, or paragraphs
  • Output may bypass it
  • Complete responses
ChatGPT Prompt Engineering for Developers

Prompt components

  • Instructions and input data to operate on
  • Example: text summarization
    • Instruction: summarize the given text
    • Input data: text to summarize

An icon representing the text summarization task

ChatGPT Prompt Engineering for Developers

Crafting a well-structured prompt with delimiters

  • Start prompt with instructions
  • Use delimiters (parentheses, brackets, backticks, etc.) to specify input parts
  • Mention which delimiters are used
prompt = """Summarize the text delimited by triple backticks into bullet points.
           ```TEXT GOES HERE```"""
response = get_response(prompt)
ChatGPT Prompt Engineering for Developers

Using formatted strings (f-strings)

  • Include defined string into another string
text = "This is a sample text to summarize"

prompt = f"""Summarize the text delimited by triple backticks into bullet points. ```{text}```"""
print(prompt)
Summarize the text delimited by triple backticks into bullet points.
```This is a sample text to summarize```
ChatGPT Prompt Engineering for Developers

Let's practice!

ChatGPT Prompt Engineering for Developers

Preparing Video For Download...