From 8d4d52457145976a7b9a39a7dec9be98d4eaca5a Mon Sep 17 00:00:00 2001 From: Netsanet Gebremedhin Date: Wed, 15 Oct 2025 02:12:01 -0400 Subject: [PATCH 1/3] docs(signature): add Google-style docstring for with_instructions (refs #8926) --- dspy/signatures/signature.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dspy/signatures/signature.py b/dspy/signatures/signature.py index 236a774ddd..b4f132f727 100644 --- a/dspy/signatures/signature.py +++ b/dspy/signatures/signature.py @@ -245,6 +245,25 @@ class Signature(BaseModel, metaclass=SignatureMeta): @classmethod def with_instructions(cls, instructions: str) -> type["Signature"]: + """Return a new Signature class with identical fields and new instructions. + + This method does not mutate ``cls``. It constructs a fresh Signature + class using the current fields and the provided ``instructions``. + + Args: + instructions (str): Instruction text to attach to the new signature. + + Returns: + type[Signature]: A new Signature class whose fields match ``cls.fields`` + and whose instructions equal ``instructions``. + + Example: + >>> NewSig = MySig.with_instructions("Translate to French.") + >>> NewSig is MySig + False + >>> NewSig.instructions + 'Translate to French.' + """ return Signature(cls.fields, instructions) @classmethod From 84ef5d7b1d1b9174d046bba08cf7f4c956bbbffe Mon Sep 17 00:00:00 2001 From: Netsanet Gebremedhin Date: Wed, 15 Oct 2025 20:12:23 -0400 Subject: [PATCH 2/3] docs(signature): unify backticks and finalize with_instructions docstring per style guide --- dspy/signatures/signature.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dspy/signatures/signature.py b/dspy/signatures/signature.py index b4f132f727..92202244e1 100644 --- a/dspy/signatures/signature.py +++ b/dspy/signatures/signature.py @@ -247,14 +247,14 @@ class Signature(BaseModel, metaclass=SignatureMeta): def with_instructions(cls, instructions: str) -> type["Signature"]: """Return a new Signature class with identical fields and new instructions. - This method does not mutate ``cls``. It constructs a fresh Signature + This method does not mutate `cls`. It constructs a fresh Signature class using the current fields and the provided ``instructions``. Args: instructions (str): Instruction text to attach to the new signature. Returns: - type[Signature]: A new Signature class whose fields match ``cls.fields`` + type[Signature]: A new Signature class whose fields match `cls.fields` and whose instructions equal ``instructions``. Example: From 46eeb18bae95c3ad0d995e86740efd02ee509558 Mon Sep 17 00:00:00 2001 From: Netsanet Gebremedhin Date: Wed, 15 Oct 2025 20:20:04 -0400 Subject: [PATCH 3/3] docs(signature): fix mkdocs rendering and make example runnable per review feedback --- dspy/signatures/signature.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dspy/signatures/signature.py b/dspy/signatures/signature.py index 92202244e1..f33df96ef0 100644 --- a/dspy/signatures/signature.py +++ b/dspy/signatures/signature.py @@ -258,11 +258,17 @@ class using the current fields and the provided ``instructions``. and whose instructions equal ``instructions``. Example: - >>> NewSig = MySig.with_instructions("Translate to French.") - >>> NewSig is MySig - False - >>> NewSig.instructions - 'Translate to French.' + ``` + from dspy.signatures import Signature, InputField, OutputField + + class MySig(Signature): + input_text: str = InputField(desc="Input text") + output_text: str = OutputField(desc="Output text") + + NewSig = MySig.with_instructions("Translate to French.") + assert NewSig is not MySig + assert NewSig.instructions == "Translate to French." + ``` """ return Signature(cls.fields, instructions)