Skip to main content
Duration: 45 minutes

Introduction

Question-answering is one of the most practical applications of LLMs—from customer support chatbots to educational tutors. But getting accurate, reliable answers requires more than just asking questions. In this lesson, you’ll learn patterns that ensure your QA systems provide well-reasoned, verifiable answers.

The QA Challenge

Common QA Problems:
  • Hallucinated facts or made-up information
  • Incomplete reasoning
  • Answers that don’t address the actual question
  • Lack of transparency in how conclusions were reached
The solution? Structured reasoning patterns that make the thinking process explicit.

Basic QA Patterns

Open-Domain QA

Answer questions without provided context.
Question: What is the capital of France?

Answer:
Output:
Paris
Best for: Factual questions with well-established answers. Use with caution for questions requiring current information or specialized knowledge.

QA with Context

Provide relevant context to ground the answer.
Context: "The Amazon rainforest spans 5.5 million square kilometers across nine countries. Brazil contains approximately 60% of the rainforest, followed by Peru with 13% and Colombia with 10%."

Question: Which country has the largest portion of the Amazon rainforest?

Answer:
Output:
Brazil has the largest portion of the Amazon rainforest, containing approximately 60% of it.
Pro Tip: Always provide context when available—it dramatically improves accuracy and reduces hallucinations.

QA with Source Citation

Request answers with references to the source material.
Context: "Recent studies show that regular exercise can improve cognitive function. A 2023 study published in the Journal of Neuroscience found that participants who exercised 30 minutes daily showed 15% improvement in memory tests compared to sedentary controls."

Question: How does exercise affect cognitive function?

Answer with citation:
Output:
According to the provided context, regular exercise can improve cognitive function. Specifically, a 2023 study in the Journal of Neuroscience found that participants who exercised 30 minutes daily showed a 15% improvement in memory tests compared to those who didn't exercise.

Multiple-Choice Questions

Basic Multiple Choice

Question: Which programming language is known for its use in data science and machine learning?

A) JavaScript
B) Python
C) C++
D) Ruby

Answer:
Output:
B) Python

Python is widely used in data science and machine learning due to its extensive libraries (NumPy, Pandas, Scikit-learn, TensorFlow) and readable syntax.

Multiple Choice with Reasoning

Request explanation along with the answer.
Question: A company's revenue increased from $100M to $150M. What is the percentage increase?

A) 25%
B) 33%
C) 50%
D) 150%

Provide your reasoning, then select the answer.

Reasoning:
Answer:
Output:
Reasoning:
- Initial revenue: $100M
- Final revenue: $150M
- Increase: $150M - $100M = $50M
- Percentage increase: ($50M / $100M) × 100 = 50%

Answer: C) 50%

Math Word Problems

Structured Math Problem Solving

Use the GSM8K annotation style for clarity.
Question: Boris has 100 apples. Beck has 23 fewer apples than Boris. If Boris gives Beck 10 apples, how many fewer apples does Beck have than Boris now?

Solve step-by-step using this format:
- State what we know
- Calculate intermediate values using «calculation» notation
- Show final answer with ####

Solution:
Output:
Let's work through this step-by-step:

What we know:
- Boris starts with 100 apples
- Beck has 23 fewer apples than Boris initially
- Boris gives Beck 10 apples

Step 1: Calculate Beck's initial apples
Beck initially has: «100 - 23 = 77» apples

Step 2: Calculate apples after the transfer
Boris after giving: «100 - 10 = 90» apples
Beck after receiving: «77 + 10 = 87» apples

Step 3: Calculate the difference
Difference: «90 - 87 = 3» apples

#### 3
GSM8K Format:
  • Use «calculation» for intermediate steps
  • Show #### before the final numerical answer
  • This format helps track reasoning and catch errors

Multi-Step Math Problems

Break complex problems into clear steps.
Question: A store offers a 20% discount on all items. If you buy 3 or more items, you get an additional 10% off the discounted price. What is the final price of 4 items originally priced at $50 each?

Solve step-by-step:
Output:
Step 1: Calculate price after first discount (20% off)
Original price per item: $50
20% discount: «$50 × 0.20 = $10»
Price after first discount: «$50 - $10 = $40» per item

Step 2: Calculate total for 4 items
Total before additional discount: «$40 × 4 = $160»

Step 3: Apply additional discount (10% off for 3+ items)
Additional discount: «$160 × 0.10 = $16»
Final price: «$160 - $16 = $144»

#### $144

Complex QA with Sub-Questions

Decomposition Strategy

