Skip to content

19 · Hands-On Labs

Twenty practical labs, from your first API call to a secure enterprise AI gateway. Every lab runs in two modes:

Mode How Cost Use it to
Mock (default) CLAUDE_LAB_MODE=mock Free, offline Learn the code path and run the self-checks. CI runs every lab this way.
Live CLAUDE_LAB_MODE=live plus an API key Uses API credits See real model behaviour

Cost: live mode calls the Claude API and is billed to your account. Most labs make a handful of short requests; each lab README states what live mode does. Set a spend limit in the Console before experimenting.

Setup (once)

# from the repository root
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements-dev.txt                 # repo tooling
pip install -r 19-hands-on-labs/requirements.txt    # only needed for live mode
cp 19-hands-on-labs/.env.example 19-hands-on-labs/.env   # optional; .env is git-ignored

For live mode, provide credentials through the environment, never in code:

export CLAUDE_LAB_MODE=live
export ANTHROPIC_API_KEY=...   # or run `ant auth login`; the SDK picks up the active profile

Run a lab:

python 19-hands-on-labs/lab-01-first-claude-interaction/lab.py

Run them all in mock mode (as CI does):

python tools/run_lab_smoke.py

How the labs work

All labs import common/claude_lab.py. It provides:

  • get_client(): the real anthropic.Anthropic() client in live mode, or a deterministic offline mock in mock mode.
  • register_mock(fn): each lab registers realistic canned responses, so mock mode exercises the same code path.
  • Guardrails that mirror the current API: the mock rejects temperature, top_p, top_k, assistant prefill and forced tool_choice, so mistakes surface offline before they cost money.
  • MODEL (default claude-opus-5-5) and FAST_MODEL (default claude-haiku-5-5), overridable via environment variables.

Lab catalogue

# Lab Level You will learn Main modules
01 First Claude interaction Beginner Messages, system prompts, stop reasons, usage 06
02 Prompt improvement Beginner Iterating a prompt against a rubric 03
03 Structured outputs Beginner JSON Schema outputs and validation 03
04 Document-grounded Q&A Beginner Quote-first grounding; saying "not found" 04
05 Context management Intermediate Token counting, summarising, caching layout 04
06 Model comparison Intermediate Quality, latency and cost trade-offs 05
07 API integration Intermediate Retries, timeouts, request IDs, streaming 06
08 Tool invocation Intermediate The tool-use loop, validation, errors 07
09 MCP fundamentals Intermediate MCP handshake, tools, allow-lists 08
10 Claude Code workflows Intermediate CLAUDE.md, permissions, hooks, commands 09
11 RAG pipeline Intermediate Chunking, BM25, retrieval metrics, citations 11
12 Agentic task execution Advanced Bounded agent loops and traces 10
13 Human-in-the-loop approvals Advanced Risk-tiered actions and approval gates 10
14 Prompt injection testing Advanced A defensive test harness for injection 12
15 Sensitive data protection Advanced PII detection, redaction, tokenisation 12
16 Evaluation framework Advanced Golden sets, graders, LLM-as-judge, A/B 14
17 Cost optimisation Intermediate Caching, batch and routing economics 15
18 Reliability engineering Advanced Backoff, circuit breakers, fault injection 15
19 Observability Advanced Structured logs, spans, metrics, redaction 15
20 Secure enterprise AI architecture Advanced An AI gateway combining labs 13–19 13, 12

Suggested paths: business users (CCAO-F) take labs 01–06; architects (CCAR-P) take all twenty, focusing on 08–20; security engineers take 08, 09, 13–15 and 18–20.

Lab conventions

Each lab README has the same sections: Objective; Level, time and cost; Prerequisites; Architecture; Setup; Walkthrough; Synthetic test data; Execution steps; Expected results; Troubleshooting; Security considerations; Cleanup; Exam relevance.

  • All data is synthetic and every organisation is fictional.
  • No credentials are ever stored in the repository. tools/scan_secrets.py and gitleaks enforce this in CI.
  • Treat model output as untrusted input. Labs validate it before acting on it.
  • Problems? See 24-troubleshooting/labs-and-repository.md.