As you deploy generative AI applications to diverse user groups, you might face a significant challenge that impacts user safety and application reliability: verifying each AI response is appropriate, accurate, and safe for the specific user receiving it. Content suitable for adults might be inappropriate or confusing for children, while explanations designed for beginners might be insufficient for domain experts. As AI adoption accelerates across industries, the need to match responses to user age, role, and domain knowledge has become essential for production deployments.
You might attempt to address this through prompt engineering or application-level logic. However, these approaches can create significant challenges. Prompt-based safety controls can be bypassed through manipulation techniques that tricks models into ignoring safety instructions. Application code becomes complex and fragile as personalization requirements grow, and governance becomes inconsistent across different AI applications. Furthermore, the risks of unsafe content, hallucinated information, and inappropriate responses are amplified when AI systems interact with vulnerable users or operate in sensitive domains like education and healthcare. The lack of centralized, enforceable safety policies creates operational inefficiencies and compliance risks.
To address these challenges, we implemented a fully serverless, guardrail-first solution using Amazon Bedrock Guardrails and other AWS services that align with modern AI safety and compliance alignment needs. The architecture provides three main components: dynamic guardrail selection based on user context, centralized policy enforcement through Amazon Bedrock Guardrails, and more secure APIs for authenticated access. You can use this serverless design to deliver personalized, safe AI responses without complex application code more efficiently, securely, and at scale.
In this post, we walk you through how to implement a fully automated, context-aware AI solution using a serverless architecture on AWS. We demonstrate how to design and deploy a scalable system that can:
This solution helps organizations looking to deploy responsible AI systems, align with compliance requirements for vulnerable populations, and help maintain appropriate and trustworthy AI responses across diverse user groups without compromising performance or governance.
This solution uses Amazon Bedrock, Amazon Bedrock Guardrails, AWS Lambda, and Amazon API Gateway as core services for intelligent response generation, centralized policy enforcement, and secure access. Supporting components such as Amazon Cognito, Amazon DynamoDB, AWS WAF, and Amazon CloudWatch help enable user authentication, profile management, security, and comprehensive logging.
What makes this approach unique is dynamic guardrail selection, where Amazon Bedrock and Bedrock Guardrails automatically adapt based on authenticated user context (age, role, industry) to help enforce appropriate safety policies at inference time. This guardrail-first approach works alongside prompt-based safety measures to provide layered protection, offering five specialized guardrails: Child Protection (Children’s Online Privacy Protection Act or COPPA-compliant), Teen Educational, Healthcare Professional, Healthcare Patient, and Adult General. These guardrails provide an authoritative policy enforcement layer that governs what the AI model is allowed to say, operating independently of application logic.
The solution uses serverless scalability, enforces safety policies, and adapts responses based on user context—making it well-suited for enterprise AI deployments serving diverse user populations. The solution can be deployed using Terraform, enabling repeatable and end-to-end automation of infrastructure and application components.
As shown in Figure 1, the web UI runs as a local demo server (localhost:8080) for testing and demonstration purposes. For production deployments, organizations can integrate the API endpoints with their existing web applications or deploy the interface to AWS services such as Amazon Simple Storage Service (Amazon S3) with Amazon CloudFront or AWS Amplify.

Figure 1: Serverless age-responsive-context-aware-ai-bedrock Architecture
Now that you understand the architecture components, let’s examine how the solution dynamically adapts responses based on different user contexts.The following diagram (Figure 2: age-responsive, context-aware AI with Amazon Bedrock Guardrails workflow) shows how different user profiles are handled:

