Lessons
1 · Understanding Modern AI
2 · Talking to AI Effectively
3 · AI for Learning
4 · AI for Work and Productivity
5 · AI for Developers
- 17AI Coding Assistants: Modes, Strengths and Your Responsibility
- 18Use AI to Understand Code, Codebases, APIs and Documentation
- 19How to Use AI to Debug Code Safely
- 20Testing, Reviewing and Refactoring AI-Generated Code
- 21Security and Licensing Risks of AI-Generated Code
- 22Vibe Coding vs Responsible AI-Assisted Building
6 · AI for Career Growth
7 · Research, Verification and Responsible AI
8 · Automation and AI Agents
Lesson 7 · Talking to AI Effectively
Give AI the Right Context: Source Material and Long Documents
The single biggest upgrade to AI answers is not a cleverer prompt. It is giving the model the right material to work from and making it show where each claim came from. This article teaches grounding, quote-first answers and how to handle long documents.
For
Students and professionals who want AI to work from their documents and notes, and to reduce invented answers.
Level
Before you start
Read Prompt Fundamentals (article 6) and the section on context windows in How Language Models Work (article 3).
On this page
Key takeaways
- Replacing "what do you know?" with "read this and answer from it" turns a guessing task into a reading task, which is easier to check.
- Label your sources, say what to do when the answer is not in them, and ask for supporting quotes before conclusions.
- For long documents, focus the input, work in stages, or split into parts. Do not assume the model read every line equally.
- Always verify that quotes exist in the source and say what the answer claims. Grounding reduces errors but does not remove them.
- Material you supply can also be wrong, outdated or hostile. Choose it carefully and never paste confidential data into tools you are not allowed to use.
Ask an assistant, "What does my college's attendance policy say about medical leave?" and it will happily answer. It has never seen your college's policy. It will produce what a typical attendance policy says, in the confident voice of someone who has read yours.
The fix is almost embarrassingly simple: give it the policy. But how you give it, and what you ask it to do with it, decides whether you get a reliable answer or a more convincing guess.
What you will learn
#- What grounding is and why it is the most effective single technique for factual tasks.
- A reusable pattern for supplying sources: label, instruct, quote, cite.
- How to work with documents that are too long or messy.
- How to check that the answer really came from the source.
- What can go wrong even when you supply the material.
The idea in plain words
#There are two ways to ask a question:
- From memory: "What does the policy say?" The model answers from patterns in its training. It cannot see your document, so it is guessing what documents of that type usually say.
- From the page: "Here is the policy. What does it say about medical leave?" The model reads what you gave it and answers from that text.
The second is called grounding: tying the answer to specific source material. It does not make the model infallible, but it changes the job from recall to reading comprehension, and reading is both easier for the model and much easier for you to verify. You can compare the answer with the page.
The source-material pattern
#Use this four-part pattern whenever facts matter.
1. Label and separate the material. Make it obvious where your instructions end and the source begins. Delimiters work well: markdown headings, triple dashes or tags. OpenAI's prompting guide mentions using Markdown headers and XML tags to create logical boundaries, and Anthropic's examples wrap documents in tags. Pick one style and use it consistently.
2. Say what the model may use. For example: "Answer using only the text between the tags. Do not use outside knowledge."
3. Give it a safe way out. "If the text does not answer the question, write 'not stated in the text'." Anthropic's guidance on reducing hallucinations recommends permitting the model to say it does not know, because otherwise guessing is the only way to produce an answer.
4. Ask for evidence. "For each point, quote the exact sentence that supports it." The same documentation recommends having the model extract word-for-word quotes first for long documents, then base its analysis on them, and verify claims with citations, retracting any that it cannot support.
Together:
Task: answer my question using only the document below.Rules:- If the document does not say, write "not stated".- For every point, give the exact quote that supports it, in quotation marks.- Do not add background knowledge.Question: Can I get an attendance exemption for medical leave, and what proof is needed?<document>[paste the policy section here]</document>A worked example
#Goal. Find out whether you can get an attendance exemption.
Initial request, with no grounding.
Does my college allow attendance exemptions for medical leave?What goes wrong. The assistant cannot know. It may answer, "Yes, with a medical certificate, typically within seven days." It sounds plausible, and it is a guess based on typical policies.
Improved request. The pattern above with the real section pasted in.
Example response (illustrative, as the real answer depends on your document).
Yes, in some cases. The document says: "Students with a medical certificatefrom a registered practitioner may apply for condonation of shortage of up to10 percent." Proof needed: "a medical certificate" (the text does not say howmany days after the absence it must be submitted: not stated).Verify. You search the document for the quoted phrase. Two failure modes are possible and both are easy to spot: the quote does not exist (invented), or it exists but says something different from the claim (misread). Here, you also notice that the answer admits one detail is "not stated". That is the safe way out working correctly. You then go to the college office for that missing detail instead of accepting a guess.
The workflow. Ground, require quotes, allow "not stated", then verify quotes against the page. Four steps, and each one removes a way for the answer to go wrong.
Ways to put context in front of a model
#Method | What it looks like | Watch out for |
|---|---|---|
Paste text | You copy the relevant section into the message | You control exactly what it sees. Best for short material |
Attach a file | Upload a PDF, document or spreadsheet | Text extraction can lose tables, headers, footnotes, or fail on scanned pages. Spot-check that it "read" what you think |
Tool retrieval | A search tool, notebook tool or workplace assistant fetches relevant passages for you | You do not see exactly what was retrieved. Open the sources it shows |
Standing instructions | A settings field or memory feature that applies to all chats | Can become outdated or conflict with your current task. Keep it short and review it |
Connectors | The assistant reaches into your calendar, email or files | More access, more risk. See Privacy and Security |
Long documents
#Bigger context windows let you paste whole reports, but longer is not automatically better. As the "Lost in the Middle" study found, models often use information at the start and end of a long input better than information in the middle. Newer models may differ, but the safe approach is the same.
Three strategies:
- Focus. Paste only the sections that matter. If you do not know which, ask the model to list the section headings and tell you which are likely to be relevant, then paste those. Fewer, more relevant tokens beat more, noisier ones.
- Stage the work. First request: "Extract every sentence that mentions deadlines, exactly as written, with section numbers." Second request, using that extract: "Now list the deadlines in date order." The extraction can be checked against the document, and the second step works on a short, reliable list.
- Split and combine. Process the document in parts (chapters, sections), take notes per part, then ask for a combined view. Keep each part's quotes so you can trace claims back.
A good habit is to make long-document answers navigable: ask for section numbers or page references, so you can jump to the source in seconds.
Context hygiene
#- Relevance beats volume. Remove boilerplate, signatures, unrelated emails, old threads.
- Say what each source is. "Source A: official circular dated 12 March. Source B: a news article." The model can then reason about reliability, and so can you.
- Include dates. Add "today is 5 October 2026" for time-sensitive work, and say how recent each source is.
- Handle conflicts explicitly. "If the sources disagree, show both versions and do not pick one."
- Keep a clean thread. If a long chat is cluttered or has gone off track, start a new one with a short summary of the key facts.
- Do not supply what you should not share. Anything you paste is processed by the product. If the document is confidential or contains personal data, check your policy first.
What can still go wrong
#Grounding reduces errors but does not remove them:
- Misreading. The answer cites a real quote but draws the wrong conclusion from it.
- Selective reading. It found one relevant sentence and missed a later exception ("except where...").
- Hidden gaps. The retrieval step or the attachment parser missed part of the material.
- Bad sources. The text you gave is wrong, out of date, or one-sided. The model has no way to know.
- Hostile text. A pasted web page or email can contain instructions aimed at the model ("ignore the above and..."). This is called prompt injection, and article 28 covers it. Be especially careful with text from sources you do not control.
The honest summary: grounding moves the problem from "did it invent this?" to "did it read this correctly?", and the second question is cheaper to answer.
Common mistakes
#- Asking about a document without supplying it, or assuming a link is enough. The model may not open links, and in some products it will pretend to.
- Pasting the whole thing when only one section is relevant.
- Skipping the safe way out, so the model feels obliged to answer.
- Trusting a paraphrase when a quote is available. Ask for quotes on anything important.
- Not checking the quote. Quotes can be invented too. Search for them.
- Forgetting the date. The same question can have a different answer after a rule change.
Exercises
#Exercise 1
Make it grounded
#Rewrite this prompt so that it is grounded and checkable: "What are the refund rules for this online course?" Assume you have the terms page as text.
Exercise 2: Fix the plan for a long document
#You have a 90-page company handbook and want to know the rules on remote work. Describe a three-step plan that keeps each step checkable.
Exercise 3: Find the failure
#You uploaded a PDF and asked for a summary. The summary is fluent but does not mention a table on page 4 that you know is important. List three possible causes and one test.
Exercise 4: Evaluate the answer
#The assistant says, "The policy allows two retakes. Quote: 'Students may attempt the exam up to two additional times.'" Searching the document, you find the sentence "Students may attempt the exam up to two additional times, subject to approval by the Dean." What is the problem, and how would you change your prompt to catch it?
Show solutionHide solution
Answer using only the terms below. If the terms do not say, write "not stated".For each rule, quote the exact sentence. Include any conditions or exceptionsthat appear in the same section. Question: what are the refund rules?<terms>[paste the terms]</terms>Why: the source is separated and labelled, the model may use only it, "not stated" is allowed, quotes can be checked, and asking for "conditions or exceptions" targets a typical failure, namely missing the fine print.
Exercise 2
Show solutionHide solution
Step 1 (focus). Ask the assistant to list the headings of the handbook, or paste the table of contents, and name the sections likely to cover remote work. You check the list against the contents page and add anything it missed (for example "Equipment", "Working hours" or "Travel").
Step 2 (extract). Paste only those sections and ask for every sentence on remote work, quoted exactly, with section numbers. You can verify each quote by searching.
Step 3 (summarise). Using only the extract, ask for a plain summary and a list of conditions and exceptions, each with its quote. If the answer will affect a decision, read the original sections once yourself.
Each step produces something you can check, so errors cannot hide in the middle.
Exercise 3
Show solutionHide solution
Possible causes: (1) The tool's text extraction skipped or garbled the table, because tables are often poorly extracted. (2) The page was an image, so there was no text to read. (3) The document was long, the model gave less attention to that part, or the product only used part of the file.
Test: ask, "Quote the first row of the table on page 4." If it cannot, or invents text, extraction failed. A fix is to paste the table's text or an image-free copy of it, or ask the model to work on that section on its own.
Exercise 4
Show solutionHide solution
Problem: the quote is real but incomplete. The answer left out the condition "subject to approval by the Dean", which changes the meaning. This is selective reading: the model gave a correct partial quote and a misleading conclusion.
Prompt change: add "Quote the complete sentence, including any conditions, exceptions or approvals, and list conditions separately." Also, when you verify, read the full sentence in the source, not only the text the model quoted. Verification means looking at the original in context.
Where to go next
#- Next: Examples, Output Formats and Structured Output teaches you to shape the answer, including output you can check by program.
- For the full checking routine, see How to Fact-Check AI-Generated Answers.
- For long documents in practice, Meetings, Notes and Long Documents: Summaries You Can Trust applies this pattern.
Sources & further reading
Connected lessons
References
Linked from 7 guides
Other pages in the library that point here.
Keep reading
More in Technology →Guide · Technology
Writing Better AI Prompts: A Practical Guide
Guide · Technology
Using AI Tools at Work Without Getting Into Trouble
Course · Career
Off-Campus Placements With AI: From Zero to Offer

