generative-ai-cdk-constructs icon indicating copy to clipboard operation
generative-ai-cdk-constructs copied to clipboard

Bedrock: Prompt Management. Add ability to add variables for `system` prompt

Open o-alexandrov opened this issue 1 year ago • 5 comments

Describe the feature

Currently, there is a limitation in Prompt Management:

  • it's impossible to use variables in the system part of the prompt

Use Case

When defining a system prompt, most of the prompts I worked on involve a necessity to have variables in the system (role defining) part of the prompt.

Proposed Solution

Add ability to reuse and add unique (used only in the system part) variables. Than, expose it through the construct.

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

o-alexandrov avatar Jan 07 '25 17:01 o-alexandrov

There're also 2 bugs in AWS Bedrock => Prompt Management. I don't know where to report them, so I just drop them here.

  1. When browsing the prompt in the UI, it highlights variables syntax in the system part as if it's working.
Screenshot 2025-01-07 at 12 02 19 PM
  1. When opening the prompt in the prompt editor, the model shows infinite loading indicator
Screenshot 2025-01-07 at 12 03 37 PM

o-alexandrov avatar Jan 07 '25 18:01 o-alexandrov

Hi @o-alexandrov ! Thanks for flagging this issue. I've tried to recreate a working example in the console, but no luck. It looks like this might be a limitation with Amazon Bedrock itself, not our CDK library.

In any case, system instructions are usually meant for static info that doesn't change between invocations, as this helps the model work more efficiently and better. You can still do role prompting by including your dynamic section in the user message.

const variantChat = PromptVariant.chat({
  variantName: 'variant1',
  model: BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
  system: "You are a highly acclaimed educator with extensive experience in developing innovative inquiry-based curricula for students. The content you create aligns with current educational standards and incorporates the latest research in effective science pedagogy.",
  messages: [
    ChatMessage.user('Your expertise lies in creating engaging, hands-on lessons about  {{subject}} that foster critical thinking and scientific curiosity for students in grades {{grades}}. Your task is to design an interactive, question-driven lesson on {{lessonName}}. Do not include a preamble to your answer.'),
  ],
  promptVariables: ['subject', 'grades', 'lessonName'],
});

aws-rafams avatar Jan 08 '25 10:01 aws-rafams

@aws-rafams

It looks like this might be a limitation with Amazon Bedrock itself, not our CDK library.

Yes, it's also not working in the AWS Bedrock web interface.

system instructions are usually meant for static info that doesn't change between invocations, as this helps the model work more efficiently and better.

Even though variables for the system message are present, it doesn't mean the system message is different for the chat. I think it's reasonable to have ability to reuse the same prompt for different cases of a system message.

  • otherwise, you'd either require a user to:
    • create a different prompt with a little difference to the system message
    • worsen the output, by moving role defining part into the user message

o-alexandrov avatar Jan 08 '25 12:01 o-alexandrov

Anyone has any updates on this? Im facing the same issue with the variable in system message.

visheanN1 avatar May 20 '25 07:05 visheanN1

The same problem we had with variables in the system message.

dosenk avatar Oct 14 '25 13:10 dosenk