AI Help Center › GenAI / LLM › Generative AI Beginner Guides › Advanced Prompting
GENAI / LLM · INTERMEDIATE GUIDE

Advanced Prompting: Few-Shot Examples, Chain-of-Thought and Structured Outputs

Advanced prompting uses four techniques to control model behaviour: few-shot prompting, chain-of-thought, structured outputs and prompt chaining. Includes a 30-minute exercise.

14 min readPublished November 2, 2026Last reviewed November 2, 2026

Advanced prompting uses four techniques to control model behaviour: few-shot prompting (showing 2 to 5 solved examples), chain-of-thought (making the model reason step by step), structured outputs (JSON or tables that software can read), and prompt chaining (splitting complex work into smaller prompts). Together they make an AI chat tool dependable inside a workflow.

Before you begin

Prerequisite: the 5-part framework from Article 3, Prompt Engineering Basics. Everything here builds on it.

Advanced prompting

Why does basic prompting stop being enough?

Basic prompting stops being enough when a well-briefed prompt still produces output that is wrong in style, skips logical steps, or cannot be used by software. The 5-part framework from Article 3 fixes most everyday failures. Three symptoms tell you that you have reached its ceiling:

  • The output is right in spirit but wrong in style. You keep editing it towards a standard you can feel but cannot fully articulate.
  • The task involves multi-step logic. Reconciliations and eligibility rules are examples. The model must not skip steps, and it confidently skips them.
  • You want to use the output in a system. You need to paste it into a spreadsheet or feed it to a script, and free-flowing prose keeps breaking the workflow.

Each symptom has a specific cure, and none of them involves writing a longer paragraph of instructions. The shift in this article is from describing what you want to engineering the conditions under which the model produces it.

Few-shot prompting

What is few-shot prompting, and when should you use it?

Few-shot prompting means including 2 to 5 examples of input and ideal output before your real request, so the model imitates a demonstrated pattern instead of interpreting adjectives. We tell every cohort this, and it lands hardest with the writers in the room: models imitate examples far better than they follow adjectives. "Professional but warm, concise but complete" means a hundred different things. Two examples of an actual email you liked mean exactly one thing.

The opposite is zero-shot prompting, where you give instructions only and no examples. The model then guesses your standards from words alone and is inconsistent on edge cases (the borderline inputs where the right answer is not obvious). With a few solved examples, it infers your labels, your edge-case handling and your format, and the output is consistent.

Zero-shot (instructions only)Few-shot (instructions + examples)'Classify this feedback asPositive / Negative / Mixed'Model guesses yourstandards from words aloneInconsistent on edge casesSame instruction+ 3 solved examplesModel infers the pattern:your labels, edge-case handling,your formatConsistent, calibrated output

A worked pattern you can copy:

Prompt
Classify customer feedback for a training institute as POSITIVE, NEGATIVE,
or MIXED, with a one-line reason.

Feedback: "Faculty was brilliant but the recordings took a week to arrive."
Label: MIXED. Praises teaching, flags operations delay.

Feedback: "Placement support was a joke."
Label: NEGATIVE. Dissatisfaction with placement services.

Feedback: "Worth every rupee, already recommended to two colleagues."
Label: POSITIVE. Strong satisfaction plus advocacy.

Feedback: "The course was fine I guess."
Label:

The examples teach three things that instructions never could: MIXED exists as a category, reasons stay to one line, and lukewarm is not positive. Your edge cases are your standards, so choose examples that cover the tricky boundaries, not three easy wins.

Few-shot earns its keep in four places: matching your company's writing voice, enforcing report formats, consistent tagging and classification, and any task you repeat weekly. Build the examples once and reuse them forever. This is the natural evolution of the prompt library you started in Article 3.

One caveat: examples consume context-window space and can over-anchor the model. The context window is the amount of text a model can consider at once (Article 2, How LLMs Work explains it). Over-anchoring means five formal examples will fight your request for a casual tone. Two or three well-chosen examples usually beat eight redundant ones.

Reasoning

What is chain-of-thought prompting, and does it still work?

Chain-of-thought (CoT) prompting means instructing a model to reason through intermediate steps before it gives a final answer. Ask a model a multi-step question and let it answer immediately, and it may pattern-match its way to a plausible wrong answer. Ask it to reason step by step before concluding, and accuracy on logic, maths and rule-application tasks improves measurably. The research behind it, Wei et al., 2022, is one of the most cited findings in the field.

