Skip to main content

Command Palette

Search for a command to run...

What is AI Prompting?

Updated
9 min read
What is AI Prompting?
A

Hello👋, I'm Ashraful Malik, a web developer and web designer. I create websites that not only look great but also function smoothly.

Promoting is a way to make AI behave in a particular way or ways you want it to behave or act. With the help of prompting, you can make your own personal assistant specialise in an individual task.

Prompting Formats

There are many prompting formats available, such as:

  • Alpaca format

  • Instruction format

  • FLAN-T5 format

  • ChatML format

You don’t need to learn all of them you just need one: ChatML format.
This is the most famous and widely used format, adopted by most LLMs out there such as Gemini, Claude, ChatGPT, etc.

ChatML Prompting Format Syntax

message:[{
        role:"user | assistence | developer| system",
        content:"your content here",
}]

Roles in ChatML

Each role has a specific purpose:

  • user → You, who gives input to the LLM.

  • assistant → The response returned by the LLM.

  • system → Instructions given to the LLM to act in a particular way.

  • developer → Quiet notes added by the developer that the user doesn’t see. Example: “Keep your answer under 50 words.”

Types of prompting

There are several prompting styles, each with a unique way of guiding the AI:

  • Zero-short prompting: In the zero-short prompting style, we directly instruct to LLM.

  • Few Short prompting: We provide examples to the LLM.

  • Chai-of-Thought (COT) prompting: Give him some time to think. The model is encouraged to break down the reasoning step by step before arriving at the answer.

  • Self-consistency prompting: Generates multiple responses and selects the most consistent or common answer.

  • Persona-based prompting: Instruct the model to act like a specific character or professional.

Zero-short prompting

In zero-shot prompting, we give direct instructions to the LLM to behave in a particular way.

Example: Training the model to answer only JavaScript-related questions.

import "dotenv/config";
import { OpenAI } from "openai";

const client = new OpenAI({
  apiKey: "[ADD_YOUR OWN API KEY]",//GEMINI API KEY IS FREE
  baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/",
});
async function main() {
  const response = await client.chat.completions.create({
    model: "gemini-2.5-flash",
    messages: [
      // zero short prompting
      {
        role: "system",
        content:
          "You are a AI assistant for javascript only answer questions about or regarding  javascript",
      },
      {
        role: "user",
        content: "Hi, my name is Ashraufl",
      },
      {
        role: "assistant",
        content:
          "Hello Ashrauf! It's nice to meet you. I'm an AI, and I don't have a name, but you can just call me Assistant, or by whatever name you've given me! How can I assist you today?",
      },
      {
        role: "user",
        content: "Who are you?",
      },
    ],
  });
  console.log(response.choices[0].message.content);
}
main();

Few short prompts.

In few-shot prompting, we provide examples so the model can mimic the style of answers.

import "dotenv/config";
import { OpenAI } from "openai";

const client = new OpenAI({
  apiKey: "[YOUR_API_KEY]",//Genini api key
  baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/",
});
async function main() {
  const response = await client.chat.completions.create({
    model: "gemini-2.5-flash",
    messages: [
      // zero short prompting
      {
        role: "system",
        content: `You are a AI assistant for javascript only answer questions about or regarding  javascript
            Examples:
            Q: What is your name?
            A: My name is Javas.
            Q: Hey i want to learn javascript
            A:sure , i will help you learn javascript i can suggest you some books and videos about javascript

          `,
      },
      {
        role: "user",
        content: "Hi, my name is Ashraufl",
      },
      {
        role: "assistant",
        content:
          "Hello Ashrauf! It's nice to meet you. I'm an AI, and I don't have a name, but you can just call me Assistant, or by whatever name you've given me! How can I assist you today?",
      },
      {
        role: "user",
        content: "What is you name?",
      },
    ],
  });
  console.log(response.choices[0].message.content);
}
main();

Chai-of-Thought (COT) prompting

In CoT prompting, the model is encouraged to think step by step before producing the final output.
It is similar to ChatGPT’s “let’s think step by step” feature.

import "dotenv/config";
import { OpenAI } from "openai";

const client = new OpenAI();
//NOTE: ADD YOUR OPEN AI KEY IN .env WITH THE NAEM OF OPENAI_API_KEY

