Exclusive Content:

Haiper steps out of stealth mode, secures $13.8 million seed funding for video-generative AI

Haiper Emerges from Stealth Mode with $13.8 Million Seed...

Running Your ML Notebook on Databricks: A Step-by-Step Guide

A Step-by-Step Guide to Hosting Machine Learning Notebooks in...

“Revealing Weak Infosec Practices that Open the Door for Cyber Criminals in Your Organization” • The Register

Warning: Stolen ChatGPT Credentials a Hot Commodity on the...

Speeding Up Custom Entity Recognition Using the Claude Tool in Amazon Bedrock

Unlocking the Power of Claude Tool Use for Efficient Entity Extraction with Amazon Bedrock

Streamlining Document Processing with Large Language Models


Key Topics Covered:

  • Understanding Claude Tool Use (Function Calling)
  • Dynamic Data Extraction with Natural Language Prompts
  • Setting Up a Serverless Pipeline: AWS Lambda and Amazon S3
  • Implementing Adaptable Entity Extraction Across Document Types
  • Deploying a Production-Ready Solution Following AWS Best Practices

Introduction to Claude Tool Use (Function Calling)

Functionality and Benefits of Amazon Bedrock

Overview of the Extraction Solution

Architecture Overview for Document Processing

Implementation Steps for a Serverless Pipeline

Optimizing Performance and Ensuring Security

Conclusion and Future Steps for Document Processing Innovation


Meet the Authors

  • Kimo El Mehri
  • Johana Herrera

Unlocking the Power of Unstructured Data with Claude Tool Use in Amazon Bedrock

Businesses across industries face a common challenge: efficiently extracting valuable information from vast amounts of unstructured data. Traditional approaches often involve resource-intensive processes and inflexible models. In this blog post, we introduce a game-changing solution: Claude Tool use in Amazon Bedrock, which leverages the power of large language models (LLMs) to perform dynamic, adaptable entity recognition without extensive setup or training.

What We’ll Cover:

  • An overview of Claude Tool use (function calling)
  • How to use Claude Tool use to extract structured data using natural language prompts
  • Setting up a serverless pipeline with Amazon Bedrock, AWS Lambda, and Amazon Simple Storage Service (S3)
  • Implementing dynamic entity extraction for various document types
  • Deploying a production-ready solution following AWS best practices

What is Claude Tool Use (Function Calling)?

Claude Tool use, also referred to as function calling, is a powerful capability that enhances Claude’s abilities by establishing and invoking external functions or tools. This feature allows us to equip Claude with a collection of pre-established tools that it can access and employ as needed, thereby boosting its functionality.

How Claude Tool use Works with Amazon Bedrock

Amazon Bedrock is a fully managed generative AI service that provides a range of high-performing foundation models (FMs) from industry leaders like Anthropic. Implementing Claude’s Tool use through Amazon Bedrock is remarkably straightforward:

  1. Users define a set of tools, including their names, input schemas, and descriptions.
  2. A user prompt may require the assistance of one or more tools.
  3. Claude evaluates the prompt and determines the applicability of any tools.
  4. If deemed useful, Claude selects the relevant tools along with the necessary input.

Solution Overview

In this post, we will walk through how to extract custom fields from driver’s licenses using Claude Tool use in Amazon Bedrock. This serverless solution processes documents in real-time, efficiently extracting information such as names, dates, and addresses without the traditional requirement for model training.

Architecture

Our custom entity recognition solution uses a serverless architecture to process documents efficiently, utilizing Amazon Bedrock’s Claude model. This minimizes the need for complex infrastructure management while providing scalable, on-demand processing capabilities.

Solution Workflow:

  1. Users upload documents into Amazon S3 for processing.
  2. An S3 PUT event notification triggers an AWS Lambda function.
  3. Lambda processes the document and sends it to Amazon Bedrock.
  4. Amazon Bedrock invokes Anthropic Claude for entity extraction.
  5. Results are monitored and logged in Amazon CloudWatch.

Architecture Components:

  • Amazon S3: Stores input documents.
  • AWS Lambda: Triggers on file upload, sends prompts and data to Claude, and stores results.
  • Amazon Bedrock (Claude): Processes input and extracts entities.
  • Amazon CloudWatch: Monitors and logs workflow performance.

Prerequisites

Before diving deeper, ensure you have the following set up:

  • An AWS account
  • Basic understanding of AWS services like S3, Lambda, and IAM

Step-by-Step Implementation Guide

Let’s walk through the process of building a serverless document processing solution using Amazon Bedrock and related AWS services.

1. Setting Up Your Environment (10 minutes)

  • Create a source S3 bucket for input (e.g., driver-license-input).
  • Configure IAM roles and permissions to allow access to S3 and Bedrock.
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "bedrock:InvokeModel",
      "Resource": "arn:aws:bedrock:*::foundation-model/*",
      "arn:aws:bedrock:*:111122223333:inference-profile/*"
    },
    {
      "Effect": "Allow",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
    }
  ]
}

2. Creating the Lambda Function (30 minutes)

  • This Lambda function will be triggered whenever a new image is uploaded to your S3 bucket.

Lambda Code Sample:

import boto3
import json
import base64

