Building with LLMs
Use a language model as a component: prompts that say what you mean, retrieval that hands it the right page, and tools it can ask your code to run. Then measure all of it, so you know it still works after the next change.
- Intermediate
- 4 units, 12 lessons, 153 exercises
- Text, JSON, Python
- No experience needed; 19 helps
Unit 01 · 3 lessons
Prompts
Write instructions a literal-minded reader cannot misread
- 01Prompts are instructions
Roles, clear asks, reasons and what examples teach
- 02Structured output
Fence inputs, ask for JSON, validate what comes back
- BOSSFix a prompt that fails
Read the failures, find the ambiguity, rerun every case
Read the unit guide
A request to a model is a list of messages with roles. The system message holds the developer's standing instructions, user messages hold what the person typed, and assistant messages hold what the model said before. The model reads all of it as one text and writes the next turn. It remembers nothing between requests, so the app sends the system message and the history again every time.
A prompt is a set of instructions for a reader who knows nothing about your project and takes you literally. Say what you want, who it is for and what a finished answer looks like. Give the reason behind a rule: a reason covers the cases you forgot to list. The test is the new colleague: could a bright stranger do the task from this text alone?
Examples are the strongest signal in a prompt. The model copies their length, format and tone, and when they disagree with the instructions the examples tend to win. Make them varied, make them cover the hard cases, and make them look exactly like the output you want.
When code will read the reply, ask for structure. Fence outside text in named tags so it cannot be mistaken for your instructions. Ask for JSON, describe it with a schema, then treat the reply like input from a stranger: parse it, validate it against the schema, and only then use it. A schema can guarantee the shape of a reply, never the truth of what is in it.
Debugging a prompt is debugging. Read the failures before changing anything, find what they share, change one thing, then rerun every test input, because a fix for one case can break another. Most failures are ambiguity: a label nobody defined, an edge case nobody mentioned, one prompt doing four jobs. Close the gap in words, or split the job into steps you can check one at a time.
Unit 02 · 3 lessons
Retrieval
Hand the model the right page instead of hoping it remembers
- 01Embeddings and search
Text becomes a vector; search becomes geometry
- 02Chunks and ranking
Chunk size, hybrid search, reranking and filters
- BOSSAnswer from documents
Ground the answer, cite sources, find where it failed
Read the unit guide
A model knows only its training data and what is in the prompt. Retrieval-augmented generation (RAG) puts the right text in the prompt: find the passages that bear on the question, paste them in, and tell the model to answer from them.
Finding them usually starts with embeddings. An embedding model turns a text into a vector, and texts with similar meaning point in similar directions. Cosine similarity, the dot product of two vectors divided by their lengths, scores how well two directions agree. Embed every chunk once, embed each question when it arrives, and keep the top k. Question and chunks must come from the same embedding model. Large collections use an approximate index, which is much faster and occasionally misses a true neighbour.
Documents are split into chunks first, because one vector for forty pages matches nothing well. Small chunks match precisely and lose context; large ones keep context and blur. Overlap protects sentences that straddle a boundary. Similarity finds what is related, not what is true or current, so store metadata (date, version, owner) and filter on it.
No single search is best. Keyword search wins on exact strings such as error codes and names; semantic search wins on paraphrase. Hybrid search runs both and fuses the two rankings. A reranker then reads the question with each of the top candidates and reorders them: slow and accurate, on a short list made by something fast and rough.
The prompt gives numbered sources and three rules: answer only from them, cite them, and say so when they do not contain the answer. When an answer is wrong, find out where: if the right chunk never reached the prompt it is a retrieval miss, and no prompt can fix it; if the chunk was there, it is a generation mistake. Measure the two separately. And remember that the index is a snapshot: a changed document changes nothing until it is ingested again.
Unit 03 · 3 lessons
Tool use
Let the model ask for actions while your code stays in charge
- 01Tool calling
A call is structured text; your code runs it and replies
- 02Designing tools
Descriptions, schemas, errors and safe retries
- BOSSUntrusted text
Prompt injection and the limits that contain it
Read the unit guide
A model can only write text. Tool use is an agreement about that text: you send tool definitions with the request, each a name, a description and a JSON schema for the input, and the model may reply with a tool call instead of an answer. The call names a tool and gives arguments. Field names differ between providers; the shape does not.
The model never runs anything. Your code receives the call, validates the arguments, runs the real function and sends the result back as a new message tagged with the id of the call it answers. Then the model is called again and continues with the result in view. One question that needs one tool costs two model calls, and steps that depend on each other need one round each.
The description is a prompt, and it is all the model knows about a tool. Say what the tool does, when to use it, what each parameter means and what comes back. A few tools with distinct jobs beat many that overlap. Use the schema to rule out bad input (enum, minimum, required) and validate anyway. Return errors as short readable messages, because the model reads them and can correct its next call.
Calls get retried, so make actions safe to repeat: give anything with a side effect a unique key the server can recognise. Put a person in front of what cannot be undone or what leaves the building. Reads, summaries and drafts can run freely.
Every text the model reads can try to steer it. A web page, an email, a retrieved chunk or a database row may carry instructions written by a stranger, and the model cannot reliably tell them from yours. Tags and warnings lower the odds and are not a boundary. Real protection sits in code: least privilege for every task, narrow tools, read-only accounts, approval before irreversible actions, validated output, and no secrets anywhere in the prompt.
Unit 04 · 3 lessons
Shipping it
Measure quality, control cost and plan for the day it fails
- 01Evals
Test cases, graders and how much a score can be trusted
- 02Cost and latency
Where the tokens and the seconds go, and the levers
- BOSSShip a feature
Ticket triage end to end, from schema to rollout
Read the unit guide
A demo works once. A product has to work on inputs nobody tried, after changes nobody remembers making. The tool for that is an eval: a set of cases (an input and the behaviour you expect), a grader, and a score, run on every change to the prompt, the model or the retrieval.
Use the cheapest grader that can decide. Exact match for labels, code for anything checkable (does it parse, does the cited source exist), a model with a rubric for judgements code cannot make, and people for checking that the model grader is right. Scores are noisy: on 100 cases a few points of difference is a few cases and can be luck. Look at which cases flipped, and always list the regressions, the cases that passed before and fail now.
Cost follows tokens. Most features read far more than they write, so the prompt is usually the bill: put the stable part first so the provider can cache it, and do not ship tools or examples nobody needs. Time follows output: tokens are written one after another, so shorter answers are faster, and streaming makes the wait feel short without changing it. Send easy requests to a small model when the eval says it is good enough.
Budget the context window: the fixed prompt, the retrieved text and the conversation all share it, and room has to be kept for the answer.
Then plan for failure. Calls time out, providers go down, replies fail validation. Retry briefly, then fall back to something safe, usually the human process that existed before. Keep a person in front of anything a customer will see until the numbers earn automation, and automate the lowest-risk slice first. After launch, watch production: corrections made by people are free labels, a jump in them means the inputs changed, and every one belongs in the eval set.
Learn Building with LLMs on your phone.
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.