Figure 2: age-responsive-context-aware-ai-bedrock Workflow
The solution workflow includes the following steps (refer to Figure 1: Solution architecture for age-responsive, context-aware AI with Amazon Bedrock Guardrails):
user_idFor a comprehensive overview of each guardrail’s configuration, including content filters, topic restrictions, PII handling, and custom filters, refer to the Guardrail Configuration Details in the Code repository.
1. For the question “What is DNA?”, the system generates different responses based on user context:
Student (Age 13):
“DNA is like a recipe book that tells your body how to grow and what you’ll look like! It’s made up of four special letters (A, T, G, C) that create instructions for everything about you.”
Healthcare Professional (Age 35):
“DNA consists of nucleotide sequences encoding genetic information through base pair complementarity. The double helix structure contains coding regions (exons) and regulatory sequences that control gene expression and protein synthesis.”
General Adult (Age 28):
“DNA is a molecule that contains genetic instructions for the development and function of living organisms. It’s structured as a double helix and determines inherited traits.”
2. The following example demonstrates how the same mathematical question receives age-appropriate responses:
Refer to the following screenshots for responses to the question: “How do I solve quadratic equations?” This makes it clearer how the same question gets different responses based on user context.
Teen Student (Age 13): Simple, step-by-step explanation with basic examples and friendly language suitable for middle school level (refer Figure 3)
For Math Teacher (Age 39): Comprehensive pedagogical approach including multiple solution methods, teaching strategies, and advanced mathematical concepts (refer to Figure 4)

Figure 3: Teen Student response with step-by-step guidance

Figure 4: Educator response with comprehensive teaching approach
Before deploying the solution, make sure that you have the following installed and configured:
git clone https://github.com/aws-samples/sample-age-responsive-context-aware-ai-bedrock-guardrails.git
$ cd sample-age-responsive-context-aware-ai-bedrock-guardrails
$ ./deploy.sh
The solution includes a web-based demo for immediate testing and advanced API testing capabilities.
For production enterprise deployments, host the web interface using AWS Amplify, Amazon S3 and Amazon CloudFront, or container services like Amazon Elastic Container Service (Amazon ECS) and Amazon Elastic Kubernetes Service (Amazon EKS). For detailed Amazon Bedrock Guardrails testing scenarios, API examples, and validation procedures, refer to the TESTING_GUIDE.md file in the cloned repository.
Interactive web demo:
$ cd web-demo
$ ./start_demo.sh
API testing :
$ cd utils
$ python3 generate_jwt.py student-123
$ curl -X POST "$(cd ../terraform && terraform output -raw api_url)"
-H "Content-Type: application/json"
-H "Authorization: Bearer <JWT_TOKEN>"
-d '{"query": "What is DNA?"}'
Explore the solution’s capabilities with these scenarios:
The cost of running this solution depends on usage patterns and scale. The following is an estimated monthly cost breakdown for a moderate usage scenario (1,000 API requests per day):

Estimated Total: $73-320/month depending on usage volume and model selection
Note: Actual costs vary based on request volume, model selection, data transfer, and Regional pricing. Use the AWS Pricing Calculator for customized estimates.
To avoid incurring ongoing charges, delete the AWS resources created during this walkthrough when they’re no longer needed. To remove deployed AWS resources and local files, run:
$ cd sample-age-responsive-context-aware-ai-bedrock-guardrails
$ ./ cleanup.sh
This solution demonstrates a guardrail-first approach to building context-aware AI applications. Key benefits include:
In this post, we demonstrated how to implement a fully serverless, guardrail-first solution for delivering age-responsive, context-aware AI responses. We showed how the previously mentioned AWS services work together to help dynamically select specialized guardrails based on user context, enforce safety policies, and deliver personalized responses. We deployed the architecture using Terraform, making it repeatable and production-ready. Through dynamic guardrail selection and centralized policy enforcement, this solution tailors AI responses to each user segment—from COPPA-compliant protection for children to clinical content for healthcare professionals—while maintaining enterprise-grade security and scalability. Organizations serving diverse user populations can benefit from reduced bypass risk, centralized governance, and operational flexibility when updating policies without modifying application code.
To get started, clone the repository and follow the deployment instructions. Test the solution using the interactive web demo to see how responses adapt based on user context. To learn more about Amazon Bedrock Guardrails, visit the Amazon Bedrock Guardrails documentation.
Manuel Rioux est fièrement propulsé par WordPress