AI Engineering with Python
Learn to build reliable applications on top of large language models: API calls, prompting, embeddings, RAG, tool use and agents, all measured with evals and deployed as real services. Vendor-neutral, using each provider's official SDK docs.
What you will be able to do
- Call LLM APIs with streaming, structured output, retries and cost control
- Write and version prompts that behave predictably
- Build retrieval-augmented generation over your own documents
- Give models tools and build safe, bounded agent loops
- Measure quality with evals and deploy an LLM service to production
Roadmap
Bar length shows each module's share of study time.
- 110h3 topics
Foundations
Enough theory and Python to build with confidence.
Show topicsNot startedExplain tokens, context limits, temperature and why models hallucinate.
- Explain tokens and tokenisation
- Understand context window limits
- Experiment with temperature and top-p
- Explain why models hallucinate
Compare models on quality, latency, cost, context size and licensing for a use case.
- Compare hosted and open-weight models
- Compare quality, latency and cost
- Check context size and licensing
Write typed async Python and validate data with Pydantic models.
- Write async functions with asyncio
- Add type hints throughout
- Validate data with Pydantic models
- Run concurrent API calls with gather
- 212h5 topics
Working with LLM APIs
Production-quality calls to any model provider.
Show topicsNot startedSend multi-turn chat requests with system prompts using a provider's official Python SDK.
- Install a provider SDK and set API keys
- Send a single-turn request
- Add a system prompt
- Build a multi-turn conversation
Stream tokens to a terminal or web client and handle partial output.
- Stream tokens to the terminal
- Stream to a web client
- Handle partial and interrupted output
Get validated, typed objects back from a model instead of free text.
- Define an output JSON schema
- Request structured output from the model
- Parse responses into Pydantic models
- Handle validation failures
Wrap model calls with backoff, timeouts and graceful fallbacks.
- Add timeouts to model calls
- Retry with exponential backoff
- Handle rate limit errors
- Add a fallback model
Estimate per-request cost and cut it with shorter prompts, caching and smaller models.
- Count tokens before sending
- Estimate cost per request
- Measure latency per call
- Cut cost with caching and smaller models
- 37h3 topics
Prompt engineering
Clear instructions beat clever tricks.
Show topicsNot startedWrite prompts with explicit task, context, constraints and output format.
- State the task explicitly
- Provide relevant context
- Set constraints and a role
- Specify the output format
Improve accuracy on a task with well-chosen examples and reasoning steps.
- Pick representative few-shot examples
- Ask for step-by-step reasoning
- Compare accuracy with and without examples
Keep prompts in version control with templates, variables and changelogs.
- Move prompts into templates
- Fill variables safely
- Version prompts in Git with a changelog
Module resources:Prompt Engineering Guide ↗ - 412h4 topics
Embeddings & retrieval
Find the right information before the model answers.
Show topicsNot startedEmbed text and rank documents by cosine similarity.
- Generate embeddings via an API
- Compute cosine similarity
- Rank documents for a query
- Visualise similar texts
Store and query embeddings with an approximate nearest-neighbour index.
- Install pgvector
- Store embeddings with metadata
- Query nearest neighbours
- Add an HNSW or IVFFlat index
Parse PDFs and web pages and chunk them so retrieval returns useful passages.
- Parse PDFs and HTML into text
- Chunk by size with overlap
- Chunk by structure and headings
- Compare retrieval across chunk sizes
Combine keyword and vector search and rerank results for better precision.
- Add keyword search with BM25 or tsvector
- Fuse keyword and vector results
- Rerank with a cross-encoder
- Measure precision before and after
- 510h3 topics
Retrieval-augmented generation
Answers grounded in your own data.
Show topicsNot startedAnswer questions over a document set with retrieved context injected into the prompt.
- Ingest and index a document set
- Retrieve top-k chunks for a query
- Inject context into the prompt
- Generate grounded answers
- Test with real questions
Return answers with source citations and refuse when context is missing.
- Return source citations with answers
- Instruct the model to stay in context
- Refuse when context is missing
Handle follow-up questions and filter retrieval by user, date or type.
- Rewrite follow-up questions as standalone
- Filter retrieval by metadata
- Store and summarise conversation history
- 612h4 topics
Tool use & agents
Let models take actions, within limits.
Show topicsNot startedDefine tools with JSON schemas and execute model-requested calls safely.
- Define tools with JSON schemas
- Handle tool call responses
- Execute calls and return results
- Validate tool arguments safely
Build a bounded agent loop with step limits, state and stop conditions.
- Implement a plan-act-observe loop
- Track state between steps
- Add step limits and stop conditions
- Log each step for debugging
Expose your own tools through an MCP server and connect a client to it.
- Learn MCP concepts: servers, tools, resources
- Build a small MCP server
- Connect a client to your server
Threat-model an LLM app and add input, output and permission guardrails.
- Threat-model your LLM app
- Test prompt injection attacks
- Add input and output guardrails
- Limit tool permissions and data access
- 712h5 topics
Evaluation & observability
If you can't measure it, you can't improve it.
Show topicsNot startedCreate a labelled test set from real and synthetic examples covering edge cases.
- Collect real user examples
- Generate synthetic edge cases
- Label expected outputs
- Version the dataset
Score outputs automatically and calibrate an LLM judge against human labels.
- Write deterministic code checks
- Build an LLM-as-judge rubric
- Calibrate the judge against human labels
- Review disagreements by hand
Measure retrieval recall and answer faithfulness separately.
- Measure retrieval recall and precision
- Measure answer faithfulness
- Diagnose retrieval vs generation failures
Block prompt or model changes that lower eval scores.
- Run evals in a CI job
- Set score thresholds
- Fail builds on regressions
Trace every model call with inputs, outputs, latency and cost and collect user feedback.
- Trace every model call
- Log inputs, outputs, latency and cost
- Collect user feedback
- Review traces to find failures
- 812h4 topics
Deployment
From notebook to a service people rely on.
Show topicsNot startedExpose a streaming chat or RAG endpoint with auth and input validation.
- Create a FastAPI app
- Add a streaming chat endpoint
- Validate input with Pydantic
- Add API key or token auth
Protect your service and budget with caches, per-user limits and spend alerts.
- Cache repeated responses
- Rate limit per user
- Set spend budgets and alerts
Run an open model locally and swap it in behind the same interface.
- Install Ollama or llama.cpp
- Run an open-weight model locally
- Swap it in behind the same interface
- Compare quality and speed
Ship the service in Docker to a cloud host with secrets managed properly.
- Write a Dockerfile for the service
- Manage secrets with environment variables
- Deploy to a cloud host
- Add health checks and logs
- 917h2 topics
Capstone project
An AI app with evidence that it works.
Show topicsNot startedA problem statement, success criteria and a 30-example eval set before writing app code.
- Write the problem statement
- Define success criteria
- Build a 30-example eval set
- Plan the architecture
A deployed app with citations, at least one tool, an eval suite in CI and a README showing scores.
- Ingest and index the documents
- Build retrieval with citations
- Add at least one tool
- Run the eval suite in CI
- Deploy the app
- Document scores in the README