dspy/configure-in-forward
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| DSPy | error | none, edit by hand | All versions |
dspy.configure(...) mutates process-wide settings and raises a thread-ownership error when called from worker threads during dspy.Evaluate, dspy.Parallel, or optimizer runs.
def forward(self, question: str) -> dspy.Prediction: dspy.configure(adapter=dspy.JSONAdapter()) return self.predict(question=question) with dspy.context(adapter=dspy.JSONAdapter()): return self.predict(question=question)What the rule reports
Section titled “What the rule reports”Calls to dspy.configure(...) or imported configure(...) inside a forward function or method.
How to fix it
Section titled “How to fix it”Replace global dspy.configure(...) inside forward with a thread-local with dspy.context(...): block, and leave model binding to the caller or runner.
Diagnostic message
Section titled “Diagnostic message”dspy.configure(...) mutates global settings and fails across threads inside forward(). Use 'with dspy.context(...):' instead.See all rules in the DSPy pack.