The prompt
Given the following context, list
the facts that {entity} would know:
Context:
{context}
{query}
List only the facts relevant to {entity}.
---
You are {entity}. Answer the following question
based only on these facts you know:
{" ".join([str(fact) for fact in known_facts])} What it is
A two-step technique: first list the facts one person would know from a context, then answer the question as that person using only those facts. The docs cite the paper Think Twice for this technique. The prompt text comes from the Instructor documentation (MIT licence, Copyright (c) 2023 Jason Liu). The two prompts are separated by a line with three dashes, which is ours. Python string quotes and code indentation were removed. Placeholders keep the source syntax. The last placeholder of step two is a Python expression that inserts the facts from step one. Original author: Jason Liu and contributors (567-labs/instructor).
Who it's for
- Anyone writing prompts
- Developers
أسلوب من خطوتين: يسرد أولًا الحقائق التي يعرفها شخص ما من السياق، ثم يجيب عن السؤال بلسان ذلك الشخص اعتمادًا عليها فقط.
Examples
Example from the docs
pythonif __name__ == "__main__":
entity = "Alice"
context = """Alice puts the book on the table.
Alice leaves the room.
Bob moves the book to the shelf.
"""
query = f"Where does {entity} think the book is?"
known_facts = generate_known_facts(entity, context, query)
response = answer_question_based_on_facts(entity, query, known_facts)
for fact in known_facts:
print(fact)
#> fact='Alice puts the book on the table.'
#> fact='Alice leaves the room. Bob moves the book to the shelf.'
print(response.location)
#> On the tableWhat it does: The usage code and printed output from the Instructor docs. Output as printed in the docs, not re-run by us. The second printed fact includes Bob moving the book, which Alice did not see, though the final answer is still the table.
Tips
- The docs say this can be useful for complex questions with multiple entities.
- The docs pass a Pydantic response model with this prompt, so the printed output follows that schema.