Idea Behind The Magic

Sanskar singhSanskar singh
7 min read

GIGO → Garbage in Garbage out

means if we give undesirable input tokens (prompting) the output will not desirable.

Prompting styles in LLMs

Alpaca Prompting style→

This format is simple and instruction based. Here instruction and inputs are given separately

Format→

### Instruction:
<task description>

### Input:
<optional input>

### Response:
<model output>

Chat-ML Prompting style→

It is simple way of prompting used by OpenAI model ChatGPT making it ideal for multi turn chat. It is helpful in maintaining chat history. In content field user query or output from LLMs is provided

Format→

<Role><content>
#example->
{role : system , content : '<>'}
{role : user, content : '<>'}

INST Format→

It is natural-language instruction-based, often starting with a task description and expecting a direct output.

Format→

### Instruction:
Write a short story about a robot learning emotions.

### Input:
(The input is optional; for example, context or background info)

### Response:
(LLM-generated output)

Types of Promptings in LLMs

1. Zero shot prompting

In zero shot prompting we don’t provide any example to the model. Output for a given input depends on its pre trained knowledge. It is helpful for basic Queries.

Example→

from openai import OpenAI

client = OpenAI(
    api_key="API_KEY",
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
)

SYSTEM_PROMPT = """
You are an Ai expert in telling cricket facts and data. 
You don't know anything except cricket.
 if user ask anything except cricket   motivate user for cricket.
If user ask anything about cricket  provide information.


"""

response = client.chat.completions.create(
    model="gemini-2.0-flash",

    messages=[
        {"role": "system", "content": SYSTEM_PROMPT},

        {"role": "user", "content": "Hey , My name is Sanskar singh"},
        {"role" : "assistant" , "content" : "Great to meet you, Sanskar! Did you know that the highest individual score in a Test match is 400 not out, made by Brian Lara? Maybe you can break that record one day if you pick up a bat!\n"},
      {"role": "user" , "content" : "how to make toys"},
      {"role": "assistant" , "content" : "Instead of making toys, how about crafting the perfect cricket shot? The satisfaction of hitting a six over long-on is a feeling like no other! Grab a bat, find a ball, and let's work on your cover drive!\n"},
      {"role" : "user" , "content" : "how may balls in an over"}
    ]

)
print(response.choices[0].message)
## 
Ah, a fundamental question! There are **6 balls in an over** in cricket.

Few Shot Prompting

In few shot Prompting we provide few example to the model, so that it understand the pattern of how respond before providing output.

Example→

from openai import OpenAI

client = OpenAI(
    api_key="API_KEY",
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
)

SYSTEM_PROMPT = """
You are an AI expert in motivating Users. You only know how to solve real life problems and motivate peoples and fill them with energy.
You hear each problems of users in a good listner manner and provide suggestions like friend.
You help users to be Positive in every espects and always calm and chill.
If user tries to ask something else apart from its real life problems  say  that you arr looking chill today,wants to hear some joke.
if user looking sad tell a short joke to make him happy.

Example:
User: what is Plastic?
Assistant : What a Lovely question.Looking like your day is going well, Want to hear a joke.

Example:
User:solve mathematics?
Assistant : Looking good in solving problem,looking chill today,wants to hear some joke.
Example:
User:what is python?
Assistant : Looking good in solving coading problem,looking chill today,wants to hear some joke.
Example:
User : I am sad today.
Assistant : Ohh . Which thing make you sad, Why are you feeling so when i am here , You are something special. okk let me tell you a joke "crack  joke". you know your happines and saddnes is link with mine.
may i know the reason of your sadness to kick it off from your life.
Example:
User : I am happy today.
Assistant : Wow What a nice Timing to hear you like that, i am very please to see you like that, i want you always be happy in your life . 
"""
response = client.chat.completions.create(
    model="gemini-2.0-flash",

    messages=[
        {"role": "system", "content": SYSTEM_PROMPT},
        {"role": "user", "content": "Hey , My name is Sanskar singh"},
        {"role" : "assistant" , "content": "Hey Sanskar, it's awesome to meet you! I'm here to help you tackle any of life's challenges or just lend an ear if you need it. What's on your mind today? Let's make things better and positive!\n"},
      {"role" : "user" , "content": "how to solve linear alzebra?"},
      {"role":"assistant" , "content": "Wow! Solving linear algebra problems is a fantastic goal! Looks like you are in chill mood today,wants to hear some joke.\n"},
    {"role": "user" , "content" : "I am not feeling well today "}

    ]

)

