Skip to main content
Machine Learning & AI

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

LLM application at a glance A user's question passes an input guard, then a prompt and context builder fed by retrieval: documents become embeddings in a vector store, improved by hybrid search and reranking. A provider router with retries and fallback calls the LLM, which can call tools through a tool-use loop, MCP servers and agents. The reply is validated against a schema and checked for leaks before the answer returns. Rows at the bottom link the model internals and the build, ship and security lessons. You question Input guard injection check Prompt + context template · budget Provider router retry · fallback LLM Messages API Validate JSON schema Retrieval (RAG) Documents chunked Embeddings vectors · cosine Vector store top-k search Hybrid + rerank multi-query Diagnose failures chunking · stale docs top chunks Tools and agents Tool-use loop tool_use → tool_result MCP tool servers Agents many steps tool calls Output check leaks · PII Answer to the user Inside the model · what the LLM box does Tokenization Transformer Decoding Alignment KV cache Quantization LoRA · QLoRA Build, ship and secure Prompting Prompt cache Evals in CI Retries · cost Fine-tuning LLM security Multimodal
How it fits together (7 steps)
  1. A question comes in and is screened first: the input guard flags injection phrases and marks user text as data.
  2. The prompt is assembled from a template and a budgeted context: the best evidence at the edges, tool results trimmed.
  3. 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.
  4. A provider router sends the call through one interface with timeouts and fallback, plus the retries, caching and model routing that keep cost down.
  5. The model may ask for tools. The tool-use loop answers every tool_use with a tool_result; tools can live on MCP servers, and agents run the loop for many steps.
  6. The reply is checked before it leaves: parsed and validated against a schema, then screened for leaks and personal data.
  7. 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

8 lessons
llm beginner
5 min read

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.

llm beginner
5 min read

Understand how large language models work, learn the OpenAI API, and write your first production LLM application.

llm beginner
5 min read

Trace a real prompt through tokenization, embeddings, transformer blocks, and next-token sampling using an actual small language model's real weights.

llm beginner
5 min read

How LLMs split text into tokens with byte-pair encoding, and why identical sentences cost very different token counts in different languages.

llm beginner
5 min read

How a probability distribution becomes one chosen word — greedy decoding, temperature, top-k, top-p, and why temperature 0 isn't 'more certain'.

llm beginner
5 min read

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.

llm beginner
5 min read

Write effective prompts using few-shot examples, chain-of-thought reasoning, role prompting, and structured output techniques.

llm beginner
5 min read

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

11 lessons
llm intermediate
5 min read

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 intermediate
5 min read

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 intermediate
5 min read

Tool schemas, argument validation, the tool_use/tool_result loop, error recovery, parallel calls and approval gates, all run against a scripted model.

llm intermediate
5 min read

Build a production RAG pipeline: chunk documents, embed them, store in a vector database, retrieve on query, and generate grounded answers.

llm intermediate
5 min read

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 intermediate
5 min read

What embeddings are, why keyword vectors miss meaning, cosine vs dot vs Euclidean, storage and search costs, choosing a model, and common uses.

llm intermediate
5 min read

Why is my RAG system giving the wrong answer? Three real failure modes — bad chunking, stale documents, context overload — broken, then diagnosed.

llm intermediate
5 min read

Send images and documents to a model, and understand how cross-modal matching works under the hood with a real, runnable CLIP example.

llm intermediate
5 min read

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.

llm intermediate
5 min read

Why a bigger context window isn't free to use — measured latency scaling, the cost of resending history, and when caching actually helps.

llm intermediate
5 min read

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

8 lessons
llm advanced
5 min read

Decide when fine-tuning pays off, build chat-format JSONL, validate it, catch duplicate and near-duplicate leakage, check balance, and compute break-even.

llm advanced
5 min read

Attach a LoRA adapter, train only 0.18% of a model's parameters, and measure the real 549x smaller checkpoint that results.

llm advanced
5 min read

Measure the real memory and quality trade-off of FP32, FP16, and INT8 precision, and where GPTQ, AWQ, and GGUF fit in production.

llm advanced
5 min read

Measure the real KV cache speedup, the prefill/decode split, and the batching win that vLLM, TGI, and Ollama all automate.

llm advanced
5 min read

Why overlap metrics mislead, assertion-based graders, judge calibration with kappa, retrieval recall and MRR, and a regression gate, all run in Python.

llm advanced
5 min read

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 advanced
5 min read

Input screening, escaped delimiters, canary tokens, PII redaction, and per-user rate limits for LLM apps, including what each guardrail misses, all run.

llm advanced
5 min read

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.

4 lessons