Skip to main content

Week 2: Architecture Patterns + RAI by Design

Week Overview

Objective: Learn the core AI architecture patterns (RAG, agentic, tool-use) and understand where RAI controls must be embedded structurally in each.
Time Estimate: 8–10 hours
Deliverable: RAI Threat Model Template β€” a reusable diagram with annotated risk layers for RAG, agentic, and tool-use patterns


RAG Architecture β€” RAI Failure Modes at Each Layer​

INPUT LAYER
β”œβ”€ User query arrives
β”œβ”€ ⚠️ Risk: Adversarial input / prompt injection
└─ πŸ›‘οΈ Control: Input validation, content safety classifier (Prompt Shield)

RETRIEVAL LAYER
β”œβ”€ Query β†’ Embedding β†’ Vector search β†’ Document chunks
β”œβ”€ ⚠️ Risk: Biased retrieval (some populations' content under-represented)
β”œβ”€ ⚠️ Risk: Stale or poisoned documents in the index
└─ πŸ›‘οΈ Control: Data freshness policy, source provenance tracking, access control

AUGMENTATION LAYER
β”œβ”€ Retrieved chunks added to prompt context
β”œβ”€ ⚠️ Risk: Indirect prompt injection (malicious content in retrieved docs hijacks LLM)
└─ πŸ›‘οΈ Control: Content scan on retrieved chunks before LLM injection

GENERATION LAYER
β”œβ”€ LLM generates response grounded in retrieved context
β”œβ”€ ⚠️ Risk: Hallucination (claims not supported by retrieved content)
β”œβ”€ ⚠️ Risk: Harmful content despite grounding
└─ πŸ›‘οΈ Control: Groundedness evaluator, output content safety filter

OUTPUT LAYER
β”œβ”€ Response returned to user
β”œβ”€ ⚠️ Risk: No disclosure that content is AI-generated
└─ πŸ›‘οΈ Control: AI disclosure, source citations, human review gate for high-stakes domains

Agentic Architecture β€” Trust Boundaries and Autonomous Risk​

AGENT LOOP ARCHITECTURE
─────────────────────────────────────────────────────────
User Intent β†’ [Planner LLM]
↓ Decides tool calls
[Tool Execution] ──→ External Systems (DB, API, email, code)
↓ Results returned
[Reasoning LLM] ──→ Next decision
↓
[Output] β†’ User / Next Agent

RAI RISK HOTSPOTS:
β”œβ”€ Planner LLM: Can be manipulated via prompt injection in tool results
β”œβ”€ Tool Execution: No human oversight between decision and action
β”œβ”€ Multi-turn loop: Accumulated context may degrade decision quality
└─ Multi-agent: Downstream agents inherit the trust of calling agents

The 3 non-negotiable architectural RAI controls for agents:

  1. Confirmation gates β€” for any irreversible action (send email, delete record, deploy code), require explicit human confirmation
  2. Audit log per tool invocation β€” caller identity, parameters, timestamp, result; stored outside the agent's context
  3. Blast radius limitation β€” scope each agent's tool permissions to the minimum required

OWASP LLM Top 10 β€” The Architect's View​

These are architectural failures, not application bugs:

RiskRoot Architectural CauseDesign Fix
LLM01: Prompt InjectionUser data and system instructions share the same input channelSeparate channels; scan retrieved content before injection
LLM02: Insecure Output HandlingLLM output rendered without sanitizationTreat all LLM output as untrusted; sanitize before passing to downstream systems
LLM03: Training Data PoisoningNo data governance on fine-tuning or RAG sourcesSource provenance required; freshness policy; adversarial input testing
LLM06: Excessive AgencyAgent has more permissions than its task requiresPrinciple of least privilege for every tool; scoped OAuth tokens
LLM08: Excessive Data ExposureSystem prompt includes sensitive data unnecessarilyData minimization in context construction
LLM09: OverrelianceNo human in the loop for high-stakes decisionsMandatory review gates; confidence thresholds routing low-confidence outputs to humans

STRIDE-AI Threat Modeling Extension​

STRIDE CategoryAI-Specific AttackArchitecture Mitigation
SpoofingPrompt injection impersonates the systemSystem/user prompt separation; instruction hierarchy
TamperingData poisoning corrupts RAG indexSource validation; signed document provenance
RepudiationAgent takes action with no audit trailImmutable audit log per tool invocation
Information DisclosureSystem prompt extraction; PII leakage via modelNo secrets in prompts; PII detection on output
Denial of ServiceAdversarial prompts causing infinite loops or max token consumptionInput length limits; loop detection in agent runtime
Elevation of PrivilegeConfused deputy β€” tricked agent uses legitimate credentials for attackerToken scoping; per-agent managed identity

This Week's Resources​

ResourceTypeEstimated Time
Azure OpenAI RAG Architecture GuideArchitecture deep-dive2 hours
Azure AI Architecture CenterReference1.5 hours
OWASP LLM Top 10Full read1.5 hours
MITRE ATLAS β€” AI Threat MatrixReference1 hour
Semantic Kernel Agent FrameworkTechnical1.5 hours

Hands-On Exercise​

Exercise β€” Annotate a RAG Architecture

Draw a RAG architecture diagram. For each component (data ingestion, embedding, retrieval, generation, output):

  1. Label the RAI risk at that layer (use OWASP LLM Top 10 as reference)
  2. Label the mitigation control you would add
  3. Label the owner of that control (data team / AI team / security / product)

Then answer: Which layer has the weakest RAI coverage in most RAG implementations you've seen β€” and why?


Week 2 Deliverable: RAI Threat Model Template​

Build a reusable threat model template with:

  • RAG layer diagram with risk annotations (one threat + one control per layer)
  • Agentic loop diagram with trust boundary markings
  • STRIDE-AI extension table (6 rows, AI-specific attack + mitigation for each)

Knowledge Check​

  1. In a RAG system, what is the risk of indirect prompt injection and at which layer does it occur?
  2. Why is "Excessive Agency" (OWASP LLM06) an architectural problem, not a code bug?
  3. A developer says: "Our agent only calls read-only APIs, so we don't need a confirmation gate." What RAI risk does this reasoning miss?
  4. In STRIDE-AI, which category covers the "confused deputy" attack pattern?