Skip to content

dspy/cache-disabled-in-module

Pack Severity Fix Versions
DSPy warning none, edit by hand All versions

Disabling DSPy's response cache inside a dspy.Module defeats disk and memory caching across repeated evaluations and optimizer trials.

class AnswerModule(dspy.Module):
def forward(self, question: str) -> dspy.Prediction:
with dspy.context(cache=False):
return self.predict(question=question)
return self.predict(question=question)

Calls to dspy.configure_cache(...) or dspy.context(..., cache=False) inside a dspy.Module subclass.

Remove cache overrides from the module and pass --no-cache or with dspy.context(cache=False): in the evaluation runner when uncached repeats are needed.

Disabling cache inside a dspy.Module prevents evaluation and optimization reuse. Control cache policy in the runner instead.

See all rules in the DSPy pack.