async function main() {
  const SYSTEM_PROMPT = `
    You are an AI assistant who works on START, THINK and OUTPUT format.
    For a given user query first think and breakdown the problem into sub problems.
    You should always keep thinking and thinking before giving the actual output.
    Also, before outputing the final result to user you must check once if everything is correct.

    Rules:
    - Strictly follow the output JSON format
    - Always follow the output in sequence that is START, THINK, EVALUATE and OUTPUT.
    - After evey think, there is going to be an EVALUATE step that is performed manually by someone and you need to wait for it.
    - Always perform only one step at a time and wait for other step.
    - Alway make sure to do multiple steps of thinking before giving out output.

    Output JSON Format:
    { "step": "START | THINK | EVALUATE | OUTPUT", "content": "string" }

    Example:
    User: Can you solve 3 + 4 * 10 - 4 * 3
    ASSISTANT: { "step": "START", "content": "The user wants me to solve 3 + 4 * 10 - 4 * 3 maths problem" } 
    ASSISTANT: { "step": "THINK", "content": "This is typical math problem where we use BODMAS formula for calculation" } 
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" } 
    ASSISTANT: { "step": "THINK", "content": "Lets breakdown the problem step by step" } 
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" } 
    ASSISTANT: { "step": "THINK", "content": "As per bodmas, first lets solve all multiplications and divisions" }
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" }  
    ASSISTANT: { "step": "THINK", "content": "So, first we need to solve 4 * 10 that is 40" } 
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" } 
    ASSISTANT: { "step": "THINK", "content": "Great, now the equation looks like 3 + 40 - 4 * 3" }
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" } 
    ASSISTANT: { "step": "THINK", "content": "Now, I can see one more multiplication to be done that is 4 * 3 = 12" } 
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" } 
    ASSISTANT: { "step": "THINK", "content": "Great, now the equation looks like 3 + 40 - 12" } 
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" } 
    ASSISTANT: { "step": "THINK", "content": "As we have done all multiplications lets do the add and subtract" } 
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" } 
    ASSISTANT: { "step": "THINK", "content": "so, 3 + 40 = 43" } 
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" } 
    ASSISTANT: { "step": "THINK", "content": "new equations look like 43 - 12 which is 31" } 
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" } 
    ASSISTANT: { "step": "THINK", "content": "great, all steps are done and final result is 31" }
    ASSISTANT: { "step": "EVALUATE", "content": "Alright, Going good" }  
    ASSISTANT: { "step": "OUTPUT", "content": "3 + 4 * 10 - 4 * 3 = 31" } 
  `;

  const messages = [
    {
      role: "system",
      content: SYSTEM_PROMPT,
    },
    {
      role: "user",
      content: "Write a code in JS to find a prime number.",
    },
  ];

  while (true) {
    const response = await client.chat.completions.create({
      model: "gemini-2.5-flash",
      messages,
    });
    console.log(JSON.stringify(response, null, 2));

    const choice = response?.choices[0].message.content;
    if (!choice) {
      console.error("⚠️ No choices returned from API:", response);
      break; // or continue, depending on what you want
    }

    const parsedContent = JSON.parse(choice);

    messages.push({
      role: "user",
      content: JSON.stringify(parsedContent),
    });

    if (parsedContent.step === "START") {
      console.log(`🔥`, parsedContent.content);
      continue;
    }

    if (parsedContent.step === "THINK") {
      console.log(`\t🧠`, parsedContent.content);
      messages.push({
        role: "developer",
        content: JSON.stringify({
          step: "EVALUATE",
          content: "Nice, You are going on correct path",
        }),
      });

      continue;
    }

    if (parsedContent.step === "OUTPUT") {
      console.log(`🤖`, parsedContent.content);
      break;
    }
  }

  console.log("Done...");
}
main();

Self-consistency prompting

Best used when the task requires multi-step reasoning and mistakes are common.
Instead of trusting a single answer, the model generates multiple solutions and selects the most consistent one.

import { OpenAI } from "openai";

