30 Days of AIDay 9 of 30 · Week 2: Applied AI & APIs
Course outline▾

Week 3 · Infrastructure & Hosting

  1. Day 15Introduction to AI Infrastructure: Hardware, Runtimes, and ComputeComing soon · 2026-10-15 · 7 PM IST
  2. Day 16Local Model Execution: Running Open-Weight LLMs Securely (Ollama, vLLM)Coming soon · 2026-10-16 · 7 PM IST
  3. Day 17Containerizing AI Workloads: Writing Production Dockerfiles for Python APIsComing soon · 2026-10-17 · 7 PM IST
  4. Day 18Docker Compose for Multi-Container AI Stacks (Web UI, Vector DB, LLM Engine)Coming soon · 2026-10-18 · 7 PM IST
  5. Day 19Kubernetes for AI 101: Pods, Deployments, and Services for Model ServingComing soon · 2026-10-19 · 7 PM IST
  6. Day 20Persistent Storage in Kubernetes: Managing State, Weights, and Vector IndicesComing soon · 2026-10-20 · 7 PM IST
  7. Day 21High-Performance Networking: Configuring Ingress and Egress for AI ClustersComing soon · 2026-10-21 · 7 PM IST

Week 4 · Enterprise Workflows

  1. Day 22Autonomous Agents: From Passive LLMs to Goal-Driven ExecutionComing soon · 2026-10-22 · 7 PM IST
  2. Day 23Tool Use & Function Calling: Connecting LLMs to APIs, Databases, and ShellsComing soon · 2026-10-23 · 7 PM IST
  3. Day 24Multi-Agent Orchestration: Supervisor, Worker, and Evaluator PatternsComing soon · 2026-10-24 · 7 PM IST
  4. Day 25Automated CI/CD: Automating the Software Lifecycle for AI ModelsComing soon · 2026-10-25 · 7 PM IST
  5. Day 26Zero-Trust Security for AI: Sandboxing Ephemeral Execution & Model EgressComing soon · 2026-10-26 · 7 PM IST
  6. Day 27Observability & Tracing for Agentic Systems (Telemetry, Logs, and Metrics)Coming soon · 2026-10-27 · 7 PM IST
  7. Day 28Human-in-the-Loop Architecture: Machine Second, Human First in PracticeComing soon · 2026-10-28 · 7 PM IST
  8. Day 29Managing Technical Debt, Drift, and Model Governance in Enterprise ITComing soon · 2026-10-29 · 7 PM IST
  9. Day 30The 10-Year Horizon: Architecting IT Strategy for the AI-Native EnterpriseComing soon · 2026-10-30 · 7 PM IST
Open the course page →

Day 9: Advanced Prompt Engineering — Few-Shot, Chain-of-Thought and Structured JSON

2026-10-09 · 9 min read

Watch the video lesson, or subscribe on YouTube for a new lesson every day.

Prompt engineering is not just talking to a chatbot. It is the programmable interface that lets you get dependable, repeatable results from an AI, and in an automated system, dependable is the whole point.

In plain terms: Imagine briefing a new colleague. "Sort these tickets" gets you a guess. A short brief, a couple of worked examples, and a note on how you want the result written down gets you what you actually need. A good prompt is that brief.

Rolewho the model should act asTaskwhat to do, in one clear sentenceContextthe facts it should useExamplestwo or three worked samplesFormatthe exact output shape, such as JSONRuleswhat not to do, and when to say "I don't know"Anatomy of a strong promptClear parts give the model less room to guess.
A strong prompt has clear parts: a role, a task, context, examples, an output format and rules. Each part removes guesswork for the model.

1. Few-shot prompting

With zero-shot prompting you give only an instruction. With few-shot prompting you add two or three perfectly formatted examples of the input and the output you want. The examples ground the model: it copies the pattern, so the answers come back in the same shape every time.