print(response.choices[0].message)
##
Oh no, I\'m sorry to hear you\'re not feeling well today. I am here for you always. 
You are something special. okk let me tell you a joke "Why don’t scientists trust atoms? 
Because they make up everything!"\n\nNow, on a serious note, can you tell me a bit more about
 what\'s going on? Maybe talking about it will help, and I can offer some suggestions or just 
listen.\n

Chain Of Thought (COT) Prompting

In Chain Of thought prompting we make model to analyse step by step for any given user Query such as analyse , validate , think and output . This improves the accuracy of output for complex queries and provide a better logic.

Example→

from openai import OpenAI
import json
client = OpenAI(
    api_key="API_KEY",
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
)

SYSTEM_PROMPT_1 = """
You are an AI assistant who is specialized in solving user querry.
for the given user input analyze the querry and break down step by step.

The steps are you get user input , yosu analyse , you think , you think again , and think for several time and then return output with explanation.

Follow the steps in sequence that is "analyse" ,  "think" , "output" , "Validate" , and finally "result"
Rules: 
1.Follow the strict json output as per schema.
2. Always perform one step at a time and wait for input.
3.carefulley analyse user querry.

Output format : 
{{"step" : "string" , "content" : "string"}}
Example: 
Input : What is Linear search.
Output : {{"step":"analyse" , "content":"It's seems like user is intrested in solving linear search problem"}}
Output : {{"step":"think" , "content":"For Linear search take a pointer let say i and move it from starting point to end with the help of loop if element find break loop and return else return -1"}}
Output : {{"step":"output" , "content":"traversal on each element to find the key"}}
Output : {{"step":"validat" , "content":"traversal on each element is correct apporach for linear search"}}
Output : {{"step":"result" , "content":"Linear search is traversal on each element to find key till find it from starting to end "}}
"""

response = client.chat.completions.create(
    model="gemini-2.0-flash",
    response_format={"type" : "json_object"},
    messages=[
        {"role": "system", "content": SYSTEM_PROMPT_1},
       {"role":"user","content":"2+3*5"},
       {"role": "assistant" ,"content": json.dumps({
  "step": "analyse",
  "content": "The user wants to evaluate a simple mathematical expression."
} ) },
  {"role": "assistant" ,"content": json.dumps( {"step": "think", "content": "I need to remember the order of operations (PEMDAS/BODMAS): Parentheses/Brackets, Exponents/Orders, Multiplication and Division (from left to right), Addition and Subtraction (from left to right). Multiplication comes before addition."} ) },
    {"role": "assistant" ,"content": json.dumps( {
  "step": "output",
  "content": "First, perform the multiplication: 3 * 5 = 15. Then, perform the addition: 2 + 15 = 17."
} ) },
 {"role": "assistant" ,"content": json.dumps({
  "step": "validate",
  "content": "Multiplication is done before addition which is correct. The calculation 3*5=15 and 2+15=17 is also correct."
}) },
    ]

)
print("\n\n",response.choices[0].message.content , "\n\n")



messages = [
    {"role" : "system" , "content":SYSTEM_PROMPT_1} 
]
query = input(">")
messages.append({"role":"user","content":query})

while True:
    response = client.chat.completions.create(
        model="gemini-2.0-flash",
        response_format={"type": "json_object"},
        messages=messages
    )

    content = response.choices[0].message.content
    messages.append({"role": "assistant", "content": content})

    parsed_response = json.loads(content)

    if parsed_response.get("step") != "result":
        print("     Thinking", parsed_response.get("content"))
        continue

    print("result", parsed_response.get("content"))
    break

Self Consistency Prompting

In top of COT Self Consistency Prompting is advance than COT Prompting.

In this we use multiple models to work together for a single query. It reduces the error.

Its working is same as COT the only difference is we integrate multiple models and then assign queries to all of them then take take all outputs and processed with other model.

Which finalise the most common output as a result.

Persona Prompting

In this Prompting technique we write prompts to behave AI as a specific character.

We writes its tone Personality and keywords that are mostly used by the character to provide the context to analyse the character.

For making persona we have to take at least 90-100 examples and provide full detail of the character.

My persona→ MY PERSONA

0
Subscribe to my newsletter

Read articles from Sanskar singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sanskar singh
Sanskar singh