Master the art and science of communicating effectively with LLMs. Learn zero-shot and few-shot prompting techniques, Chain-of-Thought reasoning that unlocks step-by-step problem solving, system prompts for controlling model behavior, and structured output techniques for reliable integration with downstream systems.
Prompt engineering is the practice of designing inputs that elicit desired outputs from LLMs. It is the primary interface between human intent and model behavior---no code changes, no fine-tuning, just carefully crafted text. Despite its apparent simplicity, effective prompting can dramatically improve model performance on complex tasks.
The core insight of prompt engineering is that LLMs are sensitive to how questions are framed. The same question asked differently can produce answers that vary from incorrect to expert-level. This sensitivity arises because the model's behavior is shaped by patterns in its training data: it responds differently to a casual question than to a formal academic query, differently to a vague instruction than to a precise one.
Modern prompt engineering has evolved from simple instruction-writing to systematic techniques like Chain-of-Thought (CoT) reasoning, which can improve math accuracy by 50%+, and structured output prompting, which enables reliable integration with software systems. Understanding these techniques is essential for any LLM practitioner.
This chapter covers:
Click any topic to jump in
Clear instructions, role assignment, and task decomposition — getting results without any examples.
In-context learning with demonstrations — how example selection and formatting drive model behavior.
Step-by-step reasoning that unlocks math and logic — zero-shot CoT, few-shot CoT, and self-consistency.
Control and reliability for deployed systems
Persona engineering, guardrails, and behavioral constraints — configuring model behavior at the system level.
JSON mode, schema specification, and constrained decoding — reliable machine-readable output from LLMs.
Zero-shot prompting asks the model to perform a task without providing any examples. The model relies entirely on its pretrained knowledge and instruction-following capabilities. This is the simplest form of prompting and works well for tasks the model has been extensively trained on.
Key insight: The quality of zero-shot prompting depends heavily on how clearly and precisely the instruction is written. Ambiguous prompts produce ambiguous results.
The most important principle: be specific about what you want. Instead of 'summarize this', say 'summarize in 2-3 sentences for a technical audience.' Instead of 'fix this code', say 'identify the bug in this Python function and explain the fix.' Ambiguity in the prompt leads to ambiguity in the output.
Prompt specificity reduces output entropy: a vague prompt gives for a specific prompt , where is the conditional entropy of the model's output distribution. Each constraint in the prompt eliminates a fraction of the output space: with independent constraints each reducing options by half, the remaining space is of the original. In practice, constraints are correlated, so the reduction follows where is the average constraint strength.
Compare the outputs for: (A) "Tell me about dogs" vs (B) "List 5 key facts about domestic dog care that a first-time owner should know, in bullet points."
Assigning a role or persona to the model changes its response style and expertise level. "You are an expert cardiologist" produces more medically precise responses than "answer this health question." The role primes the model to access relevant knowledge patterns and adopt the appropriate communication style.
Role assignment shifts the model's conditional distribution from to . By Bayes' rule, this is proportional to — the model up-weights responses that are consistent with the assigned role. The effectiveness depends on how well the role is represented in pretraining data: 'expert cardiologist' activates patterns from medical texts (high-quality training signal), while 'alien from planet Zorg' has no grounding and mainly affects style. The expected quality improvement is proportional to — larger distributional shifts indicate the role is having more effect.
Ask "What causes chest pain?" with (A) no role and (B) "You are an emergency medicine physician."
For complex tasks, break the prompt into explicit steps. Instead of 'analyze this data', specify: 'Step 1: Identify the main trends. Step 2: Note any anomalies. Step 3: Suggest three possible causes. Step 4: Recommend next steps.' This guides the model through a logical sequence and ensures completeness.
Decomposing a task into sequential steps reduces the effective complexity from to where is the complexity per step. This is because the model processes one step at a time, each with bounded context. The error probability also changes: for independent steps with per-step error , the overall success probability is for small . With steps and per step, overall success is ~77%. Without decomposition, the single-step error for the full task might be 50%+ because the model must implicitly manage all subtasks simultaneously.
You need a model to review a pull request. Write a zero-shot prompt with task decomposition.
Telling the model what NOT to do is often as important as telling it what to do. 'Do not include disclaimers', 'Do not use technical jargon', 'Do not make up information---say "I don't know" if uncertain.' Negative instructions constrain the output space and prevent common failure modes.
Negative instructions ('do not X') constrain the output distribution by zeroing out probability mass on undesired outputs: . The effectiveness depends on how much probability mass the model originally placed on forbidden outputs. If , then after the constraint, the remaining outputs are renormalized by . A common failure mode: the constraint is too vague ("don't be verbose") so is not well-defined, and the model cannot reliably exclude those outputs.
A model keeps adding 'I hope this helps!' to every response. How do you fix this?
You need an LLM to extract key information from job postings. Design a zero-shot prompt that extracts: job title, company, location, salary range, required skills, and experience level. The output should be structured.