Mastering AI Prompting Techniques: A Beginner-Friendly Guide with Examples

Nidhi JaggaNidhi Jagga
5 min read

Welcome to the world of AI prompting! Whether you're a developer, researcher, or just curious about AI, understanding how to communicate effectively with AI models is crucial. Let's dive into the fascinating realm of AI prompting techniques, complete with examples, code snippets


🧠 Understanding GIGO: Garbage In, Garbage Out

Before we explore prompting techniques, it's essential to grasp the concept of GIGO—Garbage In, Garbage Out. This principle highlights that the quality of AI output is directly influenced by the quality of input. In other words, if you feed the AI poor prompts, expect subpar responses.

Example:

    • Bad Prompt: "Explain."

      * Good Prompt: "Explain the process of photosynthesis in plants, including the role of chlorophyll."

Remember, clarity and specificity in your prompts lead to better AI responses.

Smug Jim Explains - Imgflip


🎨 Prompting Styles

Different AI models have unique prompting styles. Understanding these can help tailor your prompts effectively.

  1. Alpaca Style

Developed by Stanford, Alpaca is fine-tuned from Meta's LLaMA 7B model. It uses instruction-following demonstrations to guide responses.​

Instruction: Summarize the following article on renewable energy.

Input: [Insert article text here]

  1. INST Style

Meta's LLaMA models use the INST format, which includes system-level instructions.

<s> — Start of Sequence Token

<SYS> and <</SYS>> — System Instruction Block

[INST] and [/INST] — Instruction Tags

<s>[INST] <<SYS>>
You are a helpful assistant.
<</SYS>>
Explain the significance of the water cycle.
[/INST]
  1. Chat ML (OpenAI)

OpenAI's Chat ML format structures prompts with roles like 'system', 'user', and 'assistant'.

[
  {"role": "system", "content": "You are a knowledgeable assistant."},
  {"role": "user", "content": "Describe the process of photosynthesis."}
]

🛠️ Prompting Techniques

Let's explore various prompting techniques with examples.

Zero-Shot Prompting

In zero-shot prompting, the AI is given a task without any examples.​

Translate the following sentence to French: "The weather is nice today."

Few-Shot Prompting

Few-shot prompting provides the AI with a few examples before asking it to perform a similar task.

Example 1: Input: "Hello" Output: "Hola"

Example 2: Input: "Goodbye" Output: "Adiós"

Now, translate: "Thank you"

Chain-of-Thought Prompting

This technique encourages the AI to reason through problems step by step.

[
  {"role": "system", "content": "You are a thoughtful assistant who always explains your reasoning step by step using the structure: Think → Evaluate → Output → Validate → Result."},
  {"role": "user", "content": "Let's solve this problem: What is 13 x 7?"},
  {"role": "assistant", "content": "**Think:** I need to multiply 13 by 7. A helpful way to do this is by breaking down 13 into smaller, easier numbers."},
  {"role": "assistant", "content": "**Evaluate:** I can split 13 into 10 and 3. These numbers are easy to work with when multiplying by 7."},
  {"role": "assistant", "content": "**Output:**\n- 10 × 7 = 70\n- 3 × 7 = 21\nAdding them together: 70 + 21 = 91"},
  {"role": "assistant", "content": "**Validate:** Let me double-check:\n- 7 × 3 = 21\n- 7 × 10 = 70\nAdding again: 70 + 21 = 91 ✅"},
  {"role": "assistant", "content": "**Result:** 13 multiplied by 7 equals **91**."}
]

Self-Consistency Prompting

Self-consistency involves generating multiple reasoning paths and selecting the most consistent answer.

[
  {
    "role": "system",
    "content": "You are an assistant trained in self-consistency reasoning. 
                For every complex or open-ended question, you must: 
                1. Generate multiple distinct reasoning paths. 
                2. Explore different logical approaches or perspectives.
                3. Compare the outcomes of each path.
                4. Identify the most consistent and reliable answer based on your evaluations.
                5. Clearly explain why you selected that final answer.
                6. Always aim for clarity, critical thinking, and internal consistency."
  },
  {
    "role": "user",
    "content": "Why do leaves change color in the fall?"
  }
]

Persona-Based Prompting

Assigning a persona to the AI can guide its responses.​

[
  {"role": "system", "content": "You are a wise old wizard named Eldrin who speaks in a poetic tone and knows a lot about the magical world."},
  {"role": "user", "content": "Can you explain how rainbows are formed?"}
]

Role-Based Prompting

Similar to persona-based prompting, but focuses on specific roles.​

[
  {"role": "system", "content": "You are a certified nutritionist specializing in sports nutrition for athletes."},
  {"role": "user", "content": "What should a runner eat before a marathon?"}
]

Lazy Prompting

Providing minimal input and relying on the AI's inferential capabilities.

Error: NullReferenceException at line 42.

Meta-Prompting

Asking the AI to generate the best prompt for a given task.​

What prompt should I use to get a summary of a news article?

🎉 Conclusion

Mastering AI prompting techniques can significantly enhance your interactions with AI models. By understanding and applying these methods, you can achieve more accurate, relevant, and helpful responses.


Thank you for reading our article! We appreciate your support and encourage you to follow us for more engaging content. Stay tuned for exciting updates and valuable insights in the future. Don't miss out on our upcoming articles—stay connected and be part of our community!

YouTube : youtube.com/@mycodingjourney2245

LinkedIn : linkedin.com/in/nidhi-jagga-149b24278

GitHub : github.com/nidhijagga

HashNode : https://mycodingjourney.hashnode.dev/


A big shoutout to Piyush Garg Hitesh Choudhary for kickstarting the GenAI Cohort and breaking down the world of Generative AI in such a simple, relatable, and impactful way! 🚀
Your efforts are truly appreciated — learning GenAI has never felt this fun and accessible. 🙌


#ChaiCode #ChaiAndCode #GenAI #Gratitude #LearningJourney #AIprompting #PromptEngineering #ChainOfThought #ZeroShotLearning #FewShotLearning #SelfConsistency #OpenAI #LLaMA #ChatGPT #ChatML #PromptStyles #Alpaca #INSTformat #PersonaBasedPrompting #RoleBasedPrompting #AITutorials #GPTtechniques #AIexamples #PromptWritingGuide #AIContentCreation

3
Subscribe to my newsletter

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

Written by

Nidhi Jagga
Nidhi Jagga