Most developers learn one or two prompting patterns and apply them to everything. That works until it doesn't — and when an AI feature starts producing unreliable or inconsistent output, they don't know why or how to fix it.

Prompt engineering is a real discipline. Here are five techniques that every developer building with LLMs should have in their toolkit.

Technique 01

Chain-of-Thought (CoT) Prompting

The most well-known technique — but also the most misapplied. Chain-of-thought asks the model to reason step-by-step before answering, rather than jumping straight to a conclusion. For complex tasks, this dramatically improves accuracy.

# Without CoT — often wrong on complex reasoning prompt = """ A store has 50 apples. They sell 30% on Monday and 40% of what remains on Tuesday. How many are left? Answer: """ # With CoT — much more reliable prompt = """ A store has 50 apples. They sell 30% on Monday and 40% of what remains on Tuesday. How many are left? Think through this step by step, then give the final answer. """

The second prompt reliably gives the right answer. The first often doesn't. The magic phrase "think through this step by step" is enough to trigger chain-of-thought reasoning in most modern models.

When to use it: Multi-step reasoning, math, logic problems, anything where getting the intermediate steps wrong would compound into a wrong answer.

Technique 02

Few-Shot Prompting with Careful Examples

Zero-shot prompting (no examples) works for simple tasks. But for tasks that require a specific format, tone, or style, providing 2–4 worked examples in the prompt — called few-shot prompting — consistently outperforms zero-shot.

The key insight most developers miss: your examples are the most important part of the prompt. Bad examples produce bad outputs even with a perfect instruction.

prompt = """ Classify the sentiment of customer reviews as POSITIVE, NEGATIVE, or NEUTRAL. Review: "The product arrived quickly and works perfectly." Sentiment: POSITIVE Review: "It's okay, nothing special but does the job." Sentiment: NEUTRAL Review: "Completely stopped working after 2 days. Terrible quality." Sentiment: NEGATIVE Review: "{new_review}" Sentiment: """

Common mistake: Using examples that are too similar to each other. Diverse examples that cover edge cases teach the model the boundaries of each category far more effectively.

Technique 03

Structured Output with JSON Mode

One of the most practically important techniques for developers: forcing the model to return structured, parseable output instead of prose. This turns an LLM from a text generator into a reliable data extraction engine.

Modern APIs (OpenAI, Anthropic, Gemini) all support structured output natively. Use it whenever you're passing model output to downstream code.

from openai import OpenAI from pydantic import BaseModel class InvoiceData(BaseModel): vendor_name: str total_amount: float due_date: str line_items: list[str] client = OpenAI() response = client.beta.chat.completions.parse( model="gpt-4o", messages=[ {"role": "system", "content": "Extract invoice data from the text."}, {"role": "user", "content": invoice_text} ], response_format=InvoiceData, ) invoice = response.choices[0].message.parsed # invoice.vendor_name, invoice.total_amount, etc. — type-safe
Technique 04

System Prompt Architecture

Most developers treat the system prompt as a place to dump instructions. The better approach is to treat it as a product specification — structured, explicit, and tested.

A well-architected system prompt has four sections:

  1. Identity — who the AI is, what it knows, what its role is
  2. Constraints — what it must never do, what it should always do
  3. Output format — how the response should be structured
  4. Handling edge cases — what to do when the user asks something unexpected
system_prompt = """ # Identity You are Aria, a customer support assistant for Aikonix Technologies. You have deep knowledge of our three AI courses and pricing. # Constraints - Never make up course details — if unsure, say "I'll check and get back to you" - Never discuss competitor products - Always be professional and helpful # Output Format - Keep responses under 150 words unless asked for detail - Use bullet points for lists of more than 3 items - Always end with a question or next step # Edge Cases - If asked about technical topics outside your scope: acknowledge and offer to connect them with an instructor - If asked about pricing: always direct to the courses page for the latest pricing """

Pro tip: Version your system prompts like code. Keep them in a repository, test changes against a set of known inputs, and never deploy an untested prompt change to production.

Technique 05

Meta-Prompting: Prompts That Write Prompts

Meta-prompting is asking the model to generate or improve prompts for a given task. It sounds circular but it's incredibly powerful in practice — LLMs often know more about how to communicate with themselves than you do.

meta_prompt = """ I need a prompt for an LLM that will: - Extract action items from meeting transcripts - Return them as a structured list with owner and deadline - Handle cases where owner or deadline is unclear Generate a production-ready system prompt for this task. Include instructions for handling edge cases and an example output format. """ # Use the generated prompt as a starting point, then refine

The output won't be perfect — but it gives you a strong starting point that captures edge cases you might not have thought of. Refine from there rather than starting from a blank page.

You can take this further with automatic prompt optimisation: generate 5–10 variants of a prompt, evaluate them against a test set, and keep the best performer. This is what large teams do at scale.

When to use it: When you're writing a complex prompt and keep iterating. When you want to see a different approach. When your current prompt has consistent failure modes you can't figure out how to fix.

Putting It Together

These five techniques aren't isolated — they compound. A well-architected system prompt (Technique 4) that uses chain-of-thought instructions (Technique 1) and returns structured output (Technique 3), with few-shot examples (Technique 2) and meta-prompting used during development (Technique 5) — that's a production-grade AI feature that actually works.

The developers who ship reliable AI features aren't using magic. They're applying these techniques deliberately and testing their prompts like they test their code.

Go Deeper with Our Prompt Engineering Course

18 sessions covering all of these techniques and more — with hands-on labs every session. Starting at ₹20,000.

See the Full Curriculum →

Back to Blog