Library

Volume 2 · Prompt Engineering

Notebook
Sign in

Section 11

Prompting Techniques

533 words · about 2 min

11.1 Zero-Shot Prompting

Direct instruction with no examples.

Classify the following customer feedback as Positive, Negative, or Neutral:
"The product arrived quickly but the packaging was damaged."

Classification:

11.2 Few-Shot Prompting

Provide examples to establish the pattern.

Classify customer feedback:

Feedback: "Amazing product, will buy again!" → Positive
Feedback: "Terrible experience, want a refund" → Negative
Feedback: "It works fine, nothing special" → Neutral

Feedback: "The product arrived quickly but the packaging was damaged."
Classification:

11.3 Chain-of-Thought (CoT) Prompting

Forces step-by-step reasoning for complex tasks.

Question: A RAG system processes 10,000 queries/day. Each query retrieves
5 chunks of 512 tokens. The embedding model costs $0.0001/1000 tokens and
the LLM costs $0.01/1000 tokens. What is the daily retrieval-related cost?

Think step by step:
1. Tokens per query for retrieval: 5 chunks × 512 tokens = 2,560 tokens
2. Chunks are pre-embedded, so retrieval cost is only query embedding + LLM context cost
3. Query embedding: 10,000 queries × ~100 tokens/query = 1,000,000 tokens
4. Query embedding cost: 1,000,000 / 1000 × $0.0001 = $0.10/day
5. LLM input (retrieved context): 25,600,000 / 1000 × $0.01 = $256/day
6. Total daily retrieval-related cost: $256.10/day

11.4 Self-Consistency

Generate multiple independent CoT reasoning paths and take the majority/consensus answer — improves reliability on tasks with a single correct answer at the cost of multiple LLM calls.

Generate 5 independent analyses of this business problem.
For each, reason step by step to reach a conclusion.
Then provide the consensus answer across all 5 analyses.

11.5 ReAct (Reasoning + Acting)

Interleaves thinking with tool use — the dominant pattern for production agentic systems (see Section 26 for the full agent-loop treatment).

Question: What is the current stock price of MSFT and how does it compare to its 52-week high?

Thought: I need to look up the current MSFT stock price and its 52-week high.
Action: search_stock(ticker="MSFT")
Observation: MSFT current price: $425.30, 52-week high: $468.35, 52-week low: $380.21

Thought: I can now calculate the comparison. $425.30 is $43.05 below the 52-week high,
which is about 9.2% below the high.
Answer: MSFT is currently trading at $425.30, which is 9.2% below its 52-week high of $468.35.

11.6 Tree of Thoughts (ToT)

Explores multiple solution branches, scoring and pruning as it goes — most useful for problems with several plausible approaches and no single obvious path.

Consider three different architectural approaches for this system:

Approach A: [Microservices with event-driven architecture]
- Pros: ...  Cons: ...  Feasibility score: X/10

Approach B: [Modular monolith with async processing]
...

Approach C: [Serverless with managed services]
...

Based on the analysis, the recommended approach is...

Section 11 — Interview Q&A

Q: When would you use Self-Consistency vs. plain Chain-of-Thought? A: Plain CoT is sufficient for most reasoning tasks — it forces the model to externalize intermediate steps, which improves accuracy on multi-step problems at essentially no extra cost. Self-Consistency is worth the extra API calls (typically 3-5x cost) specifically when a task has a single objectively correct answer and errors are costly — e.g., a numeric calculation, a classification with real business consequences, or a high-stakes decision — where taking a majority vote across independently-sampled reasoning paths measurably reduces the error rate versus a single CoT pass.