Generative AI Design Patterns
Build robust GenAI applications from proven patterns: structured output, RAG, reasoning, agents with tools and hand-offs, guardrails and evaluation, each built, measured and its trade-offs known.
Advanced · Generative AI · about 29 hours · 5 modules · certificate on completion
Taught by Erikà Lindströmè, Abderrahmàn Bensoussàn, AI Learning Companions.
About this course
A demo built on a large language model can look finished in an afternoon; a GenAI application people can rely on takes design. This course teaches the patterns that close that gap, each as a problem, a solution and its trade-offs: controlling output with prompt structure, schemas, sampling and caching; retrieval-augmented generation with good chunking, hybrid search and re-ranking; reasoning with chain-of-thought, self-consistency, tree-of-thoughts search and reflection; agents that call tools in a bounded loop, route requests, hand off to each other with structured messages, ask a person before acting, and remember; and the safeguards that keep it all honest: grounding, guardrails, prompt-injection defence and evaluation.
The labs follow a hydropower plant's operations assistant. Every lab runs offline with scripted model replies, so its checks print the same numbers on any machine, and every lab also runs live against the Claude API with your own key, using the Anthropic Python SDK with the model chosen in an environment variable. You'll measure how chunking and fusion change retrieval, watch a beam search prune the right answer, fix a function from its failing tests, build an agent loop with an approval gate, and turn an assistant that obeys an injected supplier bulletin into one that passes its whole golden set. The capstone is a multi-agent research assistant with an advanced RAG pipeline and integrated safeguards.
What you'll learn
- Control LLM output with prompt structure, validated structured output, sampling settings and caching
- Implement RAG pipelines with structure-aware chunking, hybrid search and re-ranking, measured with hit rate and MRR
- Improve reasoning with chain-of-thought, self-consistency, tree-of-thoughts search and reflection loops
- Design agentic systems with tool calling, routing, structured hand-offs, human approval and memory
- Integrate guardrails and prompt-injection defences, and evaluate GenAI systems with golden sets
Skills you'll gain
GenAI design patterns, Structured output, Retrieval-augmented generation, Hybrid search and re-ranking, Reasoning patterns, Tool calling and agents, Multi-agent orchestration, Guardrails, Prompt injection defence, LLM evaluation
Tools
Python 3, Claude API, Anthropic Python SDK, Pydantic, scikit-learn, NumPy
Before you start
Machine Learning Design Patterns, or experience designing ML systems; Python; and prompting basics (Prompting and LLM Application Design helps). Install Python 3.10 or newer, then: pip install anthropic pydantic numpy scikit-learn. Every lab runs offline without a key; for the optional --live runs you need a Claude Console API key with credit and CLAUDE_MODEL set to a current model ID from Anthropic's documentation.
Modules
GenAI Foundations and Output Control
How large language models generate text and what that means for system design, then the patterns that control their output: prompt structure, structured output with validation, sampling settings and caching.
- How LLMs generate text, and what that means for design (13 min)
- Prompt patterns: roles, examples, templates and chains (12 min)
- Structured output (13 min)
- Sampling settings and caching (13 min)
- Hands-on lab: Control the output: sampling, schemas and caches
Basic and Advanced RAG
Retrieval-augmented generation from the ground up: vector stores, lexical, semantic and hybrid search, chunking strategies, and the advanced retrieval patterns of query rewriting and re-ranking, all measured.
- The RAG pattern and vector stores (13 min)
- Semantic, lexical and hybrid search (12 min)
- Chunking strategies (12 min)
- Advanced retrieval: rewriting and re-ranking (13 min)
- Hands-on lab: Build and measure a retrieval pipeline
Reasoning Capabilities
Patterns that improve how models reason: chain-of-thought and step-by-step prompting, self-consistency voting, tree-of-thoughts search, and reflection loops driven by external feedback.
- Chain-of-thought and step-by-step reasoning (12 min)
- Self-consistency (12 min)
- Tree of thoughts (12 min)
- Reflection: generate, critique, revise (12 min)
- Hands-on lab: Vote, search and reflect with checkable answers
Agentic Systems
Systems where models act: tool calling, the ReAct agent loop, routing and multi-agent orchestration with structured hand-offs, and short- and long-term memory.
- Tool calling (12 min)
- The ReAct pattern and the agent loop (12 min)
- Routing and multi-agent orchestration (13 min)
- Memory management (12 min)
- Hands-on lab: Build an agent loop with routing, a hand-off and memory
Reliability and Safeguards
Make GenAI applications dependable and safe: mitigate hallucinations, guard inputs and outputs, defend against prompt injection, and evaluate the whole system with a golden set on every change.
- Mitigating hallucinations (12 min)
- Input and output guardrails (12 min)
- Defending against prompt injection (13 min)
- Evaluating GenAI systems (13 min)
- Hands-on lab: Guard a handbook assistant and prove it with a golden set
Project: A multi-agent research assistant with RAG and safeguards
Plant engineers ask multi-step research questions, such as preparing a readiness brief for inspecting a turbine: which limits apply, who must approve what, the work order's priority and deadline, the safety rules, and when the work can be done. Build a multi-agent research assistant for them over handbook.md, starting from research_assistant.py. An orchestrator splits the task into sub-questions with structured output; researcher agents answer each from an advanced RAG pipeline (structure-aware chunks, hybrid search, re-ranking) with citations; a writer combines the findings into a cited brief; and a reviewer runs a bounded reflection loop on grounding and citations. Integrate safeguards throughout: input guards and PII redaction, screening of the supplier bulletin's injected instructions, delimited prompts, output checks and no unapproved actions. Keep an offline mode with scripted replies so the evaluation in research_tasks.json runs anywhere, and run it live with Claude too.
Part of
The products this course names are trademarks of their owners, who haven't made or endorsed it.