Skip to main content

๐Ÿ“ 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 bananas
    2. Give away 4: 7 - 4 = 3
    3. Receive 5: 3 + 5 = 8
    4. Throw out 3: 8 - 3 = 5

    Final answer: 5 bananas
  • Business-calculation example: suppose a $2,400 project receives a 15%15\% discount, then 8%8\% tax is applied, and three people split the final bill equally:

    1. Discounted price: 2400 ร— (1 - 0.15) = 2040
    2. Tax: 2040 ร— 0.08 = 163.20
    3. Final bill: 2040 + 163.20 = 2203.20
    4. Per-person share: 2203.20 รท 3 = 734.40

    Final 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 typeHow CoT can help
Mathematics and quantitative analysisMakes intermediate calculations and assumptions inspectable
Coding and debuggingEncourages a plan, hypothesis checks, and a path from symptom to likely cause
Rule-based or symbolic problemsApplies explicit conditions in a deliberate order, such as logic puzzles or multi-step transformations
Complex questions and planningSeparates subquestions, trade-offs, and dependencies before synthesizing an answer
Contextual or commonsense questionsMakes 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 >โ€‹

VariantWhat it adds
Zero-shot CoTA generic cue such as โ€œreason step by step,โ€ with no worked examples
Few-shot CoTA few demonstrations that show both the intermediate steps and final-answer format
Least-to-most promptingDecomposes a hard problem into easier subproblems, solves them, then combines the results
Auto-CoTAutomatically constructs or selects reasoning demonstrations for a task; it is not an automatic feature of every LLM
Multimodal CoTUses 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.

    ConceptMeaningExample
    Zero-shot promptingRequest a task without providing worked inputโ€“output demonstrations in the promptGive a VLM a product image and ask, โ€œClassify this product as dress, shirt, or shoesโ€
    Zero-shot image classificationClassify images into target categories without additional training on labeled examples from the target classification taskCLIP 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 >โ€‹

TechniqueWhat the prompt providesBest useMain trade-offExample
Standard promptingDirect task or questionStraightforward requestsLittle guidance for a complex processโ€œThere are 3 bags with 4 apples each. How many apples are there?โ€
Zero-shot promptingInstructions, context, and no examplesA clear task the model already understandsMay be brittle for unfamiliar labels or formatsโ€œReturn only the total number of apples: 3 bags with 4 apples each.โ€
Zero-shot CoTZero-shot prompt plus a reasoning cueMulti-step tasks when no examples are availableLonger 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 promptingA few inputโ€“output examplesNew label schemes, styles, and output formatsUses 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 CoTExamples that include intermediate reasoningDifficult tasks needing both a process and a formatMost 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โ€‹