Skip to content

Conversation

@chenmoneygithub
Copy link
Collaborator

In some scenarios users want to extract the actual prompt sent to LM programmatically. Right now we allow users to use Adapter.format() to get the multi-turn message, but sometimes users only want to extract the system message. This PR introduces a new method Adapter.format_system_message() which only extracts system message based on adapter and signature.

Example usage:

import dspy

signature = dspy.Signature("question -> answer")
system_message = dspy.ChatAdapter().format_system_message(signature)
print(system_message)

The output should resemble:

Your input fields are:
1. `question` (str):
Your output fields are:
1. `answer` (str):
All interactions will be structured in the following way, with the appropriate values filled in.

[[ ## question ## ]]
{question}
[[ ## answer ## ]]
{answer}
[[ ## completed ## ]]
In adhering to this structure, your objective is: 
        Given the fields `question`, produce the fields `answer`.

Copy link
Collaborator

@TomeHirata TomeHirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@TomeHirata
Copy link
Collaborator

Can we tag related issues if any?

@chenmoneygithub
Copy link
Collaborator Author

@TomeHirata The related issue is our work on KD service/SDK - this PR just makes it easier to extract out the prompt.

@chenmoneygithub chenmoneygithub merged commit 5e72f7b into stanfordnlp:main Nov 3, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants