DEV Community

Cover image for Understanding Prompting Techniques in AI
Shreyans Padmani
Shreyans Padmani

Posted on

Understanding Prompting Techniques in AI

Large language models are only as good as the prompts you give them. The same model can look mediocre or brilliant depending on how you ask it to do something. Below is a practical rundown of the eight core prompting techniques every developer working with LLMs should know — from the simplest zero-shot ask to full reasoning-plus-tool-use agents.

1. Zero-Shot Prompting

You ask the model to do a task with no examples at all — just a clear instruction. It leans entirely on what it learned during pretraining to produce a response.

When to use it: simple, well-known tasks (summarizing, translating, basic Q&A) where the model doesn't need to see the exact output format first.

2. One-Shot Prompting

You give the model exactly one example of the input/output pattern you want before asking your real question. That single demonstration is often enough to anchor the format and tone of the response.

When to use it: when the task is simple but the format matters — e.g., you want output as a specific JSON shape or a particular writing style.

3. Few-Shot Prompting

Same idea as one-shot, but with several (2–5) examples. More examples mean the model can pick up on patterns rather than guessing from a single case, which improves both accuracy and consistency.

Interestingly, research on in-context learning has found that what matters most isn't necessarily whether every example's label is perfectly correct — the diversity of inputs and the overall structure of the examples matter a great deal too. A well-known study by Min et al. (2022) found that even examples with randomly shuffled labels still outperformed zero-shot prompting.

When to use it: classification, structured extraction, or any task where you want the model to mimic a precise style or schema.

If you want to see few-shot and NLP-style prompting applied in a real project, I broke down how it worked for automatic feedback categorization here: NLP Customer Feedback Classification

4. Chain-of-Thought (CoT) Prompting

Instead of asking for a final answer directly, you ask the model to reason step by step. This breaks a complex problem into smaller logical steps, which tends to produce more accurate results on math, logic, and multi-step reasoning problems.

A neat shortcut discovered in research: you don't always need worked examples to get this benefit. Kojima et al. showed that simply appending "let's think step by step" to a prompt can trigger step-by-step reasoning even with zero examples. Note: this trick mainly helps standard models — reasoning models (extended-thinking, o-series, etc.) already do this internally.

5. Self-Consistency Prompting

The model generates multiple independent reasoning paths for the same question (usually via sampling), and you select the most common or most consistent final answer among them. It's "ensemble voting" applied to reasoning chains.

6. Role-Based Prompting

You assign the model a persona — teacher, senior developer, security auditor, etc. — before giving it the task. This nudges vocabulary, depth, and structure to match that role's expertise and tone.

7. Instruction Tuning / Task-Specific Prompting

This is about being explicit and structured: clearly defined task requirements, precise instructions, and a well-organized prompt format. The tighter and more structured your instructions, the more precisely the model matches your intent.

8. ReAct (Reasoning + Acting) Prompting

ReAct combines reasoning with real actions — the model thinks step by step and can call external tools or fetch external data (API calls, search, database queries) while forming its answer. This is the pattern behind most modern AI agents.


Which Technique Should You Actually Use?

Most production prompts aren't "pure" versions of any one technique — they're combinations.

Key takeaways:

  • Few-shot prompting remains one of the best return-on-effort techniques for structured or stylistic tasks.
  • Zero-shot CoT ("think step by step") is a nearly free upgrade for reasoning tasks on standard models.
  • Self-consistency is a good lever when reliability matters more than latency or cost.
  • ReAct-style prompting is what you reach for once your model needs to interact with the outside world.

Prompt engineering is still evolving fast — Tree-of-Thought and Graph-of-Thought are pushing past linear reasoning into branching, mergeable reasoning paths for enterprise-grade decisions. But these eight techniques remain the foundation.

Where this is all heading — from general-purpose LLMs to vertical, domain-specific models and autonomous agents — is something I cover in more depth here: AI Predictions 2026: From General AI Models to Vertical LLMs and Autonomous Agents

If you're curious how these prompting techniques hold up in real production projects, check out more real-world builds here: AI Case Studies

Conclusion

Prompting isn't a single skill — it's a toolbox. Zero-shot and one-shot get you quick answers, few-shot and role-based prompting shape tone and format, chain-of-thought and self-consistency sharpen reasoning, and ReAct lets the model reach beyond its own knowledge into the real world. Knowing which lever to pull, and when, is what separates a mediocre AI output from a genuinely useful one.

🔗 Official Website: shreyans.tech

Top comments (0)