๐ Prompt Engineering
Descriptionโ
< What is it? >โ
Prompt engineering is the practice of writing and evaluating instructions that guide an LLM toward a useful, accurate, and well-formatted result. A prompt supplies the task, relevant context, constraints, and desired outputโnot new model knowledge or permanently changed weights.
Application prompting needs more rigor than a personal chat prompt: it should work reliably across varied inputs, be evaluated on representative cases, and define what to do when information is missing or uncertain.
Key pointsโ
< Writing a reliable prompt >โ
- Be clear: use precise, unambiguous instructions.
- Be complete: provide the context, constraints, and data the model needs.
- Specify the output: state the format, length, audience, and any required fields.
- Organize the prompt: place critical instructions prominently and use consistent terminology.
- Test systematically: evaluate representative and difficult cases instead of trusting one good-looking answer.
- State positive actions: say what the model should do, not only what it should avoid.
< Chain-of-thought (CoT) prompting >โ
Chain of thought (CoT) asks a model to produce a logical sequence of intermediate steps before its final answer. It can help a capable model break a complex task into smaller, checkable subproblems instead of jumping directly from the question to an answer.
-
Word-problem example:
Prompt: Solve step by step. You have 7 bananas, give 4 to a friend,receive 5 more, then throw out 3 rotten bananas. How many remain?Concise reasoning:1. Start with 7 bananas2. Give away 4: 7 - 4 = 33. Receive 5: 3 + 5 = 84. Throw out 3: 8 - 3 = 5Final answer: 5 bananas -
Business-calculation example: suppose a $2,400 project receives a discount, then tax is applied, and three people split the final bill equally:
1. Discounted price: 2400 ร (1 - 0.15) = 20402. Tax: 2040 ร 0.08 = 163.203. Final bill: 2040 + 163.20 = 2203.204. Per-person share: 2203.20 รท 3 = 734.40Final answer: $734.40 per person
CoT prompting changes the prompt, not the model weights. Post-training can additionally teach a reasoning model to spend more tokens on difficult, verifiable problems through supervised fine-tuning or reinforcement learning.
< When CoT helps >โ
| Task type | How CoT can help |
|---|---|
| Mathematics and quantitative analysis | Makes intermediate calculations and assumptions inspectable |
| Coding and debugging | Encourages a plan, hypothesis checks, and a path from symptom to likely cause |
| Rule-based or symbolic problems | Applies explicit conditions in a deliberate order, such as logic puzzles or multi-step transformations |
| Complex questions and planning | Separates subquestions, trade-offs, and dependencies before synthesizing an answer |
| Contextual or commonsense questions | Makes the relevant constraints explicit, rather than relying on an unexplained conclusion |
For a simple fact lookup, classification, or creative-writing request, CoT often adds tokens and latency without improving the outcome.
< Designing a CoT prompt >โ
Ask for the task, the needed reasoning format, and the final output explicitly. A practical pattern is:
1. State assumptions or missing information.
2. Solve the relevant subproblems in order.
3. Check constraints or calculations.
4. Return a concise final answer in the requested format.
Useful instructions include Explain why, State your reasoning briefly, First determine ___, then identify ___, and If ___, then do ___; otherwise ___. For a recurring task, add verified examples and evaluate the result on cases that differ from those examples.
The visible rationale is generated text, not proof that every step is correct or a faithful record of the modelโs internal computation. Use it to make assumptions and calculations easier to review, then verify important answers with tools, tests, or source material.
< Common CoT variants >โ
| Variant | What it adds |
|---|---|
| Zero-shot CoT | A generic cue such as โreason step by step,โ with no worked examples |
| Few-shot CoT | A few demonstrations that show both the intermediate steps and final-answer format |
| Least-to-most prompting | Decomposes a hard problem into easier subproblems, solves them, then combines the results |
| Auto-CoT | Automatically constructs or selects reasoning demonstrations for a task; it is not an automatic feature of every LLM |
| Multimodal CoT | Uses images, audio, video, or other modalities as part of the reasoning context when the model supports them |
Comparisonโ
< Zero-shot prompting vs. zero-shot image classification >โ
-
Different scopes: zero-shot prompting describes the examples supplied in a prompt, while zero-shot image classification describes how a model is applied to a target classification task.
Concept Meaning Example Zero-shot prompting Request a task without providing worked inputโoutput demonstrations in the prompt Give a VLM a product image and ask, โClassify this product as dress, shirt, or shoesโ Zero-shot image classification Classify images into target categories without additional training on labeled examples from the target classification task CLIP compares a dress image with text descriptions such as โa dress,โ โa shirt,โ and โshoes,โ then selects the highest-scoring match The prompting distinction follows the in-context evaluation settings in Language Models are Few-Shot Learners; CLIP demonstrates classification without dataset-specific training.
-
What counts as a demonstration: instructions, candidate labels, and the input to be classified do not constitute worked examples. An additional image paired with its correct label would be a demonstration. A zero-shot prompt can therefore include an image, an article, and a list of allowed labels.
-
Overlap: a pretrained generative VLM can perform zero-shot image classification through zero-shot prompting. However, the absence of demonstrations in the prompt does not establish whether the model was previously fine-tuned on that target task. Zero-shot transfer also does not imply that relevant concepts were absent from pretraining.
-
Examples in these notes: the CLIP dress example demonstrates zero-shot image classification through imageโtext similarity. The Qwen news example uses zero-shot prompting to request an impact label and explanation from an article and image.
< CoT vs other prompting patterns >โ
| Technique | What the prompt provides | Best use | Main trade-off | Example |
|---|---|---|---|---|
| Standard prompting | Direct task or question | Straightforward requests | Little guidance for a complex process | โThere are 3 bags with 4 apples each. How many apples are there?โ |
| Zero-shot prompting | Instructions, context, and no examples | A clear task the model already understands | May be brittle for unfamiliar labels or formats | โReturn only the total number of apples: 3 bags with 4 apples each.โ |
| Zero-shot CoT | Zero-shot prompt plus a reasoning cue | Multi-step tasks when no examples are available | Longer output; not guaranteed to improve accuracy | โThere are 3 bags with 4 apples each. How many apples are there? Work through the calculation step by step.โ |
| Few-shot prompting | A few inputโoutput examples | New label schemes, styles, and output formats | Uses context and may overfit to the examples | โQ: 2 bags, 3 apples each. A: 6. Q: 4 bags, 2 apples each. A: 8. Q: 3 bags, 4 apples each. A:โ |
| Few-shot CoT | Examples that include intermediate reasoning | Difficult tasks needing both a process and a format | Most context-heavy prompting option in this table | โQ: 2 bags, 3 apples each. A: Multiply bags by apples per bag: 2 ร 3 = 6 apples. Q: 4 bags, 2 apples each. A: Multiply bags by apples per bag: 4 ร 2 = 8 apples. Q: 3 bags, 4 apples each. A:โ |
CoT is not automatically more accurate or more debuggable than every alternative. It is most valuable when the intermediate work can be checked; otherwise, a polished explanation can still hide a wrong conclusion.
Implementationโ
Video Tutorialโ
Referenceโ
- Language Models are Few-Shot Learners
- CLIP: Learning Transferable Visual Models From Natural Language Supervision
- Prompt Engineering with LangChain | DataCamp
- Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (Wei et al., 2022)
- Least-to-Most Prompting Enables Complex Reasoning in Large Language Models (Zhou et al., 2022)
- Automatic Chain of Thought Prompting in Large Language Models (Zhang et al., 2022)
- Chain of thought prompting (aws)
- Language Models Perform Reasoning via Chain of Thought (Google Research)