A prompt programing library (Stanford)
Optimize prompts using python.
Forces you to THINK about your problem output and input structure first.
An Abstraction over language that can be “managed”
Separates concerns and automates the lower-level ones until you need to consider them.
Programming. Defining your task, its constraints, exploring a few examples, and using that to inform your initial pipeline design.
Evaluation. Collect an initial development set, define your DSPy metrics, iterate on your system more systematically.
Optimization. Tune the prompts or weights in your program.
desc=
) to the dspy.InputField
to guide users on what input is expected.desc=
) to the dspy.OutputField
to specify any restrictions or requirements on the output. # COT
math = dspy.ChainOfThought("question -> answer: float")
# Entity extraction:
dspy.Predict("text -> title, headings: list[str], entities_and_metadata: list[dict[str, str]]")
# ReACT
dspy.ReAct("question -> answer: float", tools=[tool1, tool2])
#Code execution:
Dspy.PythonInterpreter({}).execute(expression)
# RAG:
dspy.ColBERTv2(url=….')(query, k=3)
Laith Zumot © 2025 · lzumot.github.io · CC BY-NC-SA 4.0