Module 02 of 11 / 6 lessons / 8 practice exercises / 43 links

LLM foundations and AI fluency

This module explains what a large language model actually does, what it costs to run, and how to get reliable work out of it. You will learn to write clear prompts, ground answers in real sources, tell RAG, tools and agents apart, and decide what data may go into a model at all.

New to a word? Check Start here: the basics first. How to use this module. Read each lesson top to bottom: the diagram first, then the explanation and the worked example. Use "Find more here" to go deeper with docs, videos and courses. Then do the practice. Tick "I did this" to track your progress in this browser.

  1. 2.1How an LLM produces text
  2. 2.2Context windows, cost and latency
  3. 2.3Prompting fundamentals
  4. 2.4Hallucination and grounding
  5. 2.5RAG, tools and agents in plain words
  6. 2.6Responsible use: data, privacy and human review

Lesson 2.1

How an LLM produces text

You will understand tokens, next-token prediction, the difference between training and inference, and why the same question can get different answers.

Why this matters on a client engagement

Clients will ask you 'how does it know that?' and 'why did it give a different answer this time?'. If you understand the mechanism, you can answer honestly, set the right expectations, and design around the model's weak points instead of being surprised by them.

How one token is produced

  1. Prompt textInstructions, context and the question
  2. Split into tokensText chunks turned into numbers
  3. Transformer layersAttention mixes in relevant earlier tokens
  4. Score every next tokenLikelihood for each vocabulary token
  5. Sample one tokenTemperature controls how adventurous
  6. Append and repeatStop at end token or length limit
Read left to right. The last step feeds the new token back in, and the flow repeats until the answer is finished.

The short version

A large language model (LLM) is a program that has learned, from a very large amount of text, to predict what comes next. You give it some text, called the prompt. It predicts the next small piece of text, adds it to the end, and repeats. A long, sensible answer is built one small piece at a time.

This sounds too simple to produce useful work, but predicting the next piece well requires learning a lot: grammar, facts, styles of writing, how arguments are built, how code works. The model does not look things up in a database while it writes. Everything it 'knows' is stored as patterns in billions of numbers called parameters (or weights), learned during training.

Tokens: the pieces the model works with

Models do not read letters or whole words. They read tokens. A token is a chunk of text: often a whole short word, sometimes part of a longer word, a space, or a punctuation mark. A tokenizer is the part of the system that splits text into tokens and turns each one into a number.

Tokens matter to an FDE for three reasons. Cost is charged per token. Limits, such as the context window, are measured in tokens. And some odd behaviour comes from tokens: a model can struggle to count the letters in a word because it never sees the individual letters, only the chunks. Different model families use different tokenizers, so the same text can be a different number of tokens in different models. Vendors provide tools to count tokens exactly, and you should use them rather than guess.

Next-token prediction, step by step

Here is what happens each time the model writes one token.

  • The prompt so far is split into tokens and turned into numbers.
  • The model passes these numbers through many layers. Each layer lets every token 'look at' the earlier tokens and mix in what is relevant. This mechanism is called attention, and the overall design is called a transformer.
  • At the end, the model produces a score for every token in its vocabulary: how likely it is to come next.
  • One token is chosen from these likely options. This choice is called sampling.
  • The chosen token is added to the text, and the whole process repeats for the next token.
  • It stops when the model produces a special end token or reaches the maximum length you allowed.

Training versus inference

Training is how the model is made. In pretraining, the model reads huge amounts of text and adjusts its parameters, again and again, to get better at predicting the next token. This produces a model that can continue any text but is not yet a helpful assistant. In a later stage, often called post-training or fine-tuning, people and automated methods teach it to follow instructions, answer questions, refuse harmful requests and hold a conversation. Training is done by the model provider, takes a lot of computing power, and happens before you ever use the model.

Inference is using the trained model: sending a prompt and getting a response. This is what you do on a client project. The model's parameters do not change during inference. It does not learn from your conversation in the way a person does; if it seems to remember something within a chat, that is because the earlier messages are sent to it again as part of the prompt. It also has a training cutoff: it knows little or nothing about events after its training data was collected, unless you give it that information in the prompt.

Why it is probabilistic

At each step the model produces likelihoods, not one fixed answer. Sampling picks from them. A setting called temperature controls how adventurous the choice is: lower values make the model stick to the most likely tokens, higher values let it pick less likely ones more often. Because one different token early on changes everything that follows, two runs of the same prompt can give different answers.

This has practical effects. You cannot test a prompt once and call it done; you need to run it on many cases. You should not promise a client identical output every time. And when the exact answer matters, such as a number or a category, you should give the model clear rules and examples, ask for a fixed output format, and check the result with code where you can.

Worked example

Worked example: completing a sentence

Give a model the text 'The invoice was rejected because the purchase order'. Many next tokens are possible. Words like 'number', 'was' or 'did' might all be likely, while 'banana' would be very unlikely. The model picks one, say 'number', and the text becomes 'The invoice was rejected because the purchase order number'. Now 'was', 'did' and 'had' become likely next tokens. After a few steps you might get 'The invoice was rejected because the purchase order number did not match.'

