RAG Query Rewriter
Transform a raw user question into a structured, retrieval-optimized query package that maximizes accuracy and recall when searching a knowledge base.
- Category
- AI & Prompt Engineering
- Output
- JSON
- Fields
- 3
- prompt-engineering
- ai-search
- output-optimization
- data-structuring
- workflow-design
Prompt
ROLE: You are a Retrieval-Augmented Generation (RAG) systems architect and prompt engineer. Your task is to transform a raw user question into a structured, retrieval-optimized query package that maximizes accuracy and recall when searching a knowledge base.
INPUTS:
- Knowledge Base Scope: Knowledge Base Scope
- Chat History (optional): Chat History (Optional)
- Raw User Question: User Question
INSTRUCTIONS:
1. Context Resolution: If chat history is provided, resolve pronouns, implicit references, and missing context to make the query standalone. If no history is given, note that context is missing.
2. Standalone Query: Generate a single, clean, decontextualized query that precisely captures the user's core information need.
3. Alternative Phrasings: Produce 2–3 alternative versions or sub-queries using different terminology, synonyms, or decomposition strategies to widen recall.
4. Metadata Extraction: Identify key entities, dates, product names, or specific filters that should be used for metadata filtering or vector search constraints.
5. Intent Classification: Tag the query with one primary intent: lookup, comparison, how-to, troubleshooting, or exploratory.
6. Edge-Case Handling: Briefly specify how the system should respond to vague questions, multi-part questions, or queries that fall outside the provided knowledge base scope.
CONSTRAINTS:
- Use only the information provided in the inputs. Do not invent facts, document names, or system capabilities.
- If critical context is missing or ambiguous, list it under "open_questions" instead of guessing.
- Return ONLY valid JSON. Do not include markdown code fences, explanations, or text before or after the JSON object.
- Ensure all keys match the exact structure below.
OUTPUT STRUCTURE (JSON):
{
"standalone_query": "string",
"alternative_queries": ["string", "string"],
"metadata_filters": { "key": "value" },
"primary_intent": "lookup | comparison | how-to | troubleshooting | exploratory",
"edge_case_handling": {
"vague_questions": "string",
"multi_part_questions": "string",
"out_of_scope": "string"
},
"open_questions": ["string"]
}
How to use this prompt
- Fill in the fields above. Required ones are marked with *.
- Check the prompt preview: your answers appear highlighted in place.
- Select Copy prompt and paste it into ChatGPT, Claude, Gemini or any AI assistant.
More AI & Prompt Engineering prompts
- Structure and Format AI OutputTransform unstructured input into a polished, professional output that strictly matches the requested target format.
- Automate AI WorkflowDesign a reliable, step-by-step AI automation workflow based on the user's specifications.
- Image Generation PromptTransform a user's core concept into highly optimized, ready-to-use prompts for AI image generation.
- LLM Evaluation and Model ComparisonYou are an expert AI model evaluator and technical consultant.
- Prompt Engineering Deep OptimizationRewrite the provided draft prompt using advanced prompt engineering best practices, making it more precise, reliable, and structured.
- System Prompt Production ReadyYou are an expert prompt engineer tasked with crafting production-ready system instructions for AI assistants.