Search Tutorials
--Ads--Step-Back Prompting
Retrieve background knowledge with a more general version of the question.
Some questions are so specific that the documents answering them only make sense with background knowledge. "Can I take my 5 carried-over leave days in December if I joined in March last year?" needs the carry-over rules, the leave year definition and the probation rules, which may live in different sections. Step-back prompting, proposed by researchers at Google DeepMind in 2023, first asks a more general, "stepped back" question, retrieves the principles behind it, and then answers the specific question using both.
The idea
| Original question | Step-back question |
|---|---|
| Can I take my 5 carried-over leave days in December if I joined in March last year? | What are the rules for leave carry-over, the leave year and leave for new employees? |
| Why did the X200 router's light turn orange after the firmware update? | What do the X200 router's status light colours mean? |
| Is a 7,500 rupee hotel in Pune within policy for an L2 employee? | What are the hotel cost limits by city and employee grade? |
The step-back question retrieves the general rules, the original question retrieves specific details, and the LLM reasons from both.
Implementation
from rag_helpers import ask
from retriever import DenseRetriever # from the top-k search lesson
STEP_BACK_PROMPT = """You help a search system. Given a specific question, write ONE more general
question about the underlying rules, concepts or background needed to answer it.
Output only the general question.
Examples:
Specific: Can I expense a 7,500 rupee hotel in Pune as an L2 employee?
General: What are the hotel cost limits by city and employee grade?
Specific: Why does my laptop say "BitLocker recovery" after a BIOS update?
General: How does BitLocker disk encryption work and when does it ask for a recovery key?
Specific: {question}
General:"""
def step_back_answer(question: str, retriever: DenseRetriever, k: int = 4) -> str:
general = ask(STEP_BACK_PROMPT.format(question=question), max_tokens=150).strip()
specific_hits = retriever.search(question, k=k)
general_hits = retriever.search(general, k=k)
# Merge and deduplicate, keeping order
seen, context = set(), []
for hit in general_hits + specific_hits:
if hit.id not in seen:
seen.add(hit.id)
context.append(f'<source id="{hit.id}">\n{hit.text}\n</source>')
prompt = f"""<sources>
{chr(10).join(context)}
</sources>
First identify the general rules in the sources that apply, then use them to answer the
specific question. Cite source ids. If the sources are not enough, say what is missing.
Specific question: {question}"""
return ask(prompt, effort="medium")
Note the effort="medium" on the final call: step-back questions usually need a little reasoning (applying a rule to a case), so a bit more thinking helps.
When to use it
- Rule-application questions: policies, regulations, eligibility, pricing tiers.
- Diagnostic questions: "why did X happen?" where the documents explain how the system works.
- Knowledge-intensive reasoning in science, law or finance, where principles live in different places from examples.
For simple fact lookups ("What is the hotel limit in Pune?") it adds latency without benefit. A router (see Query Routing) can decide when to use it.
Key takeaways
- Step-back prompting generates a more general question to retrieve the underlying principles.
- Retrieve for both the general and the specific question, then merge the context.
- Ask the LLM to state the applicable rules first, then apply them.
- Use it for rule-application and diagnostic questions, not simple lookups.