Applying prompt engineering techniques

Introduction to Amazon Bedrock

Nikhil Rangarajan

Data Scientist

Few shot learning

  • What is few-shot learning?
    • A technique to guide the model by providing a few examples in the prompt
    • Helps the model infer patterns and improve response quality
  • Key benefits:
    • Reduces ambiguity in the prompt
    • Produces more consistent and accurate outputs

A conceptual diagram to represent learning by example.'

Introduction to Amazon Bedrock

Few shot learning with models

prompt = """Here are examples of AWS service summaries:

Service: Amazon S3
Summary: Object storage service for storing and retrieving any amount of data.

Service: Amazon EC2
Summary: Virtual servers in the cloud for running applications.

Now, write a similar summary for:
Service: AWS Lambda\n\nSummary:"""
Introduction to Amazon Bedrock

What is structured output formatting?

  • Organizes model responses in a clear, predictable format
  • Ideal for automation and data extraction tasks

DOC.png

Introduction to Amazon Bedrock

Controlling response format

  • Request specific output structures
  • Use clear markers for parsing
  • Define format constraints
prompt = """Analyze AWS Lambda and provide output in this format:
DESCRIPTION:[2-3 sentence description]
KEY FEATURES:
- [feature 1]
- [feature 2]
USE CASES:
1. [use case 1]
2. [use case 2]"""
Introduction to Amazon Bedrock

Creating effective prompts

  • Combine few-shot examples with system prompts
  • Use structured formatting with examples
  • Layer techniques for better results
prompt = """You are an AWS technical writer. 
Here's an example of how to document APIs:
API: GetItem
Format: - Purpose: [one line], 
- Parameters: [list], 
- Returns: [description]
Now document the following API:
API: PutItem"""
Introduction to Amazon Bedrock

Let's practice!

Introduction to Amazon Bedrock

Preparing Video For Download...