Zero-shotFew-shot Classify this ticket:"VPN keeps dropping"Ticket: "Disk full" → HardwareTicket: "Login fails" → IdentityClassify: "VPN keeps dropping"(2 examples included) It seems like a network problem?Probably NETWORK or maybe VPNNetwork / VPN issue (high priority)NetworkSame format, every timeFree-form, hard to use in codeConsistent and parseable
Zero-shot gives only an instruction, so answers vary in wording and format. Few-shot adds two or three worked examples, which anchors the model to the exact format you want.

2. Chain-of-thought (CoT)

Chain-of-thought prompting asks the model to write out its reasoning step by step before it gives the final answer. If you ask an AI to analyse the dividend yield of a real-estate trust, making it do the maths in order, instead of jumping to a number, greatly reduces logic errors. A simple way to ask is: "Work through this step by step, then give the final answer on a new line."

A REIT pays ₹2.50 a quarter. The price is ₹125.What is the yearly dividend yield? Rushed answer"2%"used the quarterly amount Step by step 1. Year = 2.50 × 4 = ₹102. Yield = 10 ÷ 125 = 0.083. Answer: 8%Looks plausible,but it is wrong. Asking for the steps first reduces logic errors.
Chain-of-thought asks the model to show its reasoning before the final answer. On a multi-step calculation, working through the steps in order cuts down careless logic errors.

3. Structured JSON output

In automated workflows, free text is not much use. If the answer must go into a database or another program, you have to constrain the prompt so the model returns a strict JSON structure that code can parse. Many AI platforms now also offer a built-in structured-output mode that enforces a schema.

Free text"Sure! The ticket is..."JSON schema{"team": "network"} Yourcode ✗cannot parse✓saved to database In automation, text is useless. Structure is useful.Ask for a strict schema so the answer drops straight into your systems.
Chatty free text cannot be parsed reliably. Constraining the model to a JSON schema lets the answer flow straight into databases and application code.

Here is a small, runnable example that builds a few-shot prompt and then checks the reply before trusting it. (It does not call a model: it shows what you send and how you validate what comes back.)

import json

# 1. A few-shot prompt: two worked examples, then the new ticket
examples = [
    ("Disk is full on the file server", {"team": "hardware", "priority": "medium"}),
    ("Cannot log in after the password reset", {"team": "identity", "priority": "high"}),
]
prompt = "Classify each IT ticket. Reply with JSON only, using keys team and priority.\n\n"
for text, answer in examples:
    prompt += f'Ticket: "{text}"\nAnswer: {json.dumps(answer)}\n\n'
prompt += 'Ticket: "VPN keeps dropping every few minutes"\nAnswer:'
print(prompt)

# 2. Whatever the model replies, check it before your code trusts it
def parse_ticket(reply: str) -> dict:
    data = json.loads(reply)                          # fails if the reply is not valid JSON
    assert set(data) == {"team", "priority"}, "unexpected keys"
    assert data["priority"] in {"low", "medium", "high"}, "bad priority"
    return data

print(parse_ticket('{"team": "network", "priority": "high"}'))     # accepted
try:
    parse_ticket("Sure! The ticket looks like a network issue.")   # chatty text is rejected
except Exception as err:
    print("rejected:", type(err).__name__)

Even with a good prompt, a model can occasionally break the format, so the checking step matters.

Choosing the technique

Need the same formatevery time?Few-shotshow 2 or 3 examplesyesIs it multi-steplogic or maths?Chain-of-thoughtask for the steps firstyesDoes the output feedcode or a database?Structured JSONforce a schemayesThese techniques combine well: examples, steps and a schema.
Use few-shot examples for a consistent format, chain-of-thought for multi-step reasoning, and a structured JSON schema when the output feeds code. They can be combined.

Coming Up Next

Day 10: Tokenization, context windows and cost optimization.

#PromptEngineering #LLMs #AIImplementation #SoftwareEngineering #Automation