Back to cookbook

Prompt for Answering Only From Provided Context

19 views Published

Make this prompt yours

Share

This is a grounding prompt for retrieval-augmented generation setups: it forces ChatGPT, Claude, or Gemini to answer strictly from the text you provide and say so clearly when the answer isn't in it, instead of filling gaps with outside knowledge.

It's built for anyone wiring a model up to search results, internal documents, or a knowledge base, where an answer that sounds right but wasn't actually in the source is worse than no answer at all.

Prompt template

Make this prompt yours

prompt-template
130 tokens
You are a question-answering assistant that only uses the provided context. Context: [PASTE RETRIEVED PASSAGES OR DOCUMENTS] Question: [USER'S QUESTION] Instructions: 1. Answer using only information found in the context above. 2. Quote or reference the specific part of the context that supports your answer. 3. If the context does not contain the answer, respond exactly: "Not found in the provided context." 4. Do not use outside knowledge, even if you know the answer. Output format: Answer: [your answer, or the not-found line] Source: [the quoted passage, or "n/a"]

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
47 tokens
Context: Our refund policy allows returns within 30 days of purchase with a valid receipt. Refunds are issued to the original payment method within 5-7 business days. Question: Can I get a refund after 45 days?

When to use it

  • Building a RAG pipeline where answers must be traceable to source documents
  • Question answering over internal docs, policies, or support articles
  • Summarizing search results without letting the model add outside facts
  • Any customer-facing bot where a hallucinated answer is a real risk

Best practices

  • Pass only the retrieved passages that are actually relevant, not the whole document
  • Ask the model to quote the specific passage it used to support its answer
  • Explicitly instruct it to say the answer wasn't found when that's true
  • Keep the context and the question in clearly separated sections

Common mistakes

  • Not telling the model what to do when the answer isn't present, so it guesses
  • Passing too much irrelevant context, which dilutes the retrieval signal
  • Skipping citations, making it hard to verify the answer against the source
  • Assuming grounding is automatic just because you supplied context

FAQs

Why would a model ignore instructions and use outside knowledge anyway?

Larger models sometimes blend in general knowledge when the context is thin. Making the not-found instruction explicit and repeating it reduces this, though it's not foolproof, so always spot-check outputs in a production system.

How much context should I include?

Only the passages your retrieval step actually ranked as relevant. Dumping in unrelated documents makes it harder for the model to stay grounded and wastes tokens.

Can I use this without a real retrieval system, just pasted text?

Yes. The prompt works the same whether the context came from a vector search or you pasted it in manually.

What's the difference between this and a normal summarization prompt?

A summarization prompt condenses what's there. This prompt also has to refuse to answer when the information isn't there, which most summarization prompts don't enforce.

Found this prompt useful? Share it.

Share

More in RAG & Knowledge Retrieval

RAG & Knowledge Retrieval

AI Prompt to Deduplicate Near-Duplicate Documents Before RAG Indexing

This prompt asks ChatGPT, Claude, or Gemini to design a strategy for catching near duplicate documents before they go into a RAG index, the…

You are a retrieval systems engineer designing a document deduplication stage for a RAG pipeline.

Context:
- Document sources: [LIST SOURCES, e.g. Confluence export, CMS pages, uploaded PDFs]
- Approximate corpus size: [NUMBER OF DOCUMENTS]
- Current chunking strategy: [e.g. 512-token chunks with 50-token overlap]
- Embedding model in use: [MODEL NAME]
- Known duplication pattern, if any: [e.g. same FAQ exported in two formats, revised policy versions]

Design a near-duplicate detection and resolution strategy with the following requirements:
1. Recommend a detection method (embedding cosine similarity, MinHash/shingling, or a hybrid) appropriate for the corpus size and chunking strategy above
2. Propose a specific similarity threshold or range, and explain the tradeoff of setting it higher versus lower
3. Define a tie-breaking rule for which document in a near-duplicate pair to keep
4. Specify a dry-run report format that lists candidate duplicate pairs with their similarity score before anything is removed
5. Describe how to flag pairs that are similar overall but differ in a critical detail, such as a number, date, or clause, so those are kept rather than merged
6. Explain how to log every merge or removal decision for later auditing

Output format:
- A short written plan covering points 1-3
- A sample dry-run report row format (as a table or structured record)
- A short section on the critical-detail safeguard from point 5
- A one-paragraph logging and audit approach

Make this prompt yours

RAG & Knowledge Retrieval

AI Prompt to Design a Metadata Filtering Strategy for RAG Retrieval

Metadata filtering narrows a RAG system's search space before similarity ranking even runs, using fields like document date, source, departm…

You are a retrieval systems engineer designing a metadata filtering strategy for a RAG pipeline.

Corpus description: [WHAT THE DOCUMENTS ARE, E.G. INTERNAL POLICY DOCS, PRODUCT MANUALS, SUPPORT TICKETS]
Available metadata fields: [LIST FIELDS, E.G. DOCUMENT DATE, DEPARTMENT, PRODUCT VERSION, ACCESS LEVEL]
Current retrieval problem: [DESCRIBE THE SPECIFIC FAILURE, E.G. RETURNS OUTDATED POLICY VERSIONS ALONGSIDE CURRENT ONES]
Example query that fails today: [EXAMPLE QUERY]
Query volume/pattern notes (optional): [E.G. MOST QUERIES DON'T MENTION A DATE OR VERSION]

Task:
1. Identify which available metadata fields would most directly address the retrieval problem described.
2. For each recommended field, specify whether it should be applied as a hard pre-filter or a soft ranking boost, and explain why.
3. Describe how the system should behave when a query gives no explicit signal for that field (e.g. default to most recent, ask a clarifying question, or search unfiltered).
4. Flag any field where filtering carries a real risk of excluding a relevant result due to inconsistent or missing metadata.
5. Walk through the example query that fails today and show how the proposed strategy would change the result.

Constraints:
- Only recommend filtering on fields explicitly listed as available.
- Do not recommend a hard filter without first addressing what happens to documents missing that field.

Output format: a table of recommended fields with filter type and rationale, followed by a short walkthrough of the example query.

Make this prompt yours

RAG & Knowledge Retrieval

AI Prompt for Multi-Hop Reasoning Across Multiple Retrieved Documents in RAG

This AI prompt is for RAG (retrieval augmented generation) systems that need to answer questions where no single retrieved document contains…

ROLE: You are a careful research assistant that answers questions strictly from provided source passages, including questions that require combining facts from more than one passage.

CONTEXT: Below are retrieved passages, each labeled with a source ID.
[PASSAGE 1, LABELED SOURCE: DOCUMENT_A]
[PASSAGE 2, LABELED SOURCE: DOCUMENT_B]
[ADDITIONAL PASSAGES AS NEEDED]

QUESTION: [MULTI-HOP QUESTION THAT REQUIRES COMBINING FACTS FROM MULTIPLE PASSAGES]

INSTRUCTIONS:
1. Identify which specific passage(s) are relevant to each part of the question.
2. If answering requires combining a fact from one passage with a fact from another, state explicitly how the two facts connect before giving the final answer.
3. Cite the source ID for every claim you make.
4. If any part of the reasoning chain is missing from the provided passages, say exactly which part is missing instead of guessing or inferring it.
5. Do not use any knowledge outside the provided passages.

OUTPUT FORMAT:
Relevant Passages: [list of source IDs used]
Reasoning Chain: [how the passages connect, step by step]
Final Answer: [the answer, or a statement of what's missing if the chain is incomplete]

Make this prompt yours