Prediction/Example fields named items/keys/values/get/... return methods instead of stored values
Author: michaelkillgtaCreated Sep 25, 2026Updated Sep 28, 2026
Describe the bug
Documented attribute access (pred.answer, example.question) silently breaks for common field names that collide with Example / Prediction methods (items, keys, values, get, inputs, labels, copy, completions).
pred["items"] returns the stored value, but pred.items returns the bound method. Assignment via ex.items = ... can also diverge from _store.
To Reproduce
import dspy
from dspy.utils.dummies import DummyLM
lm = DummyLM([{"items": '["apple", "banana"]'}])
dspy.configure(lm=lm)
class Catalog(dspy.Signature):
query: str = dspy.InputField()
items: list[str] = dspy.OutputField()
pred = dspy.Predict(Catalog)(query="fruit")
print(pred["items"]) # ['apple', 'banana'] — OK
print(pred.items) # <bound method Example.items ...> — BUG
# for x in pred.items: ... → TypeError: 'method' object is not iterableAlso:
ex = dspy.Example(items=["a"])
ex.items = ["b"]
print(ex.items, ex["items"]) # can diverge (attr vs _store)Expected behavior
pred.items returns the stored list, same as pred["items"], matching how pred.answer works.
Environment
dspy==3.4.0- Python 3.13
Additional context
Example.__getattr__ only runs for names missing on the class, so class methods shadow _store. __setattr__ routes names in dir(self.__class__) away from _store. Signature construction warns for some pydantic parent names but not these Example method names.
Source: stanfordnlp/dspy