Break complex questions into manageable parts.
Question: How has climate change affected polar bear populations, and what conservation efforts are being implemented?

Break this into sub-questions and answer each:

Sub-question 1:
Sub-question 2:
Sub-question 3:

Final comprehensive answer:
Output:
Sub-question 1: How has climate change affected polar bears?
Answer: Climate change has reduced Arctic sea ice, which polar bears depend on for hunting seals. This has led to longer fasting periods, reduced body condition, and lower survival rates, particularly for cubs.

Sub-question 2: What is the current status of polar bear populations?
Answer: Polar bear populations vary by region, with some declining and others stable. Overall, they are classified as vulnerable, with an estimated 22,000-31,000 individuals remaining.

Sub-question 3: What conservation efforts are being implemented?
Answer: Conservation efforts include: protecting critical habitat, reducing human-polar bear conflicts, monitoring population health, international agreements (like the Polar Bear Agreement), and addressing climate change through emissions reduction.

Final comprehensive answer:
Climate change has significantly impacted polar bears by reducing the Arctic sea ice they depend on for hunting, leading to nutritional stress and population declines in some regions. With an estimated 22,000-31,000 polar bears remaining and classified as vulnerable, conservation efforts focus on habitat protection, conflict reduction, population monitoring, and international cooperation. However, long-term survival ultimately depends on addressing climate change itself through global emissions reduction.

Comparative Questions

Answer questions requiring comparison or analysis.
Question: Compare the advantages and disadvantages of solar energy versus wind energy for residential use.

Structure your answer:
1. Solar energy advantages
2. Solar energy disadvantages
3. Wind energy advantages
4. Wind energy disadvantages
5. Summary comparison

Answer:
Output:
1. Solar Energy Advantages:
- Works in most locations with sunlight
- Silent operation
- Low maintenance
- Scalable (from small panels to large arrays)
- Decreasing costs

2. Solar Energy Disadvantages:
- Dependent on sunlight (less effective in cloudy regions)
- Requires significant roof space
- Energy production varies by season
- Initial installation cost

3. Wind Energy Advantages:
- Generates power day and night
- Highly efficient in windy areas
- Small footprint
- Can be very cost-effective in right locations

4. Wind Energy Disadvantages:
- Requires consistent wind (not suitable for all locations)
- Noise from turbine operation
- Visual impact
- Potential wildlife concerns
- Zoning restrictions in residential areas

5. Summary Comparison:
Solar energy is more universally applicable for residential use due to its silent operation and broader geographic suitability, though it's limited by daylight hours. Wind energy can be more efficient in windy locations but faces more restrictions and practical challenges in residential settings. For most homeowners, solar is the more practical choice, while wind works best in rural areas with consistent wind and fewer restrictions.

Handling Uncertainty

Admitting Unknown Information

Context: "The company was founded in 2010 and has offices in New York and London."

Question: How many employees does the company have?

Answer:
Output:
The provided context does not include information about the number of employees. I cannot answer this question based on the given information.
Best Practice: Always admit when information isn’t available rather than guessing or hallucinating.

Qualified Answers

Provide answers with appropriate caveats.
Question: Will electric vehicles completely replace gasoline cars by 2030?

Provide a nuanced answer considering multiple factors:
Output:
It's unlikely that electric vehicles will completely replace gasoline cars by 2030, though they will likely capture a significant market share. Several factors support this assessment:

Factors favoring EV adoption:
- Improving battery technology and decreasing costs
- Expanding charging infrastructure
- Government incentives and regulations
- Major automaker commitments to EV production

Factors limiting complete replacement:
- Infrastructure challenges in rural and developing areas
- Higher upfront costs (though decreasing)
- Range anxiety for some consumers
- Existing fleet of gasoline vehicles (takes years to replace)
- Regional variations in adoption rates

Most experts predict EVs will represent 30-50% of new car sales by 2030 in developed markets, but complete replacement of the existing gasoline vehicle fleet will take decades longer.

Structured Reasoning Format

Chain of Reasoning

Make the thinking process explicit.
Question: If a train travels 120 miles in 2 hours, then increases its speed by 20 mph for the next 3 hours, how far does it travel in total?

Use this format:
Given information:
Step 1:
Step 2:
Step 3:
Final answer:
Output:
Given information:
- First segment: 120 miles in 2 hours
- Second segment: Speed increases by 20 mph, travels for 3 hours

Step 1: Calculate initial speed
Speed = Distance / Time = 120 miles / 2 hours = 60 mph

