Skip to content

Lesson 2 of 6

Use long context to answer across a long document

Upload a long report to Gemini and adjust your prompt to ask for quoted evidence and a summary, which prepares the prompt for API use.

6 minClaude, Gemini and ChatGPT

After this lesson, you will be able to upload a long document to the Gemini chat window, ask a question that requires reading the whole document, and get an answer with quoted evidence and a summary.

Upload a long document

In the first lesson, you pasted a short text into the prompt. For a long document, you can upload a file instead. Gemini reads the file and uses its contents to answer.

Open the Gemini chat window in your browser and start a new chat. Click the plus icon next to the prompt box, then choose Upload file. Select a text file, a PDF, or a Word document from your computer. The file appears as an attachment above the prompt box.

For this lesson, use a long report. If you do not have one, create a plain text file called report.txt with at least 2000 words. You can write about any topic, such as a summary of a project, a set of meeting notes, or a description of a process. Save the file on your computer.

Once the file is uploaded, type a question in the prompt box. For example:

What are the main points of this document?

Press Enter. Gemini reads the whole document and gives an answer. The answer may be a few paragraphs. Check that the answer matches the document. If the document is very long, Gemini may still read all of it because Gemini has a large context window, which is the amount of text it can consider at once.

Ask for quoted evidence

A plain summary is useful, but you often need to know where in the document the answer comes from. You can change your prompt to ask for quoted evidence. This means Gemini must copy short passages from the document and show them with the answer.

Start a new chat and upload the same file again. Type this prompt:

Read the document. Answer the question: What are the main challenges mentioned? For each challenge, give a one-sentence explanation and a short quote from the document that supports it. Put the quote in quotation marks.

Press Enter. The answer should list challenges, each with a quote. The quote must be word-for-word from the document. If a quote is not exact, the evidence is not reliable.

Quoted evidence helps you check the answer. If the quote does not match the document, the answer may be wrong. This is important when you use the API later, because you will not see the document yourself.

Ask for a summary with a word limit

Sometimes you want a short summary, not a long answer. You can ask Gemini to limit the length. Add a word limit to your prompt.

Start a new chat and upload the file again. Type:

Summarise this document in no more than 100 words.

Press Enter. The answer should be a short paragraph. Count the words. If it is more than 100 words, the prompt was not clear enough. You can say "exactly 100 words" or "about 100 words" to be more precise.

A word limit is useful when you need a quick overview. In the next lessons, you will combine a summary request with a question in one prompt.

Combine evidence and summary in one prompt

For the API, you will want one prompt that does everything: read the document, answer a question, give evidence, and summarise. You can write that prompt now and test it in the chat window.

Start a new chat and upload the file. Type this prompt:

Read the document carefully. First, answer this question: What are the main recommendations? Give each recommendation as a short sentence. Then, for each recommendation, give a short quote from the document that supports it. Finally, write a summary of the whole document in no more than 50 words.

Press Enter. The answer should have three parts: a list of recommendations, quotes for each, and a summary. Check that the quotes are exact and the summary is short.

This prompt structure is what you will use in the API. The API takes one prompt and returns one answer, so you must put all your instructions in one place.

Check the answer against the document

After you get an answer, open the document and check a few quotes. If a quote is not in the document, the answer is not trustworthy. If the summary misses an important point, you can change the prompt to ask for that point specifically.

For example, if the summary does not mention a key decision, add: "Make sure the summary includes the decision about the budget." Then run the prompt again.

Checking answers is a good habit. In the next lesson, you will write Python code that sends a prompt to the API. You will not see the document in the code, so you must trust the prompt to ask for evidence.

Key takeaways

  • Upload a long document to Gemini instead of pasting it.
  • Ask for quoted evidence so you can check where an answer comes from.
  • Use a word limit to get a short summary.
  • Combine a question, evidence request, and summary in one prompt for API use.
  • Check quotes against the document to make sure the answer is reliable.

Try it

Take a long document of your own, at least 1500 words. Upload it to Gemini in a new chat. Write one prompt that asks: (1) list the three most important dates in the document, with a one-sentence description of each; (2) give a short quote from the document for each date; (3) summarise the whole document in no more than 60 words. Run the prompt. A good result has exactly three dates, each with a description and an exact quote, and a summary of 60 words or fewer. Check the quotes against the document. If the result is not good, adjust the prompt and run it again.

Official documentation

Ready to use this in a job?

Rolebound applies to matching roles for you.

Start now

Written with AI and checked automatically. Tools change, so a command may behave differently in the version you install. Spotted a mistake? Tell us.

    Cookies on Rolebound

    We use necessary cookies to sign you in and keep the site working — those cannot be turned off. We would also like to set analytics and advertising cookies so we can see which pages help people get interviews and which adverts brought them here. Nothing optional is set unless you say yes, and you can change your mind at any time from “Cookie settings” in the footer. Read our Privacy Policy.

    Use long context to answer across a long document | Working with Gemini: Prompting, Long Context and API | Rolebound