Advanced prompting strategies

Introduction to Amazon Bedrock

Nikhil Rangarajan

Data Scientist

Prompting architecture

  • System prompts set style and approach
  • Chain-of-thought prompts provide a problem-solving framework
  • Few-shot prompts provide examples
  • Each layer builds understanding, improving reliability

A chart with four connected gears showing the prompt architecture sequence: System Prompt, Chain of Thought Steps, Few-Shot Examples, and Content Request.

Introduction to Amazon Bedrock

System prompts and style control

prompt_template = {
    "system_prompt": f"""System: Write in a professional but approachable tone.""",

"content_type": "blog_post",
"examples": [ { "title": "Cloud Migration Basics", "content": "Moving to the cloud doesn't have to be complex..." } ],
"task": f"Write a blog post about {topic}"
}
Introduction to Amazon Bedrock

Chain-of-thought prompting

def generate_message_content(text_data):
    steps = [
        "1. Understand the target audience",
        "2. Outline key points",
        "3. Draft a promotional email"
    ]

text_data["text"] += f"\nSteps:{' '.join(steps)}"
return text_data
  • 💡 Guides the model's thought process
Introduction to Amazon Bedrock

Content adaptation and parameters

parameters = {

"blog_post": {"temperature": 0.7, "top_p": 0.9}, "social_media": {"temperature": 0.8, "top_p": 0.95},
"technical": {"temperature": 0.4, "top_p": 0.8}
}
content_type = "blog_post" prompt_data["parameters"] = parameters[content_type]
  • Adjust parameters by content type
  • Parameter presets for consistency
Introduction to Amazon Bedrock

Generating prompts with templates

# Write the prompt
topic = "Cloud Security"
content_type = "blog_post"
prompt = f"Write a {topic} blog post. Use this example: {prompt_template["examples"][0]}"


# Define the parameters temperature = parameters[content_type]["temperature"] top_p = parameters[content_type]["top_p"]
# Call the model response = bedrock.invoke_model(modelId=model_id, body=json.dumps({"messages": [{"role": "user","content": [{"type": "text", "text": prompt}]}], "temperature": temperature, "top_p": top_p}))
Introduction to Amazon Bedrock

Let's practice!

Introduction to Amazon Bedrock

Preparing Video For Download...