Step 2: Calculate new speed and distance for second segment
New speed = 60 mph + 20 mph = 80 mph
Distance in second segment = 80 mph × 3 hours = 240 miles

Step 3: Calculate total distance
Total distance = 120 miles + 240 miles = 360 miles

Final answer: The train travels 360 miles in total.

Verification Step

Include a verification or sanity check.
Question: A recipe calls for 2 cups of flour for 12 cookies. How much flour is needed for 30 cookies?

Solve and verify your answer:
Output:
Solution:
- Original ratio: 2 cups flour for 12 cookies
- Flour per cookie: 2 ÷ 12 = 1/6 cup per cookie
- For 30 cookies: 30 × (1/6) = 5 cups

Verification:
- Check: 5 cups ÷ 2 cups = 2.5
- 30 cookies ÷ 12 cookies = 2.5
- The ratios match ✓

Answer: 5 cups of flour are needed for 30 cookies.

Best Practices

Provide Context

Always include relevant context when available

Show Reasoning

Make the thinking process explicit and verifiable

Admit Uncertainty

Acknowledge when information is insufficient

Verify Answers

Include sanity checks for numerical or logical answers

Practice Exercises

Exercise 1: Context-Based QA

Create a QA system that answers questions based only on provided context.
Context: [PROVIDED TEXT]

Question: [USER QUESTION]

Instructions:
1. Answer based ONLY on the provided context
2. If the answer is not in the context, state: "This information is not provided in the context"
3. Quote relevant parts of the context to support your answer
4. Keep answers concise and direct

Answer:

Exercise 2: Math Problem Solver

Design a prompt for solving word problems with clear reasoning.
Solve this math word problem step-by-step:

Problem: [WORD PROBLEM]

Format:
Given information:
- [List what we know]

Step-by-step solution:
Step 1: [First calculation]
«calculation»

Step 2: [Next calculation]
«calculation»

Step 3: [Final calculation]
«calculation»

Verification:
[Check if answer makes sense]

#### [Final numerical answer]

Exercise 3: Multi-Part Question Handler

Create a system for handling complex questions with multiple components.
Question: [COMPLEX QUESTION]

Analysis:
This question has [NUMBER] parts:
1. [First part]
2. [Second part]
3. [Third part]

Answers:

Part 1: [First part question]
Answer: [Detailed answer with reasoning]

Part 2: [Second part question]
Answer: [Detailed answer with reasoning]

Part 3: [Third part question]
Answer: [Detailed answer with reasoning]

Summary:
[Synthesize all parts into cohesive answer]

Real-World Application: Customer Support QA System

Build a comprehensive customer support QA system:
You are a customer support assistant. Answer questions based on the provided knowledge base.

Knowledge Base:
[COMPANY POLICIES, PRODUCT INFO, FAQ]

Customer Question: [QUESTION]

Response Format:
1. Acknowledge the question
2. Provide answer based on knowledge base
3. Include relevant policy/product references
4. Offer additional help if needed
5. If information is not in knowledge base, escalate appropriately

Guidelines:
- Be empathetic and professional
- Cite specific policies when relevant
- Admit when you don't have information
- Provide actionable next steps

Response:
Example:
Knowledge Base:
- Return policy: 30 days with receipt
- Shipping: 5-7 business days standard, 2-3 days express
- Warranty: 1 year manufacturer warranty on all electronics

Customer Question: "I bought a laptop 2 weeks ago and it's not working. Can I return it?"

Response:

Thank you for reaching out about your laptop issue. I'm sorry to hear you're experiencing problems with your recent purchase.

Based on our return policy, yes, you can return the laptop. Since you purchased it 2 weeks ago, you're well within our 30-day return window. You'll need your receipt for the return process.

Additionally, since this is an electronics item, it's covered by a 1-year manufacturer warranty. Depending on the issue, a warranty repair might be another option if you'd prefer to keep the laptop.

Next steps:
1. Bring the laptop and receipt to any of our stores, or
2. Contact our returns department at returns@company.com to arrange a mail-in return

Would you like me to provide more details about either the return process or warranty service?

Key Takeaways

Always provide context when available to ground answers
Use structured reasoning formats for complex questions
Show step-by-step calculations for math problems
Admit when information is insufficient or uncertain
Include verification steps for numerical answers
Break complex questions into manageable sub-questions

Module 2 Complete!

Congratulations! You’ve mastered task-specific prompting patterns for classification, extraction, generation, transformation, and question-answering. You’re now ready to tackle the Module 2 assessment.

Next: Module 2 Assessment

Test your skills with the Content Moderation System capstone project
I