Stepwise reasoning with DSPy
This example shows a simple reasoned response pattern with DSPy.
It keeps the model local and deterministic, but still returns a reasoning field and a final answer field so you can see the shape of a stepwise DSPy output.
Requirements
- Python 3.10+
Steps for running this example in the shell
- Install dependencies:
bash
python -m venv .venv
# macOS/Linux:
source .venv/bin/activate
# Windows Command Prompt:
.venv\Scripts\activate.bat
# Windows PowerShell:
.venv\Scripts\Activate.ps1
pip install -r requirements.txt- Run the script:
bash
python stepwise_reasoning.pyWhat it demonstrates
- A DSPy signature with a reasoning field and a final answer
- A local LM stub that emits repeatable JSON
- A small offline demo with no external dependencies
Output
Question 1: How should we handle the product launch this week?
Reasoning: A launch request needs a short plan and a clear final status.
Answer: Summarize the release steps, confirm the rollout owner, and share the final checklist.
Question 2: What should we say about the duplicate billing report?
Reasoning: Billing questions should confirm the charge and keep the reply precise.
Answer: Verify the charge, explain the refund status, and point the user to billing support