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.
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:
Copy
Ask AI
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.
Request answers with references to the source material.
Copy
Ask AI
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:
Copy
Ask AI
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.
Question: Which programming language is known for its use in data science and machine learning?A) JavaScriptB) PythonC) C++D) RubyAnswer:
Output:
Copy
Ask AI
B) PythonPython is widely used in data science and machine learning due to its extensive libraries (NumPy, Pandas, Scikit-learn, TensorFlow) and readable syntax.
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:
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:
Copy
Ask AI
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 applesStep 1: Calculate Beck's initial applesBeck initially has: «100 - 23 = 77» applesStep 2: Calculate apples after the transferBoris after giving: «100 - 10 = 90» applesBeck after receiving: «77 + 10 = 87» applesStep 3: Calculate the differenceDifference: «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
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:
Copy
Ask AI
Step 1: Calculate price after first discount (20% off)Original price per item: $5020% discount: «$50 × 0.20 = $10»Price after first discount: «$50 - $10 = $40» per itemStep 2: Calculate total for 4 itemsTotal 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
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:
Copy
Ask AI
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.
Answer questions requiring comparison or analysis.
Copy
Ask AI
Question: Compare the advantages and disadvantages of solar energy versus wind energy for residential use.Structure your answer:1. Solar energy advantages2. Solar energy disadvantages3. Wind energy advantages4. Wind energy disadvantages5. Summary comparisonAnswer:
Output:
Copy
Ask AI
1. Solar Energy Advantages:- Works in most locations with sunlight- Silent operation- Low maintenance- Scalable (from small panels to large arrays)- Decreasing costs2. Solar Energy Disadvantages:- Dependent on sunlight (less effective in cloudy regions)- Requires significant roof space- Energy production varies by season- Initial installation cost3. Wind Energy Advantages:- Generates power day and night- Highly efficient in windy areas- Small footprint- Can be very cost-effective in right locations4. Wind Energy Disadvantages:- Requires consistent wind (not suitable for all locations)- Noise from turbine operation- Visual impact- Potential wildlife concerns- Zoning restrictions in residential areas5. 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.
Question: Will electric vehicles completely replace gasoline cars by 2030?Provide a nuanced answer considering multiple factors:
Output:
Copy
Ask AI
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 productionFactors 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 ratesMost 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.
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:
Copy
Ask AI
Given information:- First segment: 120 miles in 2 hours- Second segment: Speed increases by 20 mph, travels for 3 hoursStep 1: Calculate initial speedSpeed = Distance / Time = 120 miles / 2 hours = 60 mphStep 2: Calculate new speed and distance for second segmentNew speed = 60 mph + 20 mph = 80 mphDistance in second segment = 80 mph × 3 hours = 240 milesStep 3: Calculate total distanceTotal distance = 120 miles + 240 miles = 360 milesFinal answer: The train travels 360 miles in total.
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:
Copy
Ask AI
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 cupsVerification:- 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.
Create a QA system that answers questions based only on provided context.
Sample Solution
Copy
Ask AI
Context: [PROVIDED TEXT]Question: [USER QUESTION]Instructions:1. Answer based ONLY on the provided context2. 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 answer4. Keep answers concise and directAnswer:
Design a prompt for solving word problems with clear reasoning.
Sample Solution
Copy
Ask AI
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]
Create a system for handling complex questions with multiple components.
Sample Solution
Copy
Ask AI
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:
Copy
Ask AI
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 question2. Provide answer based on knowledge base3. Include relevant policy/product references4. Offer additional help if needed5. If information is not in knowledge base, escalate appropriatelyGuidelines:- Be empathetic and professional- Cite specific policies when relevant- Admit when you don't have information- Provide actionable next stepsResponse:
Example:
Copy
Ask AI
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 electronicsCustomer 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, or2. Contact our returns department at returns@company.com to arrange a mail-in returnWould you like me to provide more details about either the return process or warranty service?
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.