Run the same prompt again with a higher temperature and the model might write 'The invoice was rejected because the purchase order had expired.' Both are fluent. Neither is checked against any real invoice. The model produced what is likely, not what is true for your client. That difference is the root of the hallucination problem covered later in this module.

Start practicing

Practice 1

See tokens for yourself

20 min

Goal: Build intuition for how text becomes tokens.

  1. Open the Tiktokenizer page linked below. It shows tokenizers used by some model families; others differ, but the idea is the same.
  2. Paste a normal English sentence and note how many tokens it becomes.
  3. Paste a product code such as 'SKU-88341-BLK-XL', a long email address and a sentence in another language you know. Compare the counts.
  4. Paste a short block of JSON and see how punctuation is split.
  5. Write three observations about what makes text use more tokens.

Done when: You have written three observations about token counts, each backed by one example you pasted.

Practice 2

Watch probability at work

20 min

Goal: See that the same prompt gives different answers.

  1. In a free LLM chat such as Claude, start a new chat and ask: 'Write a one-sentence reason why a delivery might be late.'
  2. Start four more new chats and ask exactly the same thing.
  3. Write down all five answers and mark which words are the same and which differ.
  4. Now ask in a new chat: 'Pick one category for a late delivery from this list only: weather, stock, address, carrier. Reply with one word.' Repeat in four new chats.
  5. Compare how much the answers varied in each case.

Done when: You can explain, with your ten answers as evidence, why a narrow task with fixed options gives more consistent output than an open one.

Common mistakes

  • Saying the model 'looks it up'. Without tools or provided documents, it is predicting from patterns learned in training.
  • Assuming the model learns from your chats during a project. Its parameters do not change during inference.
  • Testing a prompt once. Output varies; test on many cases.
  • Guessing token counts. Use the vendor's token counting tool when cost or limits matter.
  • Forgetting the training cutoff. Give the model recent facts it needs in the prompt.

Check yourself

  1. What is a token, and why does an FDE care about token counts?
  2. Describe the steps that produce one token of output.
  3. What is the difference between training and inference? Which one do you do on a project?
  4. Why can the same prompt give different answers, and what does temperature change?
  5. Why can a model sound right and still be wrong?

Lesson 2.2

Context windows, cost and latency

You will be able to estimate what an LLM feature will cost and how fast it will respond, and explain why long prompts are slower and more expensive.

Why this matters on a client engagement

A proof of concept that costs a few dollars in testing can cost a lot at full volume. A response that takes twenty seconds may be fine for a nightly report and useless for a live phone call. Clients will ask 'what will this cost to run?' and 'how fast is it?'. You need to answer with a clear calculation, not a guess.

Where the time and money go in one call

  1. Build the promptInstructions, documents, history, question
  2. Count input tokensCharged at the input price
  3. Model reads all inputMore input, longer wait for first token
  4. Model writes outputOne token at a time
  5. Count output tokensCharged at the higher output price
  6. Cost per callInput cost plus output cost
Read left to right. Input size drives the wait before the first token; output size drives the time to finish.

The short version

Every call to an LLM has input tokens (everything you send: instructions, documents, chat history, the question) and output tokens (everything the model writes back). Providers charge for both, usually as a price per million tokens, and output tokens usually cost more than input tokens. The context window is the maximum number of tokens the model can handle in one call, counting both input and output.

Latency is how long the user waits. It has two main parts: the time before the first token appears, which grows with the amount of input, and the time to write the rest, which grows with the amount of output because the model writes one token at a time.

The context window

Think of the context window as the model's desk. Everything it needs for this call must fit on the desk at once: your instructions, any documents, the conversation so far and room for the answer. Anything not on the desk does not exist for the model in that call. If a chat gets long, older messages may need to be dropped or summarised to make room.

Context windows today are large enough to hold long documents, but bigger is not always better. Long input costs more and takes longer. Models can also pay less attention to details buried in the middle of a very long prompt. A better habit is to send only what this call needs: the relevant parts of a document, not the whole archive. Check the current limits for each model on the provider's models page, because they change between model versions.

How to estimate cost, step by step

Use the same five steps on every project. Write the result down and show the client your assumptions, so they can change them.

  • Measure typical input tokens per call using a token counting tool on real examples, not a guess.
  • Measure typical output tokens per call the same way.
  • Look up the current price per million input and output tokens for the chosen model on the provider's pricing page.
  • Multiply each token count by its price and divide by one million. Add the two to get the cost per call.
  • Multiply by calls per day and working days per month. Add a margin for retries and growth.

Why long context is slower and costlier

Cost: you pay for every input token on every call. If you send a 50-page manual with each question, you pay for those pages every time, even if the answer needs one paragraph. Speed: before writing the first token, the model must process all the input. More input means a longer wait before anything appears. Output is slower per token than input because each output token needs its own pass through the model.

