Building Custom Human Review Loops with Amazon Augmented AI (A2I)


In our last article, we explored the architecture of Amazon Augmented AI (A2I) and how it enables human-in-the-loop workflows with minimal overhead. Now, it’s time to get hands-on and walk through the process of creating a custom human review loop using A2I.
This guide will equip you with practical steps and code snippets to build workflows that combine AI predictions with human validation. By the end, you’ll understand how to integrate A2I into your machine learning lifecycle.
What is a Human Review Loop?
A human review loop (also known as a human-in-the-loop or HITL loop) is a feedback cycle where:
A machine learning model makes a prediction.
The prediction is sent to a human for review (based on defined rules).
The human provides validation or corrections.
The corrected results are logged or used to retrain the model.
This ensures higher accuracy, especially in critical domains like healthcare, finance, document processing, and fraud detection.
When Should You Use a Custom Loop?
Custom workflows are best when:
You have your own model (e.g., deployed via SageMaker).
You want full control over the user interface (UI).
You need to define specific logic for triggering reviews.
Prerequisites
To follow along, ensure you have:
An AWS account with SageMaker permissions.
IAM role with A2I and S3 access.
A model deployed or mock inference function.
Step-by-Step: Create a Custom A2I Workflow
Step 1: Create an S3 Bucket
Store input data, human review results, and metadata.
aws s3 mb s3://my-a2i-review-bucket
Step 2: Set Up a Work Team
Use SageMaker Ground Truth to create a work team.
Choose between private team, vendor-managed, or Mechanical Turk.
Step 3: Design a Human Task UI
This is the web UI your reviewers will use. Save this as an HTML template.
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
<crowd-text-area name="textReview" label="Please review this text:" value="${text}" required></crowd-text-area>
</crowd-form>
Upload it:
aws sagemaker create-human-task-ui \
--human-task-ui-name "TextReviewUI" \
--ui-template file://review-ui.html
Step 4: Define a Flow Definition
This JSON file specifies your A2I workflow.
{
"FlowDefinitionName": "CustomTextReviewFlow",
"HumanLoopConfig": {
"WorkteamArn": "<your-workteam-arn>",
"HumanTaskUiArn": "<your-ui-arn>",
"TaskCount": 1,
"TaskDescription": "Review low-confidence text predictions",
"TaskTitle": "Human Text Validation"
},
"OutputConfig": {
"S3OutputPath": "s3://my-a2i-review-bucket/results/"
},
"RoleArn": "<iam-role-with-sagemaker-and-a2i-access>"
}
Use the AWS CLI:
aws sagemaker create-flow-definition --cli-input-json file://flow-definition.json
Step 5: Call A2I in Your App or Lambda
Once your model runs, trigger A2I with low-confidence predictions.
import boto3, json
a2i = boto3.client('sagemaker-a2i-runtime')
response = a2i.start_human_loop(
HumanLoopName='text-review-001',
FlowDefinitionArn='your-flow-arn',
HumanLoopInput={
'InputContent': json.dumps({ 'text': 'Model predicted: "This product is amazing!"' })
}
)
Step 6: View Results in S3
Once the human review is complete, A2I will store the approved/corrected text in your S3 bucket.
You can:
Export the result to a database or CMS.
Use it to retrain your ML model.
Monitor quality for compliance.
Example: Email Classification
Let’s say you’re classifying emails as "spam" or "not spam". But model confidence is low for certain messages.
Workflow:
Prediction = 55% confidence → Send to A2I
Human tags it manually
Corrected label saved in S3
Data used for retraining the spam classifier every week
Tips for Custom Workflows
HumanLoopName must be unique — append a timestamp or UUID.
Rotate reviewers — avoid fatigue and bias.
Use metadata — include helpful context (e.g., timestamp, source).
Random sample reviews — even high-confidence predictions need auditing.
Monitor workflows — use CloudWatch and S3 event notifications.
Next: Model Retraining from Human Feedback
With a complete loop in place, your next step is to feed these human-validated labels back into your training dataset. This creates a powerful feedback mechanism to make your models more accurate over time.
In the next article, we’ll dive into how to retrain ML models with A2I results and build continuous improvement pipelines.
Stay tuned and keep experimenting!
Subscribe to my newsletter
Read articles from Manas Upadhyay directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Manas Upadhyay
Manas Upadhyay
I am an experienced AWS Cloud and DevOps Architect with a strong background in designing, deploying, and managing cloud infrastructure using modern automation tools and cloud-native technologies.