agentleFS
kayamankayaman/skills/aws-genai-lens/SKILL.md

aws-genai-lens

Skill3 starsChanged 8 months agoCC0-1.0View on GitHub

Enforces AWS Well-Architected Generative AI Lens best practices for foundation model workloads on Amazon Bedrock and SageMaker AI. Use when designing GenAI architectures, implementing RAG pipelines, selecting foundation models, configuring Bedrock Guardrails, fine-tuning models, optimizing GenAI costs, securing AI workloads, or applying responsible AI principles including fairness, explainability, and safety.

The file

Show its rules and text

We split this skill into the rules it gives an agent

40 rules. About 0 are common, 40 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈40

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    MUST start with prompt engineering and evaluate before investing in RAG or fine-tuning

    line 60
  2. Distinctive:

    MUST benchmark multiple models on representative tasks before selecting

    line 61
  3. Distinctive:

    SHOULD use the smallest model that meets quality requirements — model right-sizing is the single biggest cost lever

    line 62
  4. Distinctive:

    MUST implement a centralized prompt catalog with version control — treat prompts as code

    line 81
  5. Distinctive:

    MUST separate system prompts from user input to prevent instruction override

    line 82
  6. Distinctive:

    MUST use few-shot examples for tasks requiring consistent format or style

    line 83
  7. Distinctive:

    SHOULD implement prompt templates with variable substitution for maintainability

    line 84
  8. Distinctive:

    SHOULD measure and track prompt performance metrics (quality, latency, cost)

    line 85
  9. Distinctive:

    MUST use Bedrock Guardrails Prompt Attack filter on all user-facing endpoints

    line 89
  10. Distinctive:

    MUST sanitize and validate all user inputs before sending to the model

    line 90
  11. Distinctive:

    MUST assume injection CAN succeed — design defense-in-depth (input filtering + output validation + action authorization)

    line 91
  12. Distinctive:

    SHOULD separate system instructions from user content using clear delimiters

    line 92
  13. Distinctive:

    MUST NOT trust model output for security-critical decisions without validation

    line 93
  14. Distinctive:

    MUST implement contextual grounding checks to detect hallucination in RAG responses

    line 127
  15. Distinctive:

    SHOULD use hybrid search (vector + keyword) for better retrieval precision

    line 128
  16. Distinctive:

    SHOULD evaluate retrieval quality separately from generation quality

    line 129
  17. Distinctive:

    SHOULD implement metadata filtering to narrow retrieval scope

    line 130
  18. Distinctive:

    SHOULD fine-tune only when prompt engineering + RAG cannot achieve the required quality for behavior or style.

    line 136
  19. Distinctive:

    MUST establish baseline metrics with prompting + RAG before fine-tuning

    line 149
  20. Distinctive:

    MUST maintain a high-quality evaluation dataset throughout the fine-tuning process

    line 150
  21. Distinctive:

    SHOULD use LoRA as the default fine-tuning approach for cost efficiency

    line 151
  22. Distinctive:

    MUST implement safety guardrails on all production FM endpoints

    line 170
  23. Distinctive:

    MUST document model limitations and known failure modes

    line 171
  24. Distinctive:

    SHOULD establish AI governance processes before production deployment

    line 172
  25. Distinctive:

    MUST configure content filters on all user-facing FM endpoints

    line 189
  26. Distinctive:

    MUST enable PII detection for workloads handling personal data

    line 190
  27. Distinctive:

    SHOULD enable contextual grounding checks for all RAG workloads

    line 191
  28. Distinctive:

    MUST right-size the model — use the smallest model meeting quality requirements

    line 209
  29. Distinctive:

    SHOULD implement prompt caching for repeated prefixes (system prompts, few-shot examples)

    line 210
  30. Distinctive:

    SHOULD use batch processing for non-real-time workloads (up to 50% cost savings)

    line 211
  31. Distinctive:

    SHOULD implement intelligent routing by query complexity (simple queries → smaller model)

    line 212
  32. Distinctive:

    SHOULD set agent stopping conditions to prevent runaway loops

    line 213
  33. Distinctive:

    SHOULD optimize prompt length — shorter prompts with same quality reduce per-request cost

    line 214
  34. Distinctive:

    MUST enforce least privilege IAM policies for all FM endpoint access

    line 222
  35. Distinctive:

    MUST use AWS PrivateLink for private VPC-to-Bedrock connections in production

    line 223
  36. Distinctive:

    MUST use customer-managed KMS keys for encryption of model inputs/outputs and fine-tuning data

    line 224
  37. Distinctive:

    MUST enable CloudTrail logging for all Bedrock API calls

    line 225
  38. Distinctive:

    SHOULD implement defense-in-depth: IAM → VPC → WAF → Guardrails → input validation → output encoding

    line 226
  39. Distinctive:

    SHOULD use Bedrock AgentCore with Cedar policy language to enforce boundaries on agent tool calls

    line 227
  40. Distinctive:

    When designing or reviewing a GenAI workload on AWS:

    line 235

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