Several techniques help. Send less: retrieve only the relevant sections (the next lessons explain retrieval). Ask for shorter output when you do not need long text. Use a smaller, faster model for simple tasks such as sorting emails into categories, and keep larger models for hard reasoning. Use prompt caching where the provider supports it: if many calls start with the same long instructions or document, the provider can reuse that processed part, which reduces cost and time for repeated calls. Stream the response so users see text appear as it is written, which makes waiting feel shorter even if the total time is the same.

Explaining cost and speed to a client

Clients rarely want token maths. They want to know three things: roughly what it will cost per month, what drives that cost up, and how fast users will get an answer. Give them a short table with your assumptions in plain words: 'about 3,000 words of input per email, about 300 words of reply, 2,000 emails a day'. Then show what changes the number most, which is usually volume and how much text you send per call.

For speed, measure rather than promise. Time twenty realistic calls and report the typical time and the slowest time, because users remember the slow ones. Match the design to the need. A nightly batch job can use a large model and long documents because nobody is waiting. A live chat needs a fast first token, short prompts and streaming. If the client needs both quality and speed, a common design is a fast model for the first step, such as sorting the request, and a stronger model only for the cases that need it.

Worked example

Worked example: cost of a support reply drafter

This is an example with made-up prices to show the method. Always use the provider's current pricing page for real numbers.

A client wants draft replies for support emails. You measure 20 real emails with a token counter. Each call includes instructions, the customer email and three relevant help articles: about 3,000 input tokens on average. Each draft reply is about 400 output tokens. Assume, for this example only, a price of 3 dollars per million input tokens and 15 dollars per million output tokens. The team handles 2,000 emails per working day, 22 days a month.

Input cost per call is 3,000 times 3 divided by 1,000,000, which is 0.009 dollars. Output cost per call is 400 times 15 divided by 1,000,000, which is 0.006 dollars. Total per call is 0.015 dollars. Per month: 0.015 times 2,000 times 22 is 660 dollars, before a margin for retries. Notice that if you had sent the whole help centre (say 60,000 tokens) instead of three articles, input cost per call would be twenty times higher.

python
# Example prices only. Look up current prices before using real numbers.
PRICE_IN_PER_M = 3.00    # dollars per million input tokens
PRICE_OUT_PER_M = 15.00  # dollars per million output tokens

def monthly_cost(tokens_in, tokens_out, calls_per_day, days=22, margin=0.2):
    per_call = (tokens_in * PRICE_IN_PER_M + tokens_out * PRICE_OUT_PER_M) / 1_000_000
    monthly = per_call * calls_per_day * days
    return per_call, monthly, monthly * (1 + margin)

per_call, monthly, with_margin = monthly_cost(3000, 400, 2000)
print(f"Per call: ${per_call:.4f}")
print(f"Per month: ${monthly:,.2f}")
print(f"With 20% margin: ${with_margin:,.2f}")

# Compare: sending the whole help centre each time
print(f"Whole help centre per month: ${monthly_cost(60000, 400, 2000)[1]:,.2f}")

Start practicing

Practice 1

Build a cost sheet

45 min

Goal: Produce a cost estimate a client could read and challenge.

  1. Pick a task: summarising meeting notes, classifying tickets, or drafting replies.
  2. Collect five realistic examples of input and write a sample good output for each.
  3. Count tokens for each using a tokenizer tool, and take the average input and output.
  4. Open the Claude pricing page and pick two models: one larger, one smaller. Note their prices.
  5. In a spreadsheet or the Python script above, calculate cost per call and per month at 100, 1,000 and 10,000 calls per day for both models.
  6. Write two sentences on which model you would test first and why.

Done when: You have a sheet with your assumptions listed, six monthly cost figures, and a two-sentence recommendation.

Common mistakes

  • Quoting costs from memory. Prices and models change; always cite the current pricing page and date.
  • Forgetting output tokens, which usually cost more per token than input.
  • Sending whole documents on every call. Send only the relevant parts.
  • Using the largest model for everything. Test whether a smaller one is good enough for simple tasks.
  • Ignoring latency until the demo. Measure response time early, on realistic input sizes.

Check yourself

  1. What counts towards the context window?
  2. List the five steps to estimate monthly cost.
  3. Why does more input make the first token appear later?
  4. Name three ways to reduce cost or latency.
  5. In the worked example, what happens to cost if output length doubles?

Lesson 2.3

Prompting fundamentals

You will be able to write a clear prompt with a role, task, context, examples and an output format, including structured JSON output that code can read.

Why this matters on a client engagement

The prompt is the first and cheapest thing you can change in an AI solution. Many 'the model is not good enough' complaints are really 'the prompt did not say what we wanted'. A clear prompt is also a written specification: the client can read it and say 'that rule is wrong', which helps discovery.

Parts of a good prompt

  1. RoleWho should the model act as?
  2. TaskWhat exactly should it do?
  3. ContextWhich facts, rules and documents matter, and why?
  4. ExamplesWhat does a good answer look like, including tricky cases?
  5. Output formatWhat shape, length and fields? What if data is missing?
Read top to bottom. Each layer answers a question the model would otherwise have to guess.

