DSPyDSPy 3.3 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
24 small wins to finish your pathNext lesson

The prompt DSPy writes for you

DSPy never asks you for prompt text. An adapter turns the signature and inputs into chat messages, then parses the model's reply back into fields.

Example
messages = dspy.ChatAdapter().format(
    dspy.Signature("question -> answer"),
    demos=[],
    inputs={"question": "What is the capital of France?"},
)
for message in messages:
    print(f"--- {message['role']}")
    print(message["content"])

dspy.ChatAdapter is the default adapter, and format is the method DSPy calls before every request. No model is involved, so you can print the exact messages any time.

  • The system message lists the input and output fields, shows the [[ ## field ## ]] markers the model must use, and ends with the task. With no description given, the task is Given the fields `question`, produce the fields `answer`.
  • The user message holds the inputs under their markers, then says which output markers to write, ending with [[ ## completed ## ]].

Reading the reply

Example
reply = "[[ ## answer ## ]]\nParis\n\n[[ ## completed ## ]]"
print(dspy.ChatAdapter().parse(dspy.Signature("question -> answer"), reply))

parse finds each output marker and returns the text under it as a dictionary. That is why the mock in lesson 2 was written with markers: it is what a model following this prompt sends back. Predict wraps both steps, format then parse, around the model call.

Names are part of the prompt
The field names appear in the prompt, so question -> answer and ticket -> category ask for different things even with identical code around them. Choose names a person would understand.
Try it yourself
  • Format "ticket -> category, priority" and find where priority appears.
  • Parse a reply that is missing [[ ## completed ## ]].
  • Parse a reply with no markers at all and read the error.

Slow is fine. Stopping is the only problem.