Explaining role prompting in Scratch

In this post, I want to share a recent worksheet I wrote for Machine Learning for Kids. It is a hands-on project to give students an insight into an aspect of prompt engineering with language models.

Students create a Scratch project that lets them have a conversation with a small language model. They try to have the same conversation multiple times, and they set up the Scratch project so that adds a short role instruction to the context at the start (e.g. “Answer like a pirate”).

The instruction changes how the model answers, and students have to try and work out from the responses they get from the model which persona has been selected.


screen recording of the Scratch project on YouTube

By repeating the activity several times, they should notice something important: the same language model gives very different answers to the same questions, just because of a small change in the instructions. This observation is the key lesson here.

What is happening

The AI being used is a language model — a system trained on vast amounts of text to predict what words should come next in a sentence.

In other projects, students explore the differences between using different models, but in this project, the model isn’t changed between conversations.

What changes is the context they give the model at the start.

Their role prompt is simply an instruction that tells the model how it should behave or “who it should pretend to be” when responding. For example: “You are a pirate. Answer like a pirate.”

The model doesn’t understand pirates, knights, or poets in a human sense. Instead, it has learned patterns from the text it has seen: pirate-like vocabulary, poetic rhythm, formal speech, and so on. When we add a role prompt, we are guiding the model to follow a particular pattern.

The aim of the project is to allow students to explore the idea that the output from language models is shaped by the instructions we give it.

Prompt engineering

The project is getting students to think about one aspect of prompt engineering – a way of thinking about how to write instructions for AI intentionally so that they produce useful outputs.

Prompt engineering is a broader collection of ideas (e.g. task framing – how to clearly state what you want), some of which could make good focuses for future worksheets.

But for this one, I’m focusing on role prompting.

I’ve described the concept as “role prompting” in the worksheet as that is the term we commonly use, however I’ve also seen it described as “persona prompting”, “role-play prompting”, or “role-based instructions”.

Why this is useful

Hopefully this is a fun project to build, but it’s also getting students to think about an important principle. Role prompting isn’t just about guiding the style, tone and focus of responses for the sake of getting a different style of output. It isn’t just about text style and imitation. (Although this is useful).

We do this because we want to enhance the clarity and accuracy of responses. Aligning the response with the role can improve the performance of the model in tasks such as reasoning. Roles don’t just alter how the model speaks, but how well they can solve tasks.

The project helps to underline the idea of the impact of how we ask questions to language models. A lesson underlined in several projects is that vague prompts lead to vague answers, and specific prompts lead to clearer, more useful responses. This project is another example that supports that.

More generally, it encourages a critical evaluation of AI. Rather than blindly trusting the responses we get from language models, we want students to learn to ask questions like “Why did the model answer like that?”, and “What was it in my instructions that caused this output?”. This simple example is another way to reinforce that mindset.

Plus, I think this sort of thing can be a useful exploration into more transferable communication skills. Role prompting is about communication, albeit with an AI. Thinking about who your audience is, what tone is needed, what style will work best – all of these are just as useful for students in writing, presentations, discussions, and other aspects of life.

What could go wrong

Part of the project is for students to choose roles that the model should be told to adopt. They may not write role personas that result in effective output on their first attempt. Some roles may produce weak results simply because the model has limited or low-quality representation of that role in its training data. But Scratch is an effective sandbox for experimentation, so students can try exploring different ways of describing the role, such as making it more specific and precise, and see the impact that this has.

Another consideration is that role prompts are prone to reinforce stereotypes. It is inevitable that the training data for language models contains biased patterns – gendered assumptions about jobs are a commonly cited example, but there are many others. With the level of depth that students will likely get to in such a short project, they are likely to end up with roles that simply encourage caricatures. With older students, it would be good to invite them to reflect on the answers that the model is giving, and whether they feel like it is a fair or accurate representation of the role.

How else could we use roles?

We could try prompting models with named figures – such as well-known educators, scientists, or historical figures. This might be a fun way to explore different view points.

However, I think there are risks here, especially if controversial public figures are chosen.

Even besides that, using a named person for the role prompt (e.g. trying to “talk” with William Shakespeare) could imply a level of authority in the model’s output that is misleading. For this project, I’ve steered students towards more neutral and generic role descriptions, but there could be interesting extensions here if done carefully.

Why I like this

Putting language models in Scratch lets students experiment. Students control where the role prompt is added, when it changes, and they can see for themselves how the output changes as a result.

“Role prompting” adds another term to give them the language needed to talk about AI behaviour, and hopefully a little confidence in how to use AI tools effectively.

The aim is to stop treating AI as a mysterious and magical black box, and instead see it as a system that responds to clear instructions. Students shouldn’t be passive users of AI – they should be thoughtful and critical users, recognising that what they ask (and how they ask) matters.

That is an empowering mindset to build as AI becomes an everyday part of our lives.

This is a continuation of what I was talking about last year in bringing generative AI into code clubs and the classroom.

Please give it a try and let me know how you get on, and what you think.

Tags: , , ,

Leave a Reply