AWS Well-Architected Generative AI Lens

Reference: AWS GenAI Lens (updated Nov 2025)

When to Apply

  • Designing GenAI architectures on AWS (Bedrock, SageMaker AI)
  • Implementing RAG pipelines with vector stores and knowledge bases
  • Selecting foundation models and deciding between prompting, RAG, and fine-tuning
  • Configuring guardrails for content safety, PII protection, and hallucination detection
  • Optimizing GenAI workload costs (model selection, caching, batching)
  • Securing AI workloads (prompt injection defense, data protection, access control)
  • Applying responsible AI principles to production FM workloads

GenAI Design Principles

  1. Design for controlled autonomy — bound agent actions with explicit guardrails and stopping conditions
  2. Implement comprehensive observability — monitor prompts, responses, latency, cost, and quality metrics
  3. Optimize resource efficiency — right-size models; use caching and batching to reduce cost
  4. Establish distributed resilience — design for FM endpoint failures, throttling, and degraded responses
  5. Standardize resource management — centralize model access, prompt catalogs, and configuration
  6. Secure interaction boundaries — validate inputs, filter outputs, enforce least privilege on FM endpoints

Lifecycle Phases

PhaseKey Activities
1. ScopingDefine the business problem; determine if GenAI is the right solution; identify success metrics
2. Model SelectionEvaluate models by modality, accuracy, latency, cost, and context window; benchmark candidates
3. CustomizationPrompt engineering → RAG → fine-tuning (progressive investment); evaluate after each stage
4. Development & IntegrationBuild application logic, implement guardrails, integrate with existing systems
5. DeploymentDeploy to production with monitoring, scaling, and rollback capability
6. Continuous ImprovementMonitor quality metrics; refine prompts, retrieval, and models; manage model lifecycle

Model Selection and Customization Strategy

Decision Tree

Start with prompt engineering (lowest cost, fastest iteration)
  ↓ Not meeting quality bar?
Add RAG for knowledge-grounded tasks
  ↓ Still not meeting quality bar?
Fine-tune when behavior/style is the bottleneck
  ↓ Need maximum control?
Custom training via SageMaker HyperPod
  • MUST start with prompt engineering and evaluate before investing in RAG or fine-tuning
  • MUST benchmark multiple models on representative tasks before selecting
  • SHOULD use the smallest model that meets quality requirements — model right-sizing is the single biggest cost lever

Model Selection Criteria

CriterionConsiderations
ModalityText, image, audio, video, multi-modal, embedding
QualityAccuracy on your task benchmarks; reasoning capability
Context WindowHow much input context the task requires
LatencyReal-time vs batch tolerance
CostPer-token pricing; throughput pricing; reserved capacity
ProviderAnthropic, Meta, Mistral, Amazon, Cohere, AI21, Stability AI (via Bedrock)

Prompt Engineering