The short version

A prompt is the text you send to the model. A good prompt is like a good brief to a smart new colleague who knows nothing about your client: it says who they are acting as, what to do, what background matters, what good looks like, and how to hand the result back. The model cannot ask you clarifying questions in the middle of a single call, so anything you leave out, it will guess.

Five parts cover most needs: role, task, context, examples and output format. You will not always need all five, but checking each one is a quick way to find what is missing.

The five parts, step by step

Use the parts in roughly this order. Put long documents near the top and your question near the end; this tends to work well with long inputs.

  • Role: who the model should act as. 'You are an accounts payable assistant at a food distributor.' A role sets vocabulary, tone and focus.
  • Task: exactly what to do, as a clear instruction. 'Classify the invoice exception and draft a one-paragraph explanation for the clerk.'
  • Context: the facts and rules it needs. Business rules, definitions, the document to work on, who reads the output. Explain why a rule exists when you can; models follow rules better when they understand the reason.
  • Examples: one to a few input and output pairs that show what good looks like, including a tricky case. Examples often fix problems that more instructions cannot.
  • Output format: the exact shape of the answer. Length, headings, or a JSON structure with named fields. Say what to do when information is missing.

Making prompts clear

Separate the parts so the model does not mix instructions with data. A common way is to wrap each part in simple tags, such as <rules> and </rules>, or <email> and </email>. Then you can refer to them: 'Use only the rules in the rules tags.' Be direct and specific. 'Keep it short' is vague; 'Under 80 words' is clear. Say what to do, not only what not to do.

For hard tasks, allow the model to think step by step before it answers, for example by asking it to reason inside thinking tags and then give the final answer in answer tags. Many current models also have a built-in thinking feature you can turn on. Thinking usually improves accuracy on multi-step problems, at the cost of more output tokens and time.

Structured output with JSON

When code will use the answer, ask for JSON (JavaScript Object Notation), a simple text format of named fields that every programming language can read. Give the exact field names, allowed values and types. Tell the model to return only JSON, with no extra text. Then check the result in code: parse it, confirm each field exists and that values are allowed. Some providers, including Claude, offer a structured outputs feature that makes the model follow a JSON schema you provide, which removes most format errors. Even then, the content can still be wrong, so you still evaluate it.

python
import json

ALLOWED = {"price_mismatch", "quantity_mismatch", "missing_po", "other"}

def check_reply(text):
    data = json.loads(text)  # raises an error if it is not valid JSON
    assert data["category"] in ALLOWED, f"bad category: {data['category']}"
    assert isinstance(data["explanation"], str) and data["explanation"]
    assert isinstance(data["needs_human"], bool)
    return data

model_reply = '{"category": "price_mismatch", "explanation": "Invoice unit price 4.20 vs PO 3.90.", "needs_human": true}'
print(check_reply(model_reply))

Iterate like an engineer

Prompting is not a one-shot skill. Write a first version, run it on ten to twenty real cases, read every output, find the pattern in the failures, change one thing, and run again. Keep old versions so you can compare. The best test cases come from the client's real work, especially the ones their experts find hard.

System prompt and user message

When you call a model through an API (application programming interface, the way programs talk to the model), there are usually two places to put text. The system prompt holds the standing instructions that apply to every call: the role, the rules, the output format. The user message holds what changes each time: the email, the invoice, the question. Keeping them apart makes the prompt easier to maintain and test, because you can change the rules in one place and rerun all your cases.

Treat prompts like code. Store them in files with version numbers, not only in a chat window. Write a short note with each change saying what failure it fixes. When a client expert says 'that answer is wrong', you can then show them the exact rule the model followed and agree together how to change it. This turns prompt work into a shared, reviewable specification instead of private trial and error.

Worked example

Worked example: before and after

The 'before' prompt is the kind most people write first. It has a task but no role, no rules, no example and no format. The model will guess what 'issue' means, how long to write and what to do when it is unsure, and the guesses will vary between runs.

The 'after' prompt adds a role, a clear task, the business rules with a reason, one example and a strict JSON format with an option for missing information. Its output can be read by code, checked automatically and compared across test cases.

text
BEFORE:
What is the issue with this invoice? [invoice text]

AFTER:
You are an accounts payable assistant at a food distributor.
Task: classify why this invoice does not match its purchase order (PO).
<rules>
A price difference under 1 percent is accepted, because suppliers round.
If the PO number is missing or unknown, use missing_po.
</rules>
<example>
Invoice: 100 cases at 4.20. PO: 100 cases at 3.90.
Output: {"category": "price_mismatch", "explanation": "Unit price 4.20 vs PO 3.90.", "needs_human": true}
</example>
<invoice>[invoice text]</invoice>
<po>[PO text]</po>
Return only JSON with fields category (price_mismatch, quantity_mismatch,
missing_po, other), explanation (under 30 words), needs_human (true or false).
If you cannot tell, use other and set needs_human to true.

Start practicing

Practice 1

Rewrite a weak prompt

45 min

