The PRIMM Framework
James is new to programming. He has spent his career in a non-technical role, but his company is shifting toward AI-driven workflows and he needs to understand code — not just use tools that generate it. His mentor is Emma, a senior engineer who has spent years building backend systems and has a reputation for turning confused beginners into confident developers.
On his first day of learning, Emma shows James an AI coding assistant. She types a prompt, and fifty lines of Python appear in ten seconds. A program that reads data, checks whether it is correct, cleans it up, and gives back the result -- all working, all ready to run.
"That's amazing," James says. "So the AI writes the code and I just use it?"
Emma points at line twelve. "What does that line do?"
James stares at it. He recognizes some of the words -- for, in, if -- but cannot explain what the line accomplishes. The AI generated fifty lines of working code and he understands none of them.
"Speed means nothing without comprehension," Emma says. "If you cannot read the code your AI produces, you cannot verify it, debug it, or adapt it. You are not programming. You are copying."
This lesson introduces the framework that solves this problem: PRIMM -- Predict, Run, Investigate, Modify, Make. It is a research-validated method that teaches you to read and understand code before you ever try to write it. In the AI era, where code generation is nearly free, PRIMM's emphasis on comprehension is more relevant than it was when it was invented.
Where Does PRIMM Come From?
James is skeptical. "A framework from 2017? Won't AI have made that obsolete by now?"
Emma shakes her head. "PRIMM wasn't built for a specific technology. It was built for how brains learn. That hasn't changed."
PRIMM was created by computing education researchers Sue Sentance and Jane Waite in 2017. They tested it with 493 students across 13 schools in England. The result: students who learned with PRIMM outperformed students who learned without it -- especially in classes where students had different skill levels.
The core idea is simple: when you talk about code and read it before writing it, you build the vocabulary and mental models that make writing possible. Each PRIMM stage gives you just enough support to reach the next level of understanding.
Since 2017, PRIMM has been adopted in schools and platforms across England, Germany, the USA, Hong Kong, Norway, Argentina, Australia, and Turkey. The research home is the Raspberry Pi Computing Education Research Centre.
The Inversion That Makes PRIMM Different
Most programming courses start at the end. Lesson one: write a Hello World program. Lesson two: write a program that adds numbers. The assumption is that writing code teaches you to understand it.
PRIMM inverts this. It starts at the beginning -- reading -- and works toward writing. The five stages are:
- Predict -- Read code and predict what it will do before running it
- Run -- Execute the code and compare the actual output to your prediction
- Investigate -- Probe the code: trace variables, test edge cases, ask questions
- Modify -- Change the code to alter its behavior in targeted ways
- Make -- Write a new program that applies what you learned
Four of the five stages build understanding. Only the last one involves writing from scratch. This is not an accident. It reflects what the research showed: comprehension is the foundation that makes production possible.
The Five Stages in Action
Emma pulls up a short Python program on her screen. "Let me show you what this looks like in practice. I'll walk you through all five stages with one program — and you'll do the thinking, not me."
James leans in. "What if I don't know Python yet?"
"That's the point," Emma says. "You're learning the process, not the syntax. Ready?"
About the code below: You have not learned Python yet. That is the point. You are seeing what the PRIMM process looks like with real code. Focus on the process, not the syntax. When you encounter Python in Chapter 33, you will already know how to approach it.
Stage 1: Predict [AI-FREE]
Read the following program. Do not run it. Do not scroll past it. Do not ask your AI assistant. Stop and predict what it will print.
name: str = "Sarah"
greeting: str = "Welcome to the Agent Factory"
message: str = greeting + ", " + name + "!"
print(message)
Before you read further, rate your confidence: How sure are you of your prediction? Score yourself from 1 to 5:
| Score | Meaning |
|---|---|
| 1 | No idea -- complete guess |
| 2 | Vague guess -- something about a greeting? |
| 3 | Think I know but could be wrong |
| 4 | Fairly confident -- I see how the pieces fit |
| 5 | Certain -- I can describe the exact output |
Write down both your prediction and your confidence score. You will compare them to the actual output in the next stage.
This program has four lines. Even if you have never seen Python before, you can probably guess what each line does -- and that is the point.
What happens in your brain when you predict:
- Reading the structure. You see three lines that store values (
name,greeting,message) and one line that prints something. The wordstrafter each colon tells you these values are text. - Reasoning about sequence. The program runs top to bottom. First it stores
"Sarah", then it stores"Welcome to the Agent Factory", then it glues them together with+, then it prints the result. - Building a mental model. You construct a picture: the program will print one line that combines the greeting with the name.
- Committing to an answer. You write down (or say aloud) what you think the output will be. This commitment is critical -- a vague sense of "it probably prints a greeting" is not a prediction. A prediction is specific and checkable — you can prove it right or wrong.
Write your prediction now before reading further.
Stage 2: Run
James writes his prediction on a sticky note: Welcome to the Agent Factory, Sarah! — confidence score 4. He is fairly sure, but the comma placement makes him hesitate. Time to find out.
Here is the actual output:
Output:
Welcome to the Agent Factory, Sarah!
Compare your prediction to the actual result. Three outcomes are possible:
- Exact match. Your mental model is accurate for this code pattern. Good -- but do not stop here. Investigate why it worked.
- Close but not exact. Perhaps you predicted the right content but missed the comma or the exclamation mark. The gap reveals what your mental model missed.
- Significantly wrong. This is not failure -- it is the most valuable outcome. The gap between your prediction and reality is exactly where learning happens. Every wrong prediction exposes an assumption you did not know you were making.
The prediction-reality gap is the engine of PRIMM. Without the prediction step, running code teaches you nothing -- you see output and think "okay." With the prediction step, you have a hypothesis to test. That transforms passive observation into active learning.
Stage 3: Investigate
James got the output right. "Great, I understand it. Next stage?"
"Not so fast," Emma says. "You got the what right. But do you understand how? What happens if the name is empty? What if you swap greeting and name in the message line? That's what Investigation is for — digging into the mechanics."
Investigation means probing the code to build deeper understanding. Here are the kinds of questions you ask:
Tracing variables. What is the value of name? It is "Sarah". What is greeting? It is "Welcome to the Agent Factory". What is message? It is the result of joining greeting, a comma and space, the name, and an exclamation mark. Tracing forces you to simulate the computer's execution in your head -- the single most important skill in programming.
Testing edge cases. What happens if name is an empty string ""? The + operator still joins the pieces together, so the output would be Welcome to the Agent Factory, ! -- a greeting with no name but the comma and exclamation mark still appear. Understanding this teaches you that + does not "know" what makes sense. It glues text together exactly as told.
Using AI as an investigation partner. This is where your AI coding assistant becomes genuinely useful -- not to generate code, but to answer questions about code you are reading:
I am reading a Python program with these lines:
name: str = "Sarah"
greeting: str = "Welcome to the Agent Factory"
message: str = greeting + ", " + name + "!"
print(message)
Question: What would happen if I swapped the order and wrote
name + ", " + greeting instead of greeting + ", " + name?
What would the output look like?
Your AI assistant will explain that the output would become Sarah, Welcome to the Agent Factory! -- the name comes first because + joins text in the order you write it. But here is the critical rule of investigation:
Verify every AI explanation by running the code yourself. The AI might be wrong. It might be right but imprecise. The only way to know is to run the experiment. Investigation is not about getting answers -- it is about building the habit of questioning and verifying.
Stage 4: Modify
"Now change something," Emma says. "Don't ask AI. Don't ask me. Open the code and change it yourself."
James hesitates. "What if I break it?"
"Then you'll learn more than if you hadn't tried."
Modification requires understanding where to change code and what the change will do. Each task below demands a little more comprehension than the last.
Change the name. Replace "Sarah" with your own name. Predict what the output will be, then run it. This is the simplest modification -- you change one value and the rest follows.
Change the greeting. Replace "Welcome to the Agent Factory" with "Hello from SmartNotes". Predict the new output. Now you are changing a different piece and watching how it flows through to the final message.
Add a second line of output. After the existing print(message), add a new line that prints just the name by itself. You need to figure out where to place the new line and what to write.
Each modification is small, but each one forces you to understand a different aspect of the program. You cannot change the greeting without understanding which variable feeds into message. You cannot add a second print without understanding the order in which lines execute.
Stage 5: Make
James managed both modifications. The greeting now says "Hello from SmartNotes, James!" and a second line prints just his name. He is starting to feel confident. "Can I build something on my own now?"
"Now you're ready," Emma says. "But start by writing down what you want to build before you write how."
Now -- and only now -- you write a new program from scratch. The goal is a project badge that stores a person's name and role, then prints a formatted badge line like Sarah - Team Lead. The process:
-
Write a specification first. Before touching code, describe what the program should do: "Given a name and a role, print them on one line separated by a dash."
-
Attempt it yourself. Try writing the code based on what you learned from the greeting program. You will need two variables (name and role), one variable that combines them, and a print statement. James tries
badge: str = name - roleand gets an error -- the minus sign does not work with text. He remembers the greeting program used+and triesbadge: str = name + " - " + role. This time it works. You will make similar wrong turns. That is expected -- each mistake teaches you something the correct answer alone would not. -
Use AI for targeted help. When you get stuck, ask a specific question -- not "write me a badge program" but "How do I join two strings with a dash between them in Python?"
-
Run your code through the Predict-Run cycle. Before executing your new program, predict what it will output. Then run it. Compare. This is PRIMM applied recursively -- you are now using the method to verify your own work.
The Make stage completes the cycle. You started by reading someone else's code. You end by writing your own. Every stage in between built the comprehension that makes writing possible.
The Comprehension Crisis
James just completed his first full PRIMM cycle — predict, run, investigate, modify, make — on a four-line program. It took twenty minutes. He could have asked AI to write the same program in ten seconds. "Is this really worth the time?" he asks.
Emma points back at the fifty lines of AI-generated code from the beginning of the lesson. "Can you explain line twelve yet?"
James pauses. He still cannot. But the greeting program? He understands every line — because he traced it, changed it, and built something new from it.
PRIMM was created in 2017 for secondary school classrooms. Why does it matter more in the AI era than it did when it was invented?
Because AI changed the economics of code production. Before AI coding assistants, writing code was slow and expensive. A developer spent hours translating requirements into syntax, debugging typos, looking up API signatures. The bottleneck was production -- the act of turning ideas into running code.
AI made production nearly free. A well-crafted prompt generates a working function in seconds. But this created a new problem: working code without understanding. James's fifty lines of Python work perfectly -- and he cannot explain what line twelve does. He has a program. He does not have knowledge.
This is the learning trap of the AI era. Students can produce code faster than ever, but the speed creates an illusion of competence. The bottleneck has shifted.
| Era | Bottleneck | Primary Skill | What Slows You Down |
|---|---|---|---|
| Pre-AI | Writing code | Typing, syntax recall, API lookup | Producing code from scratch |
| AI era | Verifying code | Reading, predicting, tracing | Deciding whether generated code is correct |
Look at PRIMM's structure through this lens. Four of five stages -- Predict, Run, Investigate, Modify -- build the verification skills that are now the bottleneck. Only one stage -- Make -- involves writing from scratch. PRIMM's 4:1 ratio of understanding to production is exactly right for an era where production is cheap and verification is expensive.
This is good news. The most important programming skill in 2026 is not typing speed or syntax memorization. It is the ability to read code and predict what it does. PRIMM builds that skill from your very first lesson. You are starting with the skill that matters most.
You already do this informally when reviewing pull requests or debugging a colleague's code. PRIMM formalizes the process and gives you structured vocabulary for a skill you have been practicing by instinct. The framework will sharpen what you already know.
Key Takeaways
- PRIMM stands for Predict, Run, Investigate, Modify, Make -- a five-stage method that starts with reading code and ends with writing it.
- The research is robust: 493 students, 13 schools, tested in real classrooms. Learners using PRIMM outperformed students who learned without it, especially in classes where students had different skill levels.
- The Predict stage is AI-free: you make your prediction without any AI assistance. This is diagnostic -- it reveals whether you actually understand the code or are relying on external help.
- Confidence scoring sharpens your judgment: rating your certainty from 1 to 5 before seeing results builds calibration -- the ability to know when you know and when you do not.
- The prediction-reality gap is the learning engine: committing to a prediction before running code turns passive observation into active hypothesis testing.
- PRIMM's 4:1 comprehension-to-production ratio matches the AI era, where generating code is cheap but verifying code is the bottleneck skill.
Try With AI
Prompt 1: Explore the Prediction Process
I am learning the PRIMM framework for reading code. Here is a short
Python program:
first: str = "Agent"
second: str = "Factory"
result: str = first + " " + second
print(result)
Before you tell me the answer, ask me what I think the output will be.
After I give my prediction, show me the actual output and explain
any differences. Then ask me one investigation question about the code.
What you are learning: The Predict-Run-Investigate cycle with AI as a structured learning partner. The prompt asks AI to quiz you rather than give you answers -- this keeps you in the active learning role that PRIMM requires.
Prompt 2: Investigate an Edge Case
I am practicing the Investigate stage of PRIMM. Here is a program:
name: str = "Sarah"
greeting: str = "Welcome to the Agent Factory"
message: str = greeting + ", " + name + "!"
print(message)
I want to investigate what happens when things change. Walk me through
these scenarios one at a time, asking me to predict before revealing
the answer each time:
1. What if name is an empty string ""?
2. What if I remove the + "!" at the end?
3. What if I swap greeting and name in the message line?
4. What if I write Name (capital N) instead of name on the message line?
For each one, explain WHY the output is what it is.
What you are learning: Systematic investigation through edge-case exploration. Each scenario tests a different assumption about how the code works -- empty inputs, string order, variable naming -- and builds your mental model of Python's behavior through concrete experiments rather than abstract rules.
Prompt 3: Practice the Modify Stage
Here is a simple Python program:
name: str = "Sarah"
greeting: str = "Welcome to the Agent Factory"
message: str = greeting + ", " + name + "!"
print(message)
I want to modify this program so it prints TWO lines:
1. The greeting message (same as now)
2. Just the name by itself on a second line
I will attempt the modification myself first. After I share
my attempt, tell me if it is correct. If not, give me a hint
without writing the full solution.
What you are learning: The Modify stage discipline — attempting a change yourself before asking for help. The prompt explicitly tells AI to give hints, not solutions, which keeps you in the driver's seat while still getting support when stuck.
Looking Ahead
James has one more question. "I used PRIMM without any AI help in this lesson. But I have an AI coding assistant. When do I get to use it?"
"Next lesson," Emma says. "You'll learn exactly when to bring AI in, when to keep it out, and how to tell whether it's helping you learn or just doing the work for you."
That is what Lesson 2 introduces: PRIMM-AI+ — the same five stages you just practiced, enhanced with AI permissions at each stage, checkpoints that keep you honest, and mastery gates that earn you the right to proceed. PRIMM gave you the method. PRIMM-AI+ gives you the operating system for learning with AI.