stanfordnlp / dspy

DSPy: The framework for programming—not prompting—foundation models
https://dspy.ai
MIT License
18.76k stars 1.44k forks source link

Structured Output Best Practices #153

Closed darinkishore closed 1 year ago

darinkishore commented 1 year ago

Hi! One of the DSPy core tenets is to avoid prompt engineering.

But if you want structured input/output, where is it best to indicate that in a program, aside from the training examples?

Would it be in

We don't always have the luxury of intermediate labels, so if an intermediate task has to have a particular format, it would be nice to have an official best practices recommendation for this case.

arnavsinghvi11 commented 1 year ago

Hi @darinkishore,

Yes, for enhanced control over structured input and outputs, utilizing the full-form signature notation is recommended, allowing you to include a prefix to denote your input/output and a desc as a refined description for the corresponding field (as you have illustrated in your example). Usually, brief descriptions suffice, as the aim is to avoid even "signature engineering" where possible and let DSPy do the work with these concise InputFields and OutputFields.

Let me know if that answers your question!

okhat commented 1 year ago

Yes, signature desc and metrics, and compiling, are the ways to control this now.

Soon we will have built-in types that will make this smoother.