Goal: See how each prompt part changes the output.

  1. Write five realistic short customer emails yourself, such as a complaint, a refund request, a question about delivery, a compliment and something unclear.
  2. In a free LLM chat such as Claude, send the weak prompt 'Sort this email' followed by each email. Save the outputs.
  3. Write a better prompt with role, task, context (your categories and why each exists), one example and a JSON output format.
  4. Run the better prompt on the same five emails in new chats.
  5. Paste each JSON reply into the Python check above, adapted to your fields, and fix the prompt until all five pass.
  6. Write down which part of the prompt made the biggest difference.

Done when: All five outputs from your improved prompt parse as valid JSON with allowed values, and you can name the change that helped most.

Common mistakes

  • Leaving out the context an expert would know. The model does not know the client's rules unless you write them down.
  • Vague limits such as 'brief' or 'detailed'. Give numbers or a clear shape.
  • Asking for JSON but not checking it in code. Always parse and validate.
  • Changing many things at once. Change one thing per round so you know what helped.
  • Testing only on easy examples. Include the cases experts find hard.

Check yourself

  1. Name the five parts of a prompt and what each one answers.
  2. Why do examples often help more than extra instructions?
  3. Why should you separate instructions from data, and how?
  4. What should your code do with a JSON reply before using it?
  5. In the before and after example, what does the 'after' prompt say to do when the model is unsure?

Lesson 2.4

Hallucination and grounding

You will understand why models invent facts, and how to reduce it with grounding, citations and permission to say 'I do not know'.

Why this matters on a client engagement

One confident wrong answer in front of a client can end trust in the whole project. In finance, health, legal or safety work, an invented number or rule can cause real harm. An FDE must design so that answers can be traced to sources and wrong answers are caught before they matter.

Grounded answer decision

Question plus source documents
Is the answer in the sources?
Yes, clearly

Answer with a citation to the passage

Partly

Answer what is supported, flag the rest

No

Say 'not found in the documents'

The model first checks the provided sources. Only the first branch should produce a confident answer.

The short version

A hallucination is when a model states something false or made up as if it were true: a wrong figure, a policy that does not exist, a citation to a paper nobody wrote. It happens because the model is trained to produce likely-sounding text, and a fluent, plausible answer is often more likely than 'I do not know'.

Grounding means giving the model the real source material and telling it to answer only from that material. It is the main defence. Citations, which point to the exact passage behind each claim, let a person check the answer. Allowing and encouraging 'I do not know' stops the model from filling gaps with guesses.

Why models invent

Recall how the model works: it predicts the next token from patterns. It has no built-in check that a statement is true. When it knows a fact well from training, the likely answer and the true answer usually match. When it does not, it still produces the most likely-looking text, which can be confident and wrong.