Rules

  • MUST implement a centralized prompt catalog with version control — treat prompts as code
  • MUST separate system prompts from user input to prevent instruction override
  • MUST use few-shot examples for tasks requiring consistent format or style
  • SHOULD implement prompt templates with variable substitution for maintainability
  • SHOULD measure and track prompt performance metrics (quality, latency, cost)

Prompt Injection Defense

  • MUST use Bedrock Guardrails Prompt Attack filter on all user-facing endpoints
  • MUST sanitize and validate all user inputs before sending to the model
  • MUST assume injection CAN succeed — design defense-in-depth (input filtering + output validation + action authorization)
  • SHOULD separate system instructions from user content using clear delimiters
  • MUST NOT trust model output for security-critical decisions without validation

RAG (Retrieval-Augmented Generation)

RAG augments FM responses with retrieved knowledge, reducing hallucination and keeping responses grounded.

Amazon Bedrock Knowledge Bases

Automates the full RAG pipeline: ingestion → chunking → embedding → vector storage → retrieval → prompt augmentation.

Vector Store Options

StoreBest ForKey Feature
OpenSearch ServerlessGeneral-purpose vector searchFully managed; hybrid search (vector + keyword)
Aurora PostgreSQL (pgvector)Teams already using AuroraFamiliar SQL; transactional consistency
Neptune AnalyticsKnowledge graph + vector (GraphRAG)Links related content; improves complex reasoning
Amazon S3 Vectors (2025)High-scale, cost-sensitive workloadsUp to 2B vectors/index; ~90% cost reduction vs specialized DBs
MongoDB AtlasMongoDB-native teamsAtlas Vector Search integration
PineconeDedicated vector DB teamsPurpose-built vector search

Chunking Strategies

StrategyUse When
Fixed-sizeUniform content; simple implementation
SemanticContent with natural topic boundaries
HierarchicalContent with parent-child structure (sections, subsections)
Custom (Lambda)Domain-specific chunking logic required

RAG Quality Rules

  • MUST implement contextual grounding checks to detect hallucination in RAG responses
  • SHOULD use hybrid search (vector + keyword) for better retrieval precision
  • SHOULD evaluate retrieval quality separately from generation quality
  • SHOULD implement metadata filtering to narrow retrieval scope

Fine-Tuning

SHOULD fine-tune only when prompt engineering + RAG cannot achieve the required quality for behavior or style.

Approaches

ApproachUse WhenCost
Supervised Fine-Tuning (SFT)Specific task format or domain styleModerate
Continued Pre-TrainingDomain-specific vocabulary and knowledgeHigh
LoRA (Low-Rank Adaptation)Resource-efficient task adaptationLow — dramatically less compute
QLoRAFine-tuning on limited GPU memoryVery low
Model DistillationCompress a large model's capability into a smaller oneModerate
Reinforcement Fine-Tuning (2025)Align model behavior with human preferencesHigh — but avg 66% accuracy gain
  • MUST establish baseline metrics with prompting + RAG before fine-tuning
  • MUST maintain a high-quality evaluation dataset throughout the fine-tuning process
  • SHOULD use LoRA as the default fine-tuning approach for cost efficiency

Responsible AI

Eight Dimensions

DimensionKey Practices
FairnessBias detection and auditing across demographics; diverse evaluation datasets
ExplainabilityInterpretable decisions; document model limitations and known failure modes
Privacy & SecurityEncryption at rest/transit; access controls; regulatory compliance (GDPR, HIPAA)
SafetyContent filtering; guardrails; output validation; harmful content prevention
ControllabilityHuman oversight; monitoring; ability to adjust or override model behavior
Veracity & RobustnessAccuracy validation; automated reasoning for hallucination detection; adversarial testing
GovernanceAI review committees; model cards; documentation; escalation procedures
TransparencyClear disclosure that content is AI-generated; model provenance documentation
  • MUST implement safety guardrails on all production FM endpoints
  • MUST document model limitations and known failure modes
  • SHOULD establish AI governance processes before production deployment

