Skip to content

Read the Prompt Again

By appending the phrase "Read the question again", you can improve the reasoning abilities of Large Langauge Models 1

This could look something like this

Re-Reading Template

[ Input Query ] Read the question again: [ Input Query ]

[ Critical Thinking Prompt ]

We can implement this in Instructor pretty simply.

import instructor
from openai import OpenAI
from pydantic import BaseModel, Field


client = instructor.from_openai(OpenAI())


class Solution(BaseModel):
    final_answer: int = Field(..., description="This is the final answer")


def solve_question(question: str) -> int:
    response = client.chat.completions.create(
        model="gpt-4o",
        response_model=Solution,
        messages=[
            {
                "role": "system",
                "content": f"""{question}. Read the question
                again. {question}. Adhere to the provided
                format when responding to the problem and
                make sure to think through this step by
                step.""",
            },
        ],
    )
    return response.final_answer


# Example usage
if __name__ == "__main__":
    question = """Roger has 5 tennis balls. He buys 2 more cans of tennis
    balls. Each can has 3 tennis balls. How many tennis balls
    does he have now?"""

    answer = solve_question(question)
    print(answer)
    #> 11

References

1: Re-Reading Improves Reasoning in Large Language Models