Prompting and it's Techniques

Instruction Prompting
The model is explicitly instructed to follow a particular guideline or format.
Zero Shot Prompting
When there is no information or example provided to model, rather asking the direct questions.
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "What is the capital of France?"},
]
)
print(response.choices[0].message.content) #The capital of France is Paris.
Few Shot Prompting
When some examples are provided to the model before generating a response. If you give the model a prompt to generate only queries related to a particular subject so, it will not provide any response other than that.
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI()
system_prompt = """
you are a helpful assistant. You need to provide the answers of the user queries based on the examples provided.
You need to give the answers only related to Maths Problems.
You should not give any other information apart from the examples provided.
Here are some examples:
Input: 4+10
Output: 14 which is calculated by adding 4 and 10.
Input: 16*4
Output: 64 which is calculated by multiplying 16 and 4 and you can get the answer by multiplying 4 and 16 as well.
Input: 4-8*2
Output: -12 which is calculated by subtracting 8*2 from 4.
Input: Why the water has no color?
Output: Hey bro, Is it math query?
"""
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": "what is value of 23*2+45-12"} #79 which is calculated by multiplying 23 and 2, then adding 45, and finally subtracting 12.
{"role": "user", "content": "what is computer?"} #Hey bro, Is it math query?
]
)
print(response.choices[0].message.content)
Chain of Thought Prompting
When there are several steps provided in prompt so that How model need to break down the reasoning before reaching out to any result.
Example: User provides the input query so, model analyze the input, think several times before providing a response, validate the output, and then provide the result to the user. So, here through system prompt we’re putting a model into the situation of thinking like human, model will think, validate, and then provides the correct result to the user.
Self Consistency Prompting
When the model generates several responses of user query, and to provide the final result, it selects the most consistent or common answer.
Direct Answer Prompting
When the model is instructed to give a clear, concise response without providing any explanation.
Persona based Prompting
When the model is asked to give responses as if it is a particular character or professional.
Example: If I give the system prompt related to info about a person, personality traits, Communication style and Knowledge areas to the model so, the model will have the response as you’re talking to that person.
Role Playing Prompting
Role-playing prompting is when you instruct the model to assume a specific role — like a coder, physician, teacher, or chef — so it interacts and responds from that perspective.
It helps tailor the language, tone, and expertise to match the persona.
Example:
You are an experienced Python developer. A junior dev asks how to use list comprehensions. Explain it simply
Contextual Prompting
Contextual prompting involves including relevant background information in the prompt to help the model generate more accurate, relevant, and useful responses.
It sets the agenda or background so the model better understands your intent.
Example:
My laptop fan sounds like it’s trying to take off. I only opened 10 Chrome tabs. What do I do?
Multimodal Prompting
Multimodal prompting means giving the model multiple types of input — like text + images — to improve understanding and generate richer, more accurate responses.
Great for tasks like image captioning, visual Q&A, or combining context with visuals.
Example:
Image: User uploads a picture of a cat wearing sunglasses and holding a slice of pizza
Text: Describe this cat as a main character in a movie.
Subscribe to my newsletter
Read articles from Shikha Lodhi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
