[Bug] Signature.insert/prepend/append silently drops a field whose name exists in the other section
What happened?
dspy.ChainOfThought("reasoning, question -> answer") ends up with the signature question -> reasoning, answer: the user's reasoning input is gone. At call time it only logs that reasoning isn't in the signature and is ignored, so the LM never sees it. Same with Signature("question -> answer").append("answer", InputField()), which silently drops the new input.
String signatures already reject this (Signature("reasoning, question -> reasoning, answer") raises "distinct names", added in #9432), but insert() merges both sections through a dict, so a name from the other section just collapses. Reproduced on 3.4.0 with DummyLM.
I have a small fix (raise the same error in insert() when the name exists in the other section; same-section replacement unchanged) and will open a PR.
Steps to reproduce
dspy.ChainOfThought("reasoning, question -> answer")and inspect its signature: it isquestion -> reasoning, answer(thereasoninginput is gone).dspy.Signature("question -> answer").append("answer", dspy.InputField()): the new input is silently dropped instead of raising.- For comparison,
dspy.Signature("reasoning, question -> reasoning, answer")raises "distinct names".
DSPy version
3.4.0
Found with AI assistance (Claude Code); I verified the repro.
Source: stanfordnlp/dspy