Get startedGet started for free

Creating structured output prompts

When analyzing software applications or services, it's crucial to present information in a clear, structured format. In this exercise, you'll learn how to create prompts that generate well-organized analyses of a popular music streaming service. You'll enhance a basic prompt structure by adding pricing and limitations sections, helping create a comprehensive service overview that could be useful for product comparisons or documentation.

The boto3 and json libraries, and the bedrock client, have been pre-imported.

This exercise is part of the course

Introduction to Amazon Bedrock

View Course

Exercise instructions

  • Complete the prompt by adding a PRICING section with 2 pricing tiers and a LIMITATIONS section with 2 limitations with bullet points by following the same format as the FEATURES and USE CASES sections.

Hands-on interactive exercise

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

# Add PRICING and LIMITATIONS sections
messages = [{"role": "user", 
             "content": """Analyze sample music streaming data and provide information in this format:
              DESCRIPTION: [Write a 2-3 sentence description]
              FEATURES: - [feature 1] - [feature 2]
              USE CASES: 1. [use case 1] 2. [use case 2]
              ____
              ____"""}]

request_body = json.dumps({"anthropic_version": "bedrock-2023-05-31", "max_tokens": 100, "messages": messages})
response = bedrock.invoke_model(modelId='anthropic.claude-3-5-sonnet-20240620-v1:0', body=request_body)
response_body = json.loads(response['body'].read().decode())
print (response_body['content'][0]['text'])
Edit and Run Code