def lambda_handler(event, context):
    # Initialize clients
    bedrock = boto3.client("bedrock-runtime")
    s3 = boto3.client("s3")

    bucket = event["Records"][0]["s3"]["bucket"]["name"]
    key = event["Records"][0]["s3"]["object"]["key"]
    file = s3.get_object(Bucket=bucket, Key=key)

    # Encode image to base64
    image_data = file["Body"].read()
    base64_image = base64.b64encode(image_data).decode('utf-8')

    # Define tool schema
    tools = [{
        "name": "extract_license_fields",
        "input_schema": {
            "type": "object",
            "properties": {
                "first_name": { "type": "string" },
                "last_name": { "type": "string" },
                "issue_date": { "type": "string" },
                "license_number": { "type": "string" },
                "address": {
                    "type": "object",
                    "properties": {
                        "street": { "type": "string" },
                        "city": { "type": "string" },
                        "state": { "type": "string" },
                        "zip": { "type": "string" }
                    }
                }
            },
            "required": ["first_name", "last_name", "issue_date", "license_number", "address"]
        }
    }]

    payload = {
        "anthropic_version": "bedrock-2023-05-31",
        "max_tokens": 2048,
        "messages": [{
            "role": "user",
            "content": [
                {"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": base64_image}},
                {"type": "text", "text": "Extract the driver's license fields from this image."}
            ]
        }],
        "tools": tools
    }

    try:
        response = bedrock.invoke_model(
            modelId="global.anthropic.claude-sonnet-4-5-20250929-v1:0",
            body=json.dumps(payload)
        )
        result = json.loads(response["body"].read())
        return {
            "statusCode": 200,
            "body": json.dumps({"message": "Process completed", "raw_response": result}, indent=2)
        }
    except Exception as e:
        return {
            "statusCode": 500,
            "body": json.dumps({"error": str(e), "type": str(type(e))})
        }

3. Configure Lambda Timeout

  • Increase Timeout: Adjust the timeout from the default 3 seconds to at least 30 seconds.

4. S3 Event Notification (5 minutes)

  • Open the Amazon S3 console.
  • Select your S3 bucket, go to the Properties tab, and set up an event notification for PUT events to trigger your Lambda function.

5. Testing and Validation (15 minutes)

  • Upload a sample driver’s license image to validate the extraction process.
  • Use CloudWatch to monitor execution results and troubleshoot any errors.

Performance Optimization

  • Configure Lambda memory and timeout settings.
  • Implement batch processing for multiple documents.
  • Utilize S3 event notifications for automatic processing.

Security Best Practices

  • Implement encryption at rest for S3 buckets.
  • Apply least privilege IAM policies.
  • Enable Virtual Private Cloud (VPC) endpoints for private network access.

Error Handling and Monitoring

To debug effectively, always log the raw response from Claude. Utilizing structured error handling in your Lambda function can help capture issues and refine your approach.

Conclusion

Claude Tool use in Amazon Bedrock presents a powerful solution for custom entity extraction, minimizing the reliance on complex machine learning models. This serverless architecture promotes scalable, cost-effective processing of documents with little setup and maintenance. By leveraging large language models through Amazon Bedrock, organizations can unlock new levels of efficiency, insight, and innovation in handling unstructured data.

Next Steps

We encourage you to explore this solution further by implementing the sample code in your environment and customizing it for your specific needs. Join the AWS re:Post community to share your experiences and learnings about entity extraction solutions.

For deeper technical insights, explore the comprehensive documentation on Amazon Bedrock, AWS Lambda, and Amazon S3. Consider integrating with Amazon Textract and Amazon Comprehend for additional capabilities. For enterprise solutions, reach out through your AWS account team.


About the Authors

Kimo El Mehri: Kimo is an AWS Solutions Architect with expertise spanning infrastructure, storage, security, GenAI, and data analytics. He is passionate about helping customers leverage AWS services to drive their digital transformation.

Johana Herrera: A Solutions Architect at AWS, Johana specializes in generative AI and analytics. She enjoys assisting customers in architecting solutions involving security and resilience.

Latest

OpenAI Shifts ChatGPT Shopping Strategy Following Disappointing Instant Checkout Performance

OpenAI Repositions ChatGPT as a Product Discovery Tool Amid...

Agile Robots and Google DeepMind: Pioneering the Future of AI Robotics

Transforming Robotics: DeepMind and Agile Robots Forge Innovative Partnership...

OpenAI Announces Shutdown of Sora, Its Generative AI Video Creation Tool

OpenAI’s Sora AI Video Application Discontinued Amid Declining Interest A...

Don't miss

Haiper steps out of stealth mode, secures $13.8 million seed funding for video-generative AI

Haiper Emerges from Stealth Mode with $13.8 Million Seed...

Running Your ML Notebook on Databricks: A Step-by-Step Guide

A Step-by-Step Guide to Hosting Machine Learning Notebooks in...

VOXI UK Launches First AI Chatbot to Support Customers

VOXI Launches AI Chatbot to Revolutionize Customer Services in...

Investing in digital infrastructure key to realizing generative AI’s potential for driving economic growth | articles

Challenges Hindering the Widescale Deployment of Generative AI: Legal,...

10 Best YouTube Channels for Mastering Machine Learning

Your Ultimate Guide to Learning Machine Learning: 10 YouTube Channels for Every Learning Style In the ever-evolving world of AI and machine learning, figuring out...

How Bark.com and AWS Partnered to Create a Scalable Video Generation...

Revolutionizing Video Content Creation: How Bark.com Leveraged AWS for AI-Powered Solutions Author Collaboration: Insights from Hammad Mian and Joonas Kukkonen of Bark.com Revolutionizing Video Content Creation:...

Assessing AI Agents for Production: A Practical Guide to Strands Evaluations

Systematic Evaluation of AI Agents: Challenges and Solutions with Strands Evals Understanding the Unique Evaluation Needs of AI Agents Core Concepts Behind Strands Evals Connecting Agents to...