What this prompt does
This prompt optimizes a retrieval-augmented generation prompt — the instruction layer that sits between your retrieved chunks and the model's answer. It tackles the parts that make or break a RAG system: how to format [chunk_count] retrieved chunks for the model, how to attribute sources, and how to enforce anti-hallucination guardrails so the model only answers from the provided context. It also handles contradictions between chunks, designs an honest "I don't know" response when context is insufficient, and adds query rewriting to improve retrieval before generation.
The variables tie the optimization to your stack and goals. [use_case] defines the application, such as internal documentation Q&A, and [current_setup] describes the existing retrieval stack so the advice fits what you run. [chunk_count] sets how many chunks the prompt must present and reason over. The pair [current_hallucination_rate] and [target_hallucination_rate] make the goal measurable — reducing fabricated answers from one level to a lower one — which keeps the guardrail work grounded in a real target rather than a vague hope.
When to use it
- You are building a documentation-Q&A or internal-knowledge agent and need it grounded in retrieved sources.
- The model invents answers when the context is thin and you need stronger anti-hallucination guardrails.
- Retrieved chunks contradict each other and the model needs rules for reconciling them.
- You want honest "I don't know" behavior instead of confident fabrication when context is insufficient.
- Source attribution matters and answers need inline citations or links back to documents.
- Retrieval quality is weak and a query-rewriting step could surface better chunks before generation.
Example output
Expect an optimized RAG prompt covering how to present [chunk_count] chunks, source-attribution instructions, explicit anti-hallucination guardrails, and rules for handling contradictions and low-relevance chunks. It includes a defined "I don't know" response with a suggestion for a better query, a query-rewriting prompt to run before retrieval, metadata utilization, and an output format with a confidence score and the sources actually used — all aimed at moving from [current_hallucination_rate] toward [target_hallucination_rate].
Pro tips
- Make the anti-hallucination guardrail explicit and strict — "only answer from the provided context" is what makes a RAG system trustworthy enough to ship.
- Design the "I don't know" path deliberately; an honest refusal with a better-query suggestion beats a confident wrong answer every time.
- Format
[chunk_count]chunks with clear delimiters and source labels so the model can cite precisely and ignore low-relevance ones. - Treat
[current_hallucination_rate]and[target_hallucination_rate]as a measured goal — track real hallucinations rather than assuming the guardrails worked. - Add the query-rewriting step when retrieval is the weak link; better chunks in usually beats more guardrails on the generation side.
- Use metadata like source date and document type in answers so users can judge freshness and authority, not just the text.