Amazon Bedrock Guardrails

Six safeguard policies applied on both inbound prompts and outbound responses:

PolicyPurposeConfiguration
Content FiltersBlock hate, insults, sexual, violence, misconduct, prompt attackConfigurable strength per category
Denied TopicsBlock up to 30 specific topicsNatural language topic descriptions
Word FiltersExact-match blocking of specific wordsWord list management
Sensitive Information FiltersDetect and block/mask PIIML-based detection; block or mask options
Contextual Grounding ChecksDetect hallucination in RAG responsesGrounding score threshold
Automated Reasoning ChecksFormal mathematical logic verification"First GenAI safeguard to use formal logic"
  • MUST configure content filters on all user-facing FM endpoints
  • MUST enable PII detection for workloads handling personal data
  • SHOULD enable contextual grounding checks for all RAG workloads
  • The ApplyGuardrail API works with ANY model, including self-hosted or third-party

Cost Optimization

Pricing Models

ModelUse When
On-Demand (per token)Variable, unpredictable workloads; development and testing
Provisioned ThroughputSustained, predictable production workloads; guaranteed capacity
Batch (up to 50% discount)Non-real-time processing; bulk document analysis
Cross-Region InferenceNeed lower latency or higher availability across regions

Cost Reduction Strategies

  • MUST right-size the model — use the smallest model meeting quality requirements
  • SHOULD implement prompt caching for repeated prefixes (system prompts, few-shot examples)
  • SHOULD use batch processing for non-real-time workloads (up to 50% cost savings)
  • SHOULD implement intelligent routing by query complexity (simple queries → smaller model)
  • SHOULD set agent stopping conditions to prevent runaway loops
  • SHOULD optimize prompt length — shorter prompts with same quality reduce per-request cost

Security

Rules

  • MUST enforce least privilege IAM policies for all FM endpoint access
  • MUST use AWS PrivateLink for private VPC-to-Bedrock connections in production
  • MUST use customer-managed KMS keys for encryption of model inputs/outputs and fine-tuning data
  • MUST enable CloudTrail logging for all Bedrock API calls
  • SHOULD implement defense-in-depth: IAM → VPC → WAF → Guardrails → input validation → output encoding
  • SHOULD use Bedrock AgentCore with Cedar policy language to enforce boundaries on agent tool calls

Key guarantee: Amazon Bedrock does not allow model providers to learn from customer data or prompts.


Checklist

When designing or reviewing a GenAI workload on AWS:

  • Business problem is clearly defined; GenAI is confirmed as the right approach
  • Model selection is based on benchmarks, not assumptions; smallest effective model chosen
  • Prompt engineering is exhausted before adding RAG; RAG before fine-tuning
  • Centralized prompt catalog exists with version control
  • Prompt injection defenses are implemented (Guardrails + input validation + defense-in-depth)
  • RAG pipeline uses appropriate chunking and includes contextual grounding checks
  • Bedrock Guardrails are configured: content filters, PII detection, and denied topics at minimum
  • Cost optimization applied: model right-sizing, caching, batching where applicable
  • IAM least privilege, PrivateLink, KMS encryption, and CloudTrail are configured
  • Responsible AI dimensions are addressed: safety, fairness, transparency, governance
  • Monitoring covers: latency, cost per request, quality metrics, guardrail triggers, error rates

Key References

Book / ResourceAuthor(s)PublisherYear
AWS Well-Architected Generative AI Lens (official)AWSAWS Docs2025
AI EngineeringChip HuyenO'Reilly2025
Generative AI on AWSFregly, Barth, EigenbrodeO'Reilly2023
Hands-On Large Language ModelsJay Alammar, Maarten GrootendorstO'Reilly2024
Build a Large Language Model (From Scratch)Sebastian RaschkaManning2024
Designing Machine Learning SystemsChip HuyenO'Reilly2022

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.