HyperScale Blog

Prompting Smartly- Practical Tips for Leveraging the ChatGPT Capabilities

Written by Dr. Angelina Gokhale | Aug 27, 2024 11:12:10 AM

Table of Contents 

  • Introduction 
  • Tips for Leveraging ChatGPT Capabilities 
    • Using Typographical Symbols
    • Using JSON or Other Known Data Types
    • Using Programming Language to Embed Prompts 
    • Providing guidelines for Output Formatting 
    • Using Keywords for Input and Output
    • Using Clear and Precise Instructions 
    • Curating a Large Training Text 

Introduction

As part of my work at DNIF, I have significantly been involved in training ChatGPT to perform some meaningful and engaging tasks. Given my academic background and the teaching pedagogy in classroom discussions that I have followed for over a decade, it was relatively easier for me to quickly get ChatGPT to do what I wanted.  Later, I took up a few courses to learn valuable ways of prompting smartly. 

In this article, I shall help you with some quick tips and tricks you could use in your day-to-day work to get promising results from ChatGPT, enforcing better recall. The tips are a combination of approaches I have referred to and ones from my experience conversing with ChatGPT. I shall introduce each section by explaining the tips using helpful examples.

Tips for Leveraging ChatGPT Capabilities 

 

Prompt Indications 

😐 Unclear verbose prompt   
😀 Effective prompt

Tip 1: Using Typographical Symbols

The use of punctuation symbols, special characters, and brackets help in emphasizing the words you want ChatGPT to analyze.

Example 1: Use the apostrophe to emphasize the “ text ” 

😐 

Prompt = "Help me understand the group by clause in SQL"

 😀

Prompt = """Help me understand the “GROUP BY” clause in MySQL"""

Example 2: Use curly braces to pass multiple {text} to the actual prompt

😐

Prompt = "Give me a SQL query for counting number of failed login attempts on my network

Prompt = "Give me a SQL query for counting number of packets blocked on the network grouped by the destination IP address"

😀

Prompt = """
query1 = "counting number of failed login attempts on my network”
query2 = "counting number of packets blocked on the network grouped by the destination IP address"

Provide an SQL query for {query1} and {query2}
"""
[Note. Enclosing the prompt in three apostrophes """... ..."""  indicates a multi-line prompt]

Example 3: Use triple backticks ```text``` or angular brackets <text> to recall a value

😀

Prompt = """
    keyword = Having Clause
    Explain the syntax for the SQL ```keyword``` with two examples
    """

                               OR

    Prompt = """
    keyword = Having Clause
    Explain the syntax for the SQL <keyword> with two examples
    """

Tip 2: Using JSON or Other known Data Types

Make use of data types from different programming languages that you are already familiar with, namely, dictionaries, lists or file formats like JSON. You can combine these with typographical symbols to describe a complex prompt using fewer tokens.   

Example 1: Use key-value pairs

😐

Prompt = "Given a table users, and column names login_activity (login, logout), username, status (failed, passed), provide an SQL query to count failed login attempts "

😀

Prompt = """
```Users``` <name  of  the  table>
 ```Field  names```:
     "username" : <email_id of the user>
     "login_activity" : [LOGIN/ LOGOUT] 
     "status" : [PASSED/ FAILED] 
 Given  the  description of the table ```Users```, provide an SQL query to count failed login  attempts. Use the ```Field names``` while constructing the query.
"""

Example 2: Use JSON format

😐

Prompt = "Given that organization 1 faced 2 ransomware attacks, organization 2 faced 3 attempts of Brute Force and organization 1 is based in Delhi while org2 is based in Mumbai. Both are branches for the Accounting division. Their client is in Singapore. Client organization faced Denial of Service attempts. Analyze this situation and Provide SQL queries for each organization to track such behavior on the network. How should they protect their network?"

😀

Prompt = """
case : 
{ "organization1": {
"attack": "ransomware",
"location": "Delhi",
"division": "Accounting",
"type": "branch",
},
"organization2": {
"attack": "brute force attempts",
"location": "Mumbai",
"division": "Accounting",
"type": "branch",
},
"organization3": {
    "attack": "denial-of-service",
"location": "Singapore",
"type": "client",
},
}
Analyze the above ```case``` and provide SQL queries for each organization to investigate traces of the respective attacks on its network. Also provide mitigation measures.
[Note: You could use the first verbose prompt to ask ChatGPT to output a formatted JSON object and then use that as a prompt to obtain the desired response]

Tip 3: Using a Programming Language to Embed Prompts

Knowing a programming language comes in handy for making API calls to the OpenAI plugin. By embedding prompts in a script we can dynamically pass values inside a prompt. 

😀 

 Example: Using Python to dynamically pass values to the prompt

import pandas as pd

scenario = pd.read_csv( "scenario.csv" )

for i in range (len(scenario)):
        organization = scenario['Org'][i]
        attack_history = scenario['Attacks'][i]

      prompt = f"""Based on the {organization} and {attack_history} provide mitigation measures"""

Tip 4: Providing guidelines for Output Formatting

You can provide a style or template to guide ChatGPT’s response format. Use typographical symbols to design the output template. 

Example: You can edit the previous prompt to format the output

😀

prompt = f"""Based on the {organization} and {attack_history} provide mitigation measures. Respond as follows:
==========================================================
Organization name: <name of the organization>
Attack summary: <summarize the attack in a sentence>
Mitigation measures: <list top 3 mitigation measures>
==========================================================
"""

Tip 5: Using keywords for Input and Output

Use words like “Remember”, “Recall”, “Think”, “Analyze” where you want ChatGPT to spend time comprehending and analyzing the prompt. Use words like “Output”, “Respond” when you expect ChatGPT to respond in a said manner.

😀

 Example: Using the keyword “Analyze” and “Respond” in the previous prompt

prompt = f"""Analyze the ```organization```: {organization} , ```attacks```: {attack_history} and provide mitigation measures. 

Respond as follows:
==========================================================
Organization name: <name of the organization>
Attack summary: <summarize the attack in a sentence>
Mitigation measures: <list top 3 mitigation measures>
==========================================================
"""

Tip 6: Using Clear and  Precise Instructions

While prompting ChatGPT, it is recommended to be clear with your instructions. It is okay to end up with spelling mistakes but “not okay” if you cannot specify what you want. Let your prompts be meaningful conversations with a logical flow that helps ChatGPT understand your expectations. 

Tip 7: Curating a Large Training Text

If you wish to create a large training text for training ChatGPT, always ensure to chunk and test your prompts to know which ones work effectively. Combine all those prompts in a logical manner to compile your training text.

In summary, using these tips increases your chances of obtaining the desired responses in fewer prompts. Exploring libraries like LangChain can help you provide structured responses and define reusable prompt templates that can integrate with your back-end application code.

Acknowledgements:
I wish to acknowledge the team at DeepLearning.AI especially Prof. Andrew Ng, Isa Fulford, and Harrison Chase for the insightful sessions on Prompt Engineering.