Get startedGet started for free

Creating structured output prompts

Your team is extending the primary-school science-and-maths platform with AI-powered analytics that review each course module. As a proof of concept, you’ll use Claude to produce an analysis of the new “Geometry Basics” learning module.

The boto3 and json libraries, module_data, 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 that lists two subscription tiers for the module, and a LIMITATIONS section that lists two current limitations, following the same bullet-point format used for FEATURES and USE CASES.

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 “Geometry Basics” module data in {module_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