c5.6 Harden agent prompts and validate input with Guardrails
Protect the agent's reasoning from manipulation with guardrails, instruction hardening, and a pre-processing validation layer, so prompt attacks cannot redirect the agent.
Implementation guidance
How to implement on AWS
Deploy a versioned Bedrock Guardrail invoked as part of the agent's response generation, with content filters, denied topics, and custom word filters. Harden agent instructions to resist manipulation, and add a pre-processing Lambda that sanitizes/validates input before it reaches the agent. Test regularly with adversarial techniques. Enforce guardrail use for direct Amazon Bedrock invocation with the bedrock:GuardrailIdentifier IAM condition key, so a model call without the approved guardrail is denied.
Acceptance criteria
A versioned guardrail runs in the agent's loop; instructions are hardened; a pre-processing validation layer exists; adversarial tests pass. A direct model invocation without the approved guardrail is denied.
Practical implementation
How this control is implemented in each reference architecture:
A versioned guardrail runs inside the agent's response loop in the Generative AI account, instructions are hardened, and a pre-processing Lambda validates input before it reaches the agent.
- Deploy a versioned Bedrock Guardrail invoked as part of the agent's response generation, with content filters, denied topics, and custom word filters.
- Enforce guardrail use, not just configure it. Attach an IAM identity policy that denies bedrock:InvokeModel, bedrock:InvokeModelWithResponseStream, bedrock:Converse, and bedrock:ConverseStream unless the bedrock:GuardrailIdentifier condition key matches the approved guardrail and version. To apply a guardrail across OUs or accounts, use an Amazon Bedrock policy in AWS Organizations that points to a versioned guardrail. This applies to direct Amazon Bedrock invocation; keep content guarding comprehensive so callers cannot skip evaluation with guard content tags.
- Harden agent instructions to resist manipulation, and add a pre-processing Lambda that sanitizes/validates input before it reaches the agent.
- Run adversarial test techniques regularly against the agent loop.
How to validate: A versioned guardrail runs in the agent's loop; instructions are hardened; a pre-processing validation layer exists; adversarial tests pass. A direct model invocation without the approved guardrail is denied.
Avoid: Relying on the system prompt alone to resist injection. Add a guardrail in the loop and a validation layer; prompts are not a security boundary.
A versioned guardrail in the agent loop, hardened instructions, and a pre-processing validation Lambda protect the agent's reasoning within the account.
- Run a versioned Bedrock Guardrail in the agent's response generation with content, denied-topic, and custom-word filters.
- Enforce guardrail use, not just configure it. Attach an IAM identity policy that denies bedrock:InvokeModel, bedrock:InvokeModelWithResponseStream, bedrock:Converse, and bedrock:ConverseStream unless the bedrock:GuardrailIdentifier condition key matches the approved guardrail and version. As an alternative or addition, set account-level guardrail enforcement in each Region you use. This applies to direct Amazon Bedrock invocation. The IAM condition key alone does not stop a caller from skipping prompt evaluation with guard content tags, so set content guarding to comprehensive in the account-level enforcement configuration. Do not use a role with this condition for APIs that call models on your behalf, such as RetrieveAndGenerate, InvokeAgent or InvokeInlineAgent, because some of those internal calls carry no guardrail and are denied.
- Harden instructions and add a pre-processing Lambda that validates input before the agent.
- Test regularly with adversarial techniques.
How to validate: A versioned guardrail runs in the loop; instructions are hardened; a validation layer exists; adversarial tests pass. A direct model invocation without the approved guardrail is denied.
Avoid: No guardrail inside the agent loop. Injection can redirect the agent; filter and validate at every turn.
Threats addressed
- Prompt injection manipulating the agent's reasoning into unintended actions.
- Hallucinated or unwanted behavior from an unguarded agent.
AWS services
Framework mappings
OWASP GenAI/LLM Top 10 (2026)
- LLM01 Prompt Injection
- LLM07 Misinformation
NIST AI Risk Management Framework (AI 100-1)
- MEASURE.2 AI systems are evaluated for trustworthy characteristics
- MANAGE.1 AI risks are prioritized, responded to and managed
AWS Well-Architected Generative AI Lens (Security)
- GENSEC04-BP01 Implement a secure prompt catalog
- GENSEC04-BP02 Sanitize and validate user inputs to foundation models
OWASP GenAI Top 10 for Agentic Applications (2025)
- ASI01 Agent Goal Hijack
Learning resources
References
- AWS SRA for AI — Capability 5, Application security
AI Security Maturity Model