stanfordnlp / dspy

DSPy: The framework for programming—not prompting—foundation models
https://dspy-docs.vercel.app/
MIT License
17.36k stars 1.33k forks source link

Clarification on the use of hard-written output field prompt in TextToSQLAnswer Signature #1178

Closed backslash112 closed 3 months ago

backslash112 commented 3 months ago

I am reading the text-to-sql example from the examples/ folder, and I have a question regarding the TextToSQLAnswer class. I noticed that the sql output field uses a hard-written prompt in its description:

sql:str = dspy.OutputField(desc="Generate syntactically correct sqlite query with correct column names using suitable tables(s) and its rows.\n Don't forget to add distinct.\n Please rename the returned columns into suitable names.\n DON'T OUTPUT anything else other than the sqlite query")

My question is: Does the content of the desc parameter matter in this case? Is it used as a prompt for the model to generate the SQL query, or is it just a human-readable description?

Thanks!

arnavsinghvi11 commented 3 months ago

Hi @backslash112 , the description is attached with the field within the prompt.

For instance, in the intro.ipynb notebook, the signature BasicQA is defined as

class BasicQA(dspy.Signature):
    """Answer questions with short factoid answers."""

    question = dspy.InputField()
    answer = dspy.OutputField(desc="often between 1 and 5 words")

which turns into the prompt:

Answer questions with short factoid answers.

---

Follow the following format.

Question: ${question}
Answer: often between 1 and 5 words

---

Question: What is the nationality of the chef and restaurateur featured in Restaurant: Impossible?
Answer:

The description is certainly not necessary if the signature instruction covers your task requirements, but can often help in guiding the model on how to treat the corresponding Input and OutputFields.