LLM Engineering Tutorial with Examples.
LLM engineering tutorial: building with large language models through prompt engineering, RAG, fine-tuning, tool use and application architecture.
Architecture at a glance
Click any box to open the lesson that teaches it
LLM application at a glance
question → guard → prompt + retrieved context → model ↔ tools → validated answer
How it fits together (7 steps)
- A question comes in and is screened first: the input guard flags injection phrases and marks user text as data.
- The prompt is assembled from a template and a budgeted context: the best evidence at the edges, tool results trimmed.
- Retrieval supplies that evidence. Documents are chunked and turned into embeddings, a vector store returns the top chunks, hybrid search and a reranker fix the order, and three failure modes show what goes wrong.
- A provider router sends the call through one interface with timeouts and fallback, plus the retries, caching and model routing that keep cost down.
- The model may ask for tools. The tool-use loop answers every
tool_usewith atool_result; tools can live on MCP servers, and agents run the loop for many steps. - The reply is checked before it leaves: parsed and validated against a schema, then screened for leaks and personal data.
- Underneath: how the model works (tokens, the transformer, decoding, serving), and how you ship it: evals in CI, fine-tuning when prompting and RAG aren't enough, and security beyond guardrails.
Beginner
Start here — no prior experience needed
LLM Engineering Learning Roadmap
A structured path from how a transformer actually works to building and serving production-grade LLM applications — internals, prompting, RAG, fine-tuning, inference, and safety.
Introduction to LLM Engineering
Understand how large language models work, learn the OpenAI API, and write your first production LLM application.
How an LLM Actually Works
Trace a real prompt through tokenization, embeddings, transformer blocks, and next-token sampling using an actual small language model's real weights.
Tokenization
How LLMs split text into tokens with byte-pair encoding, and why identical sentences cost very different token counts in different languages.
Inference and Decoding
How a probability distribution becomes one chosen word — greedy decoding, temperature, top-k, top-p, and why temperature 0 isn't 'more certain'.
Pretraining, Instruction Tuning, and Alignment
The pipeline that turns a raw text predictor into a model that follows instructions — and why a chat template matters as much as the weights.
Prompt Engineering
Write effective prompts using few-shot examples, chain-of-thought reasoning, role prompting, and structured output techniques.
LLM Engineering Projects
Projects that build real LLM-powered applications — from prompt engineering basics to production RAG systems and fine-tuned models.
Intermediate
For developers with core concepts down
Structured Outputs in Production
Why 'return JSON only' isn't enough, and how schema validation plus a retry loop turns a flaky text model into a reliable data source.
LLM APIs and Provider Abstraction
A common interface over multiple LLM backends, with a real timeout-and-fallback router — so one provider's slow response doesn't become your outage.
LLM Tool Use and Function Calling
Tool schemas, argument validation, the tool_use/tool_result loop, error recovery, parallel calls and approval gates, all run against a scripted model.
RAG — Retrieval-Augmented Generation
Build a production RAG pipeline: chunk documents, embed them, store in a vector database, retrieve on query, and generate grounded answers.
RAG: Advanced Retrieval and Reranking
Hybrid search can rank the wrong document to the top — a real measured example, then the fixes: cross-encoder reranking and multi-query retrieval.
LLM Embeddings and Vector Search
What embeddings are, why keyword vectors miss meaning, cosine vs dot vs Euclidean, storage and search costs, choosing a model, and common uses.
RAG Failure Diagnosis
Why is my RAG system giving the wrong answer? Three real failure modes — bad chunking, stale documents, context overload — broken, then diagnosed.
Multimodal LLMs
Send images and documents to a model, and understand how cross-modal matching works under the hood with a real, runnable CLIP example.
LLM Context Engineering
Fit system prompt, history, documents and tool results into a token budget, cite sources, chunk by heading and trim tool output, all as runnable Python.
Long-Context Economics and Prompt Caching
Why a bigger context window isn't free to use — measured latency scaling, the cost of resending history, and when caching actually helps.
RAG vs. Fine-Tuning vs. Prompting
A decision framework for the three ways to change what a model knows or how it behaves, with a real example of one problem solved two different ways.
Advanced
Production-grade patterns for experienced engineers
LLM Fine-Tuning
Decide when fine-tuning pays off, build chat-format JSONL, validate it, catch duplicate and near-duplicate leakage, check balance, and compute break-even.
LoRA, QLoRA, and PEFT
Attach a LoRA adapter, train only 0.18% of a model's parameters, and measure the real 549x smaller checkpoint that results.
Quantization
Measure the real memory and quality trade-off of FP32, FP16, and INT8 precision, and where GPTQ, AWQ, and GGUF fit in production.
LLM Inference and Serving
Measure the real KV cache speedup, the prefill/decode split, and the batching win that vLLM, TGI, and Ollama all automate.
LLM Evaluation
Why overlap metrics mislead, assertion-based graders, judge calibration with kappa, retrieval recall and MRR, and a regression gate, all run in Python.
LLM Production Patterns
Retries with backoff and jitter, a SQLite response cache, token cost math, model routing, and a circuit breaker around LLM API calls, all run for real.
LLM Safety and Guardrails
Input screening, escaped delimiters, canary tokens, PII redaction, and per-user rate limits for LLM apps, including what each guardrail misses, all run.
LLM Security Beyond Guardrails
Indirect prompt injection, excessive agency, and insecure output handling — the OWASP-style risks that survive input/output guardrails.
Also part of LLM Engineering
Taught in other topics. Each link opens the lesson in its home topic.
Introduction to AI Agents
What makes an AI agent: tools, the ReAct loop of thought, action and observation, step caps that stop runaway loops, and memory that survives sessions.
Multi-Agent Systems
Orchestrators and subagents in runnable Python: parallel fan-out, partial failures, parsing a model's plan safely, and approval gates for risky tool calls.
MCP: Your First Server and Client
Build a Model Context Protocol server with one tool in Python, call it from a scripted client over stdio and in memory, and see why stdout is off limits.
MCP Tools: Schemas, Results and Errors
See the inputSchema MCP builds from Python type hints, return structured output, and tell tool errors from protocol errors, all with real printed results.