Sub topic 1
Decide What the Summary Is For
Prerequisites
You should know basic Python, have sent prompts to an LLM through an API or chat interface, and understand that tokens are small units of text used to measure input and output.
Decide What the Summary Is For
A useful summary starts with a purpose. State who will read it, what they need, and how long it should be. A summary for an executive may list decisions and risks. A summary for a developer may preserve technical details and action items.
Define these constraints before writing the prompt:
- Audience: who will use the result?
- Purpose: what decision or task will it support?
- Length: how much text is useful?
- Content: which facts must be included?
- Style: should it use bullets, headings, or prose?
Extractive and Abstractive Summaries
An extractive summary selects sentences or phrases from the source. It usually preserves wording closely and reduces the risk of inventing facts.
An abstractive summary writes new sentences that express the source's meaning. It is often clearer and shorter, but it can omit details or introduce claims that the source never made.
Choose extractive output when exact wording matters, such as legal evidence. Choose abstractive output when readers need a concise explanation.
prompt = """Summarise the document for a project manager.
Use five bullet points. Include decisions, risks, and open actions.
Use only information stated in the document.
DOCUMENT:
""" + documentTokens and Context Windows: Will It Fit?
A token is a small piece of text. A model's context window is the maximum number of input and output tokens it can handle in one request. The document, instructions, conversation history, and requested summary all use this space.
Estimate the total before making a request:
input tokens + prompt tokens + output tokens <= context-window limit
Leave room for the output. A document that barely fits may fail when the prompt or requested summary is added. If it does not fit, split it at natural boundaries such as paragraphs, sections, or chapters.
Writing a Summarisation Prompt
Write constraints that can be checked. Name the audience, required content, length, and evidence rule. For example: “Write 100 words for a project manager. Include decisions and risks. Use only the document. If information is missing, say so.”
Exercise
A document uses 8,000 tokens. The prompt uses 300 tokens, the model limit is 10,000 tokens, and you reserve 2,000 tokens for output. Will it fit?
Show answer
No. The total is 10,300 tokens, which exceeds the 10,000-token context window.