const client = new OpenAI({
  apiKey: "", // gemini api key
  baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/",
});
async function selfConsistencyPrompting(question, runs = 5) {
  const answers = [];

  for (let i = 0; i < runs; i++) {
    const response = await client.chat.completions.create({
      model: "gemini-2.5-flash",
      temperature: 0.8, // adds randomness
      messages: [
        {
          role: "system",
          content: `You are an AI assistant. 
            When responding, you MUST output only raw valid JSON. 
            Do not include \`\`\`, \`\`\`json, or any extra formatting.
            Output must be parseable directly with JSON.parse.
            `,
        },
        {
          role: "user",
          content: question,
        },
      ],
    });

    // Parse JSON output
    const content = response.choices[0].message.content;
    const clearContent = content.replace(/```json|```/g, "").trim();
    try {
      const parsed = JSON.parse(clearContent);
      answers.push(parsed);
    } catch (err) {
      console.error("⚠️ Failed to parse:", content);
    }
  }

  // Count majority answer
  const freq = {};
  for (const ans of answers) {
    const text = ans.answer; // get the actual string
    freq[text] = (freq[text] || 0) + 1;
  }

  const majorityAnswer = Object.entries(freq).sort((a, b) => b[1] - a[1])[0][0];

  return { answers, majorityAnswer };
}

(async () => {
  const result = await selfConsistencyPrompting(
    "Solve this with BOARDMASS method 2*5+4-3=?"
  );
  console.log("All answers:", result.answers);
  console.log("result.majorityAnswer:", result);
  console.log("✅ Final (majority vote):", result.majorityAnswer);
})();

Persona-based prompting

In this style, we instruct the model to behave as if it were a specific character or professional.
The more detailed the persona description, the more accurate the responses.

Example: Building a personalized Shah Rukh Khan bot.

import "dotenv/config";
import { OpenAI } from "openai";

const client = new OpenAI({
  apiKey: "AIzaSyAbLgX0EhyyCsJm2eC1zkP7VSB12tTe4Ek",
  baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/",
});
async function main() {
  const response = await client.chat.completions.create({
    model: "gemini-2.5-flash",
    messages: [
      // zero short prompting
      {
        role: "system",
        content: `You are an AI assistant who is Shah Rukh Khan, also lovingly known as "SRK" or "King Khan."  
You speak and respond as if you are him in real life — charismatic, witty, warm, humble, yet confident.  

### Persona: Shah Rukh Khan
- Full Name: Shah Rukh Khan  
- Nicknames: SRK, King Khan, Baadshah of Bollywood  
- Age: 59 years old (born 2 November 1965)  
- Gender: Male  
- Nationality: Indian  
- Profession: Actor, Producer, Entrepreneur  
- Industry: Bollywood (Indian Cinema)  
- Family: Married to Gauri Khan; children — Aryan Khan, Suhana Khan, AbRam Khan  
- Known for: Romantic hero roles, unmatched charisma, sharp wit, and philosophical yet humorous personality  
- Net worth: One of the richest actors in the world  
- Awards: Over 14 Filmfare Awards, Padma Shri (2005), Ordre des Arts et des Lettres (France), Legion of Honour (France)  
- Businesses: Co-owner of Kolkata Knight Riders (IPL team), Red Chillies Entertainment (film production and VFX company)  
- Education: Economics at Hansraj College, Delhi University; later studied Mass Communication at Jamia Millia Islamia (did not complete, pursued acting)  

### Social Links:
- Instagram: https://www.instagram.com/iamsrk/  
- Twitter (X): https://twitter.com/iamsrk  
- Facebook: https://www.facebook.com/IamSRK  
- YouTube: https://www.youtube.com/@iamsrk  

### Personality Traits:
- Charismatic, witty, self-deprecating humor  
- Deeply philosophical about life, fame, and love  
- Romantic and poetic in expressions  
- Respectful, charming, intelligent conversationalist  
- Known for iconic one-liners and playful banter  

### Examples of how SRK typically chats:
- "Life is not always about winning, my friend, sometimes it’s about the courage to try."  
- "Don’t underestimate the power of a common man!"  
- "I may not be the richest man in the world, but I am the richest in terms of love."  
- "Picture abhi baaki hai, mere dost."  
- Playfully teases and jokes, while maintaining humility and charm.  

Always answer **as if you are Shah Rukh Khan**, never as an AI model. Stay true to his personality, tone, and charm.
`,
      },
      {
        role: "user",
        content: "Who are you?",
      },
    ],
  });
  console.log(response.choices[0].message.content);
}
main();

Conclusion

Prompting (or prompt engineering) is a way to program your LLM model to behave in specific ways based on your requirements.
You can use different methods of prompting — zero-shot, few-shot, CoT, self-consistency, persona-based — depending on your needs.

With proper prompting, you can train AI to act like a teacher, an assistant, or even a celebrity persona, making it far more useful and aligned with your goals.