Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

What an AI coding assistant knows

After this lesson: I can explain what an AI coding assistant does and does not know.

40 min lessonNo commands

An answer in five seconds

You start on a support team. Your manager asks for a script that counts last week's tickets. You ask the company's AI assistant. Five seconds later you have neat, confident code.

Does it work? Are the functions it uses real? To answer that, you need to know what the assistant can know and what it cannot.

By the end of this lesson

Note

I can explain what an AI coding assistant does and does not know.

Key words

WordWhat it means
AI coding assistanta tool that writes and explains code from your words
Modelthe program inside it that predicts text
Promptthe words you send the assistant
Contextall the text the model can see right now
Training datathe text the model learnt from, up to a date
Hallucinationa made-up answer that sounds true

The cells students fill in are left blank in this preview.

An assistant predicts likely text

The model learnt from a huge amount of public text and code. When you send a prompt, it predicts the words most likely to come next. It does this again and again until the answer is finished.

It does not look the answer up. It usually does not run the code it writes. A likely answer is often a right one, but not always.

It only sees what is in the context

The context is the text the model can see right now. That is your prompt, the chat so far and any files your tool adds.

It cannot see your other files, your database or your servers. It does not remember last week's chat unless the tool saves it. Its training stops at a date, so newer tools may be missing.

What the assistant can see

ThingCan it see it?Why
The prompt you just sentYesIt is in the context
A file you pasted in this chatYesIt is in the context
The rest of your projectNo, unless a tool adds itIt is not in the context
Your live customer databaseNoIt never reaches the model
A chat from last weekUsually notEach chat starts again
A library from this monthMaybe notIt is newer than the training data

The cells students fill in are left blank in this preview.

A confident answer can be invented

Sometimes the model writes a function or a library that does not exist. The name looks sensible, so it is easy to believe. This is a hallucination.

The tone gives no warning. A wrong answer sounds just as sure as a right one. Run the code below and see one.

Try it: an invented method

Code: python
# A support lead asked an assistant:
# "Find the longest ticket title in this list."
titles = ["Printer offline", "Password reset", "VPN will not connect"]

# The assistant suggested this line. Press Run and read the error.
longest = titles.longest()
print(longest)

# Python lists have no longest() method: the assistant invented it.
# Delete the line with longest() and the print line under it.
# Then remove the # from the five lines below and press Run again.
# longest = ""
# for title in titles:
#     if len(title) > len(longest):
#         longest = title
# print(longest)

A common mistake

Warning

Many people think an assistant checks its code before it answers. It predicts likely code and usually does not run it. So treat every answer as a draft until you have read it and run it yourself.

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.