The mechanism, in Article 2's terms, is that each generated token becomes context for the next. A token is a small chunk of text, often a word or part of a word. Forcing intermediate steps means the final answer is conditioned on the reasoning and not on a shortcut.

Complex question:'Which of these 4 vendorsmeets all our criteria?'Prompt: 'Work througheach criterion for eachvendor before concluding'Step 1:List criteriaStep 2:Check vendors A-Dagainst each criterionStep 3:Eliminate with reasonsConclusion, auditablebecause you can readthe steps

A worked example with numbers. Take this question: "A reseller buys an item for ₹1,18,000 including 18% GST and sells it for ₹1,41,600 including 18% GST. What is the profit excluding GST?" A model that answers instantly can take the shortcut of subtracting the two prices and reporting ₹23,600. That figure wrongly counts ₹3,600 of GST as profit. Now ask it to work in steps: "First remove GST from both prices. Then subtract. Show each step." The steps give ₹1,18,000 ÷ 1.18 = ₹1,00,000 for the purchase and ₹1,41,600 ÷ 1.18 = ₹1,20,000 for the sale, so the profit excluding GST is ₹20,000. You can also see exactly where a wrong answer would have gone wrong.

Three ways to trigger it, from basic to high stakes:

  • The classic: "Think step by step before answering."
  • Better for business work: "First list the rules that apply. Then check each option against each rule. Only then give your recommendation, flagging anything uncertain."
  • Best for high stakes: make the model show its work and check itself. "After your answer, review your own reasoning and state the weakest step."

