Get startedGet started for free

Implementing chain of thought prompting

When generating content with Claude, breaking down the thinking process helps produce better results. Your task is to create a function that adds structured thinking steps to a prompt, guiding the model through the task of creating a promotional email for a new cloud platform.

The json library has been imported.

This exercise is part of the course

Introduction to Amazon Bedrock

View Course

Exercise instructions

  • Outline three steps the model should take in preparing the response, using a numbered list (1., 2., 3.).
  • Using the steps list for the chain of thought, populate the "text" field of text_data by appending them after "\nSteps: ".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

def generate_message_content(text_data):
    steps = [
        "____",
        "____",
        "____"
    ]
    text_data["text"] += "\nSteps: " + ____
    return text_data

text_data = {"text": "Create a promotional email for a new cloud platform."}
  
print(generate_message_content(text_data))
Edit and Run Code