Hallucinations are more common in some situations: rare or very specific facts (a client's internal policy, a part number), recent events after the training cutoff, exact numbers and dates, long chains of reasoning, and questions that assume something false ('Why did our Q3 policy change?' when nothing changed). They are also more likely when the prompt pushes for an answer at any cost.

Grounding, step by step

Use these steps whenever an answer must be factually correct.

  • Find the source: the client's documents, database rows or system records that contain the true answer.
  • Put the relevant parts in the prompt, clearly marked, for example inside document tags with a title and an id.
  • Instruct the model to answer only from those documents, and to say 'I do not know' or 'not found in the documents' when the answer is not there.
  • Ask for citations: a short quote or document id for each claim. For long documents, ask the model to first pull out the relevant quotes, then answer from the quotes.
  • Check citations in code or by review: does each quote really appear in the source, and does it support the claim?
  • Measure: in your test set, include questions whose answer is not in the documents, and count how often the model correctly says it does not know.

Going deeper: tools that help

Some providers offer a citations feature. With Claude, you can pass documents and the response comes back with references to the exact passages it used, which is easier to check than quotes the model writes itself. For numbers, let code do the maths: retrieve the figures with a database query and ask the model to explain them, rather than asking it to calculate. For high-stakes outputs, keep a human review step, and show the reviewer the sources next to the answer so checking is quick.

Also design the user experience for honesty. A screen that shows 'Source: Returns policy, section 4' next to the answer invites checking. A screen that shows only a confident paragraph invites blind trust.

What grounding cannot fix

Grounding reduces hallucination but does not remove it. The model can still misread a source, mix up two similar documents, or quote correctly but draw the wrong conclusion. If the source documents are out of date or contradict each other, the answer will reflect that. This is why evaluation on real cases and a clear review process stay necessary.

Talking to clients about hallucination

Be honest early. Tell the client in plain words that the model can produce confident wrong answers, that the design reduces this but does not remove it, and that you will measure how often it happens on their real cases. Clients handle a known, measured error rate far better than a surprise in front of their manager.

Agree on what an error costs. A wrong answer in an internal search tool may be a small annoyance. A wrong figure in a regulatory report is serious. The cost decides how much grounding, checking and human review you need. Write the agreed bar down, for example 'no unsupported claims in 100 test questions, and correct "not found" on every unanswerable question', so everyone knows what 'good enough' means before the demo, not after it.

Worked example

Worked example: a returns policy question

A customer asks: 'Can I return a mattress after 60 days?' Ungrounded, a model may say 'Most retailers allow 30 days, so no' or invent a 100-night trial. Neither is about this client.

Grounded, the prompt includes the client's returns policy and an instruction to answer only from it, with a quote, and to say so if the policy does not cover the question. Suppose the policy says mattresses can be returned within 90 days if unused and in original packaging. The model answers yes, with the conditions, and quotes the sentence. If the policy were silent on mattresses, the correct output would be 'The policy does not mention mattresses; please check with the team', and your test set should include such a question to make sure it does this.

text
Answer the customer question using only the policy below.
<policy id="returns-v3">[policy text]</policy>
<question>Can I return a mattress after 60 days?</question>
First copy the exact sentences from the policy that are relevant into <quotes>.
Then answer in <answer> in under 50 words.
If the policy does not answer the question, write in <answer>:
"The policy does not cover this. Please check with the team."

Start practicing

Practice 1

Catch a hallucination, then ground it

40 min

Goal: See hallucination happen and see grounding reduce it.

  1. Find a short public policy page, such as a library's borrowing rules or a shop's returns policy, and copy its text.
  2. Write five questions: three answered in the text, two that are not answered anywhere in it.
  3. In a free LLM chat, ask the five questions without the policy. Note any answers that are invented or about some other organisation.
  4. In a new chat, use the grounded prompt from the example with the real policy text, and ask the same five questions.
  5. For each grounded answer, check that the quote really appears in the policy and supports the answer.
  6. Score both runs: correct, wrong, or correctly said 'not covered'.

Done when: You have a ten-row score table (five ungrounded, five grounded) and can show at least one case where grounding changed the answer.

Common mistakes

  • Trusting fluent answers. Fluency is not evidence; ask for sources.
  • Not giving the model permission to say it does not know. Say it explicitly.
  • Letting the model do arithmetic on important figures. Use code for calculations.
  • Never testing unanswerable questions. Include them in every test set.
  • Assuming grounding solves everything. Keep evaluation and human review.

Check yourself

  1. What is a hallucination, and why does next-token prediction cause it?
  2. Name three situations where hallucination is more likely.
  3. List the steps to ground an answer in sources.
  4. How do you check that a citation is real and relevant?
  5. What can still go wrong after grounding?

Lesson 2.5

RAG, tools and agents in plain words

You will understand what retrieval augmented generation, tool use and agents are, and how to choose the simplest one that solves the client's problem.

Why this matters on a client engagement

Clients hear these words constantly and often ask for 'an agent' when a simpler design would be cheaper, faster and more reliable. An FDE must explain the options in plain words and pick the right one. Later modules teach how to build each; this lesson gives you the map.

Choosing the simplest pattern

Client task
What does the answer depend on?
Only general knowledge

Plain prompt

Client documents

RAG

Live data or actions

Tools, in a fixed workflow

Unknown, many steps

Agent with limits and review

Start at the question and pick the first branch that fits. Move to a more complex pattern only when tests show you need it.

The short version

Start with a plain model call: you send a prompt, it sends text back. Three patterns extend this. Retrieval augmented generation (RAG) finds relevant pieces of the client's documents and adds them to the prompt, so the model answers from real sources. Tool use lets the model ask your code to do something, such as look up an order or run a calculation, and then use the result. An agent is a model that uses tools in a loop, deciding its own next step, until it finishes a task.

Each step adds power and also adds cost, delay and ways to fail. The rule of thumb is: use the simplest pattern that solves the problem, and only add more when tests show you need it.

RAG: give the model the right pages

RAG solves the problem from the last lesson: the model does not know the client's documents. You prepare by splitting documents into chunks, such as sections or paragraphs, and storing them in a searchable index. When a question comes in, a search step retrieves the most relevant chunks, and these are put into the prompt with an instruction to answer from them.

The search can be keyword search, semantic search using embeddings (lists of numbers that represent meaning, so 'refund' can match 'money back'), or both. The quality of RAG depends mostly on retrieval: if the right chunk is not found, the model cannot use it. Use RAG when answers live in a large body of text that changes over time, such as policies, manuals or past tickets.

Tools: let the model ask your code

With tool use, you describe functions to the model: a name, what it does and what inputs it needs, for example get_order_status with an order_id. When the model decides it needs one, it replies with a structured request to call that tool. Your code runs the function, sends the result back, and the model writes its answer using it. The model never runs code itself; your program stays in control and decides what is allowed.

Use tools when the answer depends on live data in a system (order status, stock levels, account balance), when you need exact calculations, or when the model must take an action such as creating a ticket. Actions that change things need extra care: start with read-only tools and add human approval for anything that writes.

Agents: tools in a loop

An agent repeats a cycle: look at the goal and what has happened so far, choose a tool, run it, look at the result, and decide the next step, until the task is done or a limit is reached. This is useful when the steps cannot be known in advance, such as investigating why a shipment is late across several systems.

Anthropic's guide to building effective agents, linked below, separates workflows, where your code sets the steps in a fixed order, from agents, where the model chooses the steps. Workflows are more predictable and easier to test. Agents are more flexible but cost more, take longer and can make compounding mistakes. Many real problems are solved well by a workflow.

  • Answer from documents: RAG.
  • Answer needs live system data or exact maths: tools.
  • Known fixed steps: a workflow of calls and tools set by your code.
  • Open-ended task with steps you cannot predict: an agent, with limits and review.

Questions to ask before choosing

In discovery, a few plain questions usually make the choice clear. Where does the answer live today: in documents, in a system, or in someone's head? If it is in someone's head, no pattern will help until it is written down. How often does that information change? Fast-changing data points to tools that read the live system rather than a copy. Does the task only read information, or does it need to change something? Anything that writes needs approval and careful limits.

Also ask how many steps an expert takes and whether those steps are always the same. If an experienced person follows the same five steps every time, write those steps as a workflow in code. If they say 'it depends' and explore, that is where an agent may earn its extra cost. Finally, ask how the result will be checked. Whatever you choose, you will need real examples with known good answers to test it.

Worked example

Worked example: one help desk, three needs

An internal IT help desk wants AI support. During discovery you find three kinds of request.

First, how-to questions such as 'How do I set up VPN on a new laptop?' The answers are in about 400 help articles. This is RAG: retrieve the right article sections and answer with a citation. Second, status questions such as 'Is my laptop order shipped?' The answer is in the asset system, so the model needs a read-only tool get_ticket_status. A short fixed workflow is enough: identify the ticket, call the tool, explain the result. Third, a small number of messy problems such as 'Email stopped syncing on my phone after the update.' Here the steps are not known in advance, so an agent that can check the user's account, recent changes and known incidents might help, but only after the first two are working and with a technician reviewing its suggestions.

You would build and evaluate them in that order, simplest first, because the first two probably cover most of the volume (something you confirm by counting real tickets).

Start practicing

Practice 1

Classify ten tasks

30 min

Goal: Practise choosing the simplest pattern.

  1. Write ten realistic tasks from a business you know, such as 'summarise this contract', 'what is the stock of item X', 'which policy covers travel to a conference'.
  2. For each, decide: plain prompt, RAG, tools in a workflow, or agent. Write one reason.
  3. For each tool you named, write its name and inputs, for example get_stock(item_id), and mark it read-only or write.
  4. Ask Claude to argue for a different choice on three of them, then decide yourself whether to change.
  5. Swap lists with your pair partner and check each other's choices.

Done when: You have ten tasks, each with a pattern and a reason, and you and your partner agree on at least eight.

Common mistakes

  • Building an agent because it sounds advanced. Start with the simplest pattern and test.
  • Blaming the model when RAG fails. Check retrieval first: was the right chunk found?
  • Giving tools write access too early. Start read-only and add human approval for actions.
  • No limits on agents. Set a maximum number of steps and a cost budget.
  • Skipping evaluation because 'it is just retrieval'. Every pattern needs a test set.

Check yourself

  1. Explain RAG, tool use and agents each in one sentence.
  2. Why does RAG quality depend mostly on retrieval?
  3. Who actually runs the code when a model uses a tool?
  4. What is the difference between a workflow and an agent?
  5. For a question about live stock levels, which pattern fits and why?

Lesson 2.6

Responsible use: data, privacy and human review

You will know how to decide what data may go into which AI tool, how to handle personal data, how to watch for bias, and where to put a human in the loop.

Why this matters on a client engagement

An FDE works with the client's real data, often including customer and employee details. One careless paste into the wrong tool can break a contract, a law or the client's trust, and end the engagement. Clients also need to know who checks the AI's work and what happens when it is wrong. Getting this right early is part of the job, not paperwork.

How much human review is needed

AI output ready
If it is wrong, how bad is it?
Low harm, easy to undo

Run automatically, sample weekly

Medium harm

Person reviews before it is used

High harm or about a person

Person decides; AI only prepares

Ask what happens if the output is wrong, then pick the matching level of review.

The short version

Responsible use comes down to four questions. What data is this, and how sensitive is it? Where is it allowed to go? Could the output be unfair or harmful to some people? Who checks the output before it affects anyone? The client's own policies and contracts set the answers. Your job is to ask, follow them, and design the system so the safe path is the easy one.

When in doubt, stop and ask. 'Can I send this data to this model?' is always a good question to ask the client's security or data protection team. Guessing is not.

What data may go where

Most organisations classify data into levels such as public, internal, confidential and restricted. Learn the client's levels on day one. Then check which AI tools are approved for which level. A free consumer chat app, a company-approved enterprise chat tool and an API account under a contract with the client are different places with different terms for storage, retention and training on your data. Read the provider's data and privacy terms and the client's agreement; do not assume.

Personal data, often called PII (personally identifiable information), is any information that identifies a person: names, emails, phone numbers, addresses, account numbers, ID numbers, and combinations of details that point to one person. Privacy laws such as the EU GDPR set rules for how it may be processed. Some data is extra sensitive, such as health, financial or biometric data, and some industries have their own rules.

  • Use the least data that does the job. If the task is classifying complaints, you may not need customer names at all.
  • Remove or mask personal data before it reaches the model where you can, for example replacing names with placeholders.
  • Use synthetic or masked data for early prototypes and demos.
  • Keep data in client-approved systems and accounts only. Never copy client data to personal devices or personal AI accounts.
  • Never paste secrets such as passwords or API keys into prompts.

Bias and fairness

Models learn from human-written text, which carries human biases. They can treat people differently based on names, language, gender, age or location, even when told not to. The risk is highest when the output affects people: hiring, lending, insurance, pricing, benefits, discipline. In those areas, test on purpose: create pairs of cases that differ only in a sensitive detail, such as the name, and check whether the output changes. Keep a human decision maker for decisions about people, and record what the AI recommended and what the human decided.

Human in the loop, step by step

Human in the loop means a person reviews or approves the AI's output before it takes effect. Decide where to put that person based on the cost of an error.

  • List what the system outputs and what happens next with each output.
  • For each, ask: if this is wrong, who is harmed and how badly? Can it be undone?
  • Low harm and easy to undo, such as sorting internal emails: let it run, sample and review a few each week.
  • Medium harm, such as a draft reply to a customer: a person reviews and sends.
  • High harm or hard to undo, such as a payment, a decision about a person or a medical statement: a person decides; the AI only prepares information.
  • Make review easy: show sources next to the output and let reviewers mark errors with one click, so you can measure and improve.

Security risks specific to LLMs

LLM systems add new risks. Prompt injection is when text the model reads, such as an email or a web page, contains instructions that try to make the model do something else, like reveal data or call a tool. Treat all content the model reads as untrusted data, limit what tools can do, and require approval for actions. The OWASP Top 10 for LLM applications, linked below, is a good checklist to review with the client's security team.

Client policies come first

Every client has its own rules, and they override general advice, including this lesson. Ask for the acceptable use policy for AI tools, the data classification policy, and any contract terms with the AI provider. Find out who approves exceptions. Write the answers in your project notes and share them with your pair, so nobody has to guess later.

Keep a simple record as you build: which data went to which tool, under which approval, and how long it is kept. If the client's security team asks a question at the end of the project, you can answer in minutes. This record also helps the client owner after hand over, because they will need to explain the system to auditors and new team members.

Worked example

Worked example: complaint triage at an insurer

An insurer wants AI to sort incoming complaints by topic and urgency. Complaints contain names, policy numbers, and sometimes health details.

You ask the data protection team first. They confirm complaints are confidential and contain sensitive data, and that only the company's approved enterprise AI environment may be used. For the prototype, you build a test set of 200 masked complaints: names become [NAME], policy numbers become [POLICY], and health details are kept only where they change the urgency. You confirm that the task works without names.

For review, sorting by topic is medium harm (a misrouted complaint is delayed), so a team member checks the queue each morning. Urgency marked 'vulnerable customer' is high harm if missed, so any complaint the AI marks low urgency but which mentions health or money worries is shown to a person. You also test for bias by duplicating twenty complaints with different names and checking the urgency stays the same.

Start practicing

Practice 1

Write a data handling plan

45 min

Goal: Practise the questions you will ask on day one of a real engagement.

  1. Pick a realistic use case, such as summarising HR cases, drafting supplier emails or sorting patient appointment requests.
  2. List every data field the system would see and mark each as public, internal, confidential or restricted, and whether it is personal data.
  3. Cross out the fields the task does not actually need.
  4. Write how you would mask the remaining personal fields for the prototype.
  5. Use the human in the loop steps to choose a review level for each output.
  6. Write five questions you would send to the client's data protection or security team.

Done when: You have a one-page plan with a field list, masking approach, review levels and five questions, and your pair partner can find no field you forgot.

Practice 2

Run a simple bias test

25 min

Goal: See whether a sensitive detail changes model output.

  1. Write a short, made-up job application summary with no name.
  2. In a free LLM chat, ask the model to rate the candidate from 1 to 10 with a one-line reason. Use a new chat each time.
  3. Repeat with the same summary but different names suggesting different genders or backgrounds, three runs each.
  4. Record the scores and compare.

Done when: You have a small score table and a two-sentence note on whether the scores changed and what you would do on a real project.

Common mistakes

  • Pasting client data into a personal or free AI tool. Use only client-approved tools and accounts.
  • Sending all fields because it is easier. Send only what the task needs and mask personal data.
  • Assuming the AI is neutral. Test for bias where output affects people.
  • Adding human review that is too slow or unclear to use. Make review quick, with sources shown.
  • Letting tools act on instructions found in emails or documents. Treat that content as untrusted.

Check yourself

  1. What four questions does responsible use come down to?
  2. What is PII? Give five examples.
  3. How do you decide the level of human review for an output?
  4. How would you test whether a model treats people differently by name?
  5. What is prompt injection and how do you limit its damage?