The 2026 update most tutorials skip. Modern reasoning models (OpenAI's o-series, Claude's extended thinking, Gemini's thinking modes) now do chain-of-thought internally, on their own. For those models, adding "think step by step" to a prompt adds little. What still matters, and matters more than before, is your version of CoT: specifying which steps the reasoning must include (for example, "check GST applicability before computing margin") and demanding an audit trail. The technique did not die. It moved up a level, from triggering reasoning to directing it.

There is a second benefit: trust. Reasoning you can read is reasoning you can check. In our corporate sessions, teams in finance and compliance consistently rate the audit trail as more valuable than the accuracy improvement itself.

Structured outputs

How do you get an AI model to return structured output like JSON?

To get structured output, give the model an exact schema with allowed values, tell it to return only valid JSON, and add a rule to use null for anything missing. This matters the moment a system, not a person, reads the output: Google Sheets, a Python script, your CRM (the software a business uses to track customers and leads). Prose becomes the problem, and you need structure. The common format for structured data is JSON (JavaScript Object Notation), a labelled container format that every programming language understands. A schema is simply the fixed list of fields you want back and the values each field may take.

The pattern:

Prompt
Extract from the email below and return ONLY valid JSON, no commentary,
in exactly this schema:
{"client_name": "", "request_type": "demo | pricing | complaint | other",
 "urgency": "high | medium | low", "next_action": "",
 "deadline_mentioned": true/false}
Email: [paste]

For a sample email reading "Hi, this is Meera Nair. We would like pricing for 40 learners. Please send it by Friday", a good response looks like this:

JSON
{"client_name": "Meera Nair", "request_type": "pricing", "urgency": "medium",
 "next_action": "Send pricing for 40 learners", "deadline_mentioned": true}

Because the output is in a fixed shape, a script or spreadsheet can read it without any cleaning. A parser (the code that reads the model's output) fails on even one stray sentence, which leads to the rules below.

Three rules separate working automations from broken ones:

  1. Give the exact schema, with allowed values. "Return JSON" alone invents a new structure on each run. A fixed schema with enumerated options ("demo | pricing | complaint | other") makes runs comparable.
  2. Say "ONLY valid JSON, no commentary." Models like to add a friendly preamble, and that breaks your parser.
  3. Include a null-handling rule: "If a field is not present in the source, use null. Never guess." Null is the value that means "no data here". This single line is your main defence against hallucinated data (confident but invented information) flowing into a spreadsheet, where it acquires credibility it has not earned.

If you build with APIs later in this series (an API is the way your own software talks to a model), note that providers now offer enforced structured outputs at the API level. See OpenAI's structured outputs guide and Anthropic's tool use documentation. These guarantee schema compliance instead of requesting it. In the chat interface, the prompt-level rules above are your tool. Either way, the skill is the same: designing a good schema. That is data modelling, which is why data-trained professionals pick this up faster than they expect.

Tables are the simpler cousin of JSON. "Return a markdown table with columns X, Y, Z" pastes straight into Sheets and Excel.

Prompt chaining

What is prompt chaining, and why does it beat one big prompt?

Prompt chaining means breaking a complex task into a sequence of smaller prompts, where each output feeds the next stage and a human reviews between stages. It outperforms a single mega-prompt on both quality and debuggability.

The instinct with a big task is to write a bigger prompt. Resist it. A 400-word mega-prompt asking for research, analysis, drafting and formatting in one shot produces mediocre work at every stage, and when it fails you cannot tell which part failed. The professional pattern is to decompose the work into stages, run each as its own prompt, and feed each output into the next, reviewing at the joints.

Prompt 1:Extract key pointsfrom 3 documentsHumanreviewPrompt 2:Compare and findcontradictionsHumanreviewPrompt 3:Draft summary forCXO audienceHumanreviewFinaldeliverable

Illustration only, not a client result: suppose you must brief a CXO on three vendor proposals. Prompt 1 extracts price, timeline and risks from each proposal. You check the extraction against the documents. Prompt 2 compares the three and lists contradictions. You confirm the contradictions are real. Prompt 3 drafts a one-page summary for the CXO. You read it once and send it.

Why this wins:

  • Each stage gets a clean, focused context window. Instructions buried in a mega-prompt get diluted (Article 2 explains why).
  • You insert judgement where it is cheap. Catching a wrong extraction at stage 1 costs seconds. Catching it in the final draft costs the deliverable.
  • Stages become reusable. Your "extract key points" prompt works on next month's documents too.

If this looks like an assembly line, that is the point. It is also a preview of AI agents (Article 9, AI Agents Fundamentals), which are essentially chains where the model itself decides the next step. Learn to design chains by hand and agents will feel logical rather than magical.

Worked example · Illustrative

One mega-prompt: Asking for extraction, comparison and an executive brief in one step produced a polished summary, but it quietly omitted two delivery risks and mixed quoted facts with assumptions.

Three-stage chain: Stage 1 extracted price, timeline and risks into a fixed table. A reviewer checked every row against the proposals. Stage 2 compared only the verified table and flagged contradictions. Stage 3 drafted the CXO brief from that checked comparison. The chain took an extra review pass, but every conclusion could be traced back to a source field.

Decision guide

Which technique should you use for which problem?

Match the technique to the symptom. The table below summarises the four techniques.

Technique Use it when What you give the model Main risk
Few-shot prompting Style, tone or classification standards are hard to describe in words 2 to 5 solved input and output examples, including edge cases Over-anchoring to the examples; wasted context space
Chain-of-thought The task has multi-step logic or rules that must not be skipped The specific steps to follow, plus a request for an audit trail Little benefit if the model already reasons internally
Structured outputs Software, not a person, reads the result An exact schema with allowed values and a null rule Valid structure can still contain wrong facts
Prompt chaining The task mixes research, analysis, drafting and formatting A sequence of focused prompts with human review between them Needs more setup per task than a single prompt
Hands-on exercise

How do you build a feedback classifier in 30 minutes?

You will combine all four techniques into a reusable classifier that turns messy feedback into clean spreadsheet rows.

  1. Collect (5 minutes). Gather 10 pieces of real free-text feedback relevant to you: customer reviews, course feedback, support messages, even WhatsApp group complaints. Use no confidential data and anonymise names.
  2. Design the schema (5 minutes). Decide what columns your spreadsheet needs. A solid starter: {"sentiment": "positive|negative|mixed", "topic": "product|service|price|other", "urgency": "high|low", "summary": "", "verbatim_quote": ""}. Adjust the topics to your business.
  3. Write the few-shot prompt (10 minutes). Write the instruction, your schema and three solved examples, choosing at least one genuinely ambiguous case. Add the null rule and "ONLY valid JSON, one object per feedback item, as a JSON array." A JSON array is a list of JSON objects inside square brackets, one object per feedback item.
  4. Run and audit (5 minutes). Paste all 10 items and check the output against your own judgement. Where the model disagreed with you, do not just fix the output. Fix the examples so the boundary is taught, then re-run. This example-refinement loop is the actual skill.
  5. Land it in a spreadsheet (5 minutes). Ask: "Convert that JSON array to a markdown table." Copy the table the model gives you and paste it into cell A1 of a Google Sheet. If the columns do not split, use Data, then Split text to columns. You now have a pipeline: raw feedback to structured data to an analysable table.

Stretch goal: chain it. Prompt 2: "From this table, identify the three most actionable issues and draft a one-paragraph note to the operations head." You have just built a two-stage analysis pipeline.

Common misconceptions

What are the common misconceptions about these techniques?

Four beliefs about advanced prompting are common and wrong.

  • "More examples always help." Past 3 to 5 examples, returns diminish and costs rise. Past a point, irrelevant examples actively hurt. Curate, do not hoard.
  • "Chain-of-thought is obsolete because reasoning models exist." The trigger phrase is largely obsolete on those models. Directing the reasoning (which checks to run, in what order, what to flag) is more valuable than ever, and demanding a visible audit trail never stopped mattering.
  • "JSON output means the data is correct." Structure guarantees shape, not truth. A model can hallucinate inside a perfectly valid schema. Hence the null rule, and hence verification before that data drives a decision.
  • "Chaining is slower than one big prompt." Per attempt, slightly. Per successful deliverable, chaining is almost always faster, because mega-prompt failures cost full restarts.
Honest limits

When should you not use these techniques?

You do not need these techniques for simple tasks, and using them anyway adds effort for no gain.

  • One-off tasks. If you will never repeat the task, writing examples costs more than the editing you save. A single clear prompt using the 5-part framework is enough. The same goes for chaining a task that already works in one prompt.
  • Output that only a person will read. Do not force JSON when you are reading the answer yourself. Plain prose or a simple table is easier to read and quicker to ask for.
  • Reasoning models. Do not add "think step by step" to a reasoning model. Spend those words on telling it which checks to run.
  • High-stakes data with no checking step. Do not let structured output feed a decision unless a person has checked a sample against the source.
Action plan

What should you do next?

  1. Pick one task you repeat weekly and write a few-shot prompt for it with two or three examples, including one edge case. Save it in your prompt library from Article 3.
  2. Add a null rule and a fixed schema to any prompt whose output goes into a spreadsheet or script, and check ten outputs against your own judgement before relying on it.
  3. Split your longest prompt into two or three stages, with a review step between them, and compare the result with the original.
FAQ

Frequently asked questions

What is few-shot prompting?

Few-shot prompting means including two to five examples of ideal input and output pairs in your prompt, so the model imitates the demonstrated pattern instead of interpreting adjectives. It is the most reliable way to control tone, format and classification standards.

What is chain-of-thought prompting?

Chain-of-thought prompting means instructing a model to reason through intermediate steps before giving a final answer. It improves accuracy on multi-step logic and produces an auditable reasoning trail.

How do I get ChatGPT to return JSON?

Provide the exact schema with allowed values, instruct it to return only valid JSON with no commentary, and add a rule to use null for missing information instead of guessing. The same approach works in Claude and Gemini.

What is prompt chaining?

Prompt chaining means breaking a complex task into a sequence of smaller prompts, where each output feeds the next stage, with human review between stages. It outperforms single mega-prompts on quality and debuggability.

Do these techniques work on all AI models?

Yes, with one nuance. Reasoning-class models perform chain-of-thought internally, so an explicit "think step by step" adds little there. Few-shot prompting, structured outputs and chaining apply to all models.

Keep learning

What is next in this series?

You can now steer a model with examples, direct its reasoning, extract machine-readable data and design multi-stage pipelines. That is the complete toolkit for working inside a chat window, which means you have outgrown it.

Next, Article 5: Embeddings and Vector Databases: How AI Understands Meaning. It is the first article on the builder's side of the series: how text becomes numbers that capture meaning, why that enables semantic search over your own documents, and the foundation that everything called "RAG" stands on.

Series roadmap: 1. What Is Generative AI? → 2. How LLMs Work → 3. Prompt Engineering Basics → 4. Advanced Prompting (you are here) → 5. Embeddings and Vector Databases → 6. RAG Explained → 7. Fine-Tuning vs RAG → 8. Function Calling and Tool Use → 9. AI Agents Fundamentals → 10. Multi-Agent Systems → 11. Evaluating LLM Outputs → 12. Building Your First AI App.

Sources

Sources