Lab: Prompt engineering challenge
Start with a deliberately vague prompt and iterate through every technique from this module — ending with a final version you can compare to your first attempt.
This lab is a structured prompt engineering exercise. You'll begin with a bad prompt — one that's vague, under-specified, and likely to produce an unhelpful response — and progressively improve it using every technique covered in this module.
You'll need access to an AI assistant (Claude, ChatGPT, or any chat-based LLM) to run these prompts. The goal is not just to get a good final response but to develop a feel for what specifically each improvement adds.
The starting prompt
Here is the vague prompt you'll use as your starting point. Do not improve it yet — run it first and note what you get.
Starting prompt: "Help me write a function."
Run this in your AI assistant and paste the response somewhere you can refer back to it (a text file, a note, a separate tab).
Observe: What did the model produce? What assumptions did it make? What did it get wrong or leave undefined?
Step 1: Apply the Task/Context/Format/Constraints framework
Now rewrite the prompt using all four components. Here is the specific task you're actually targeting:
You want a Python function that takes a list of dictionaries — each with
"name"(string),"score"(integer), and"active"(boolean) keys — and returns a new list containing only the active entries, sorted by score in descending order.
Using the Task/Context/Format/Constraints framework:
- Task: what the function should do
- Context: the shape of the input data (the dictionary keys and types)
- Format: you want just the function body in a Python code block, with a docstring
- Constraints: no external libraries; handle the case where the input list is empty; use type hints
Write your improved prompt, run it, and note what changed in the response.
Check: Did the model produce a working function? Does it handle an empty list? Does it use type hints? Does it have a docstring?
Step 2: Add a role
Extend your prompt from Step 1 by adding a role. Try this framing:
"Act as a senior Python developer doing a code review for a junior. Write the function, then add a brief comment about anything a junior developer might get wrong when modifying this code."
Run the updated prompt and observe: what did the role add? Did the tone or content of the explanation change? Did the model surface any non-obvious considerations?
The role here does two things: it shifts the register toward experienced-practitioner thinking, and it explicitly requests a review note that wouldn't appear in a pure "write the function" prompt. Both parts are doing work.
Step 3: Apply chain-of-thought
Now apply chain-of-thought reasoning to the same task. Add this instruction to your prompt:
"Before writing the function, explain step by step: (1) what the problem requires, (2) what Python built-ins or idioms are the right tools, and (3) any edge cases to consider. Then write the function."
Run the updated prompt. Notice whether the intermediate reasoning reveals anything you hadn't explicitly asked for. Does the model catch the empty-list edge case through reasoning rather than because you specified it?
Reflect: Did the chain-of-thought step produce any insight that wasn't in the Step 1 or Step 2 output? Was there a step in the reasoning that you'd want to push back on or verify?
Step 4: Iterate based on the output
Your Step 3 output should be a reasonably good function. Now deliberately break it using one of these scenarios and ask for a targeted fix:
Scenario A: The function produces the correct output but you want the sort to be stable — entries with the same score should maintain their original relative order. Ask the model whether the current implementation guarantees this.
Scenario B: A colleague says the code is hard to read because the list comprehension is too dense. Ask the model to refactor it for readability without changing its behaviour.
Scenario C: You've discovered that some dictionaries in the real data are missing the "active" key entirely. Ask the model to handle that gracefully with a sensible default.
Pick one scenario, send the targeted follow-up, and note how the model responds to a specific, scoped correction.
Step 5: Ask for a critique
After getting the final version of the function, send this follow-up:
"What are the weaknesses of this implementation? What would you do differently if you were starting from scratch and performance on very large lists was a concern?"
Note what the model says. Does it surface anything you hadn't considered? Is there a weakness it identifies that you disagree with?
Step 6: Compare first vs. final
Look at your two responses side by side: the output from the starting prompt ("Help me write a function.") and the output from your final, iterated prompt.
Write down — even just informally in a note — answers to these questions:
- What specific component was most responsible for the improvement between the first and final version?
- Which step (framework, role, chain-of-thought, iteration, critique) added the most value?
- Was there a step that added complexity but didn't materially improve the output?
- What would you do differently next time you approach a similar task?
This reflection step is not optional busywork. The ability to accurately assess which part of a prompt change produced which part of an output improvement is the core skill this lab is building. You're training your own diagnostic loop, not just producing a good function.
What you've practised
This lab applied all five techniques from the Prompt Crafting module to a single concrete task:
- Task/Context/Format/Constraints — structuring the initial request precisely
- Role prompting — shifting the register and focus of the response
- Chain-of-thought — surfacing explicit reasoning you can verify and engage with
- Iterating mid-conversation — using targeted follow-ups to correct specific issues
- Requesting critique — using the model's output as material for a better next round
Each technique addresses a different failure mode. The habit of reaching for the right one at the right moment is what makes AI assistance reliable rather than hit-or-miss.
Up next: the second module — AI for Problem Solving — moves from individual prompt techniques to larger-scale strategies: decomposing complex problems, debugging with AI, validating AI-generated solutions, and using AI as a research partner.
Tokens and context windows
Understand what tokens are, why context windows matter, and how to work within them efficiently rather than fighting their limits.
Decomposing problems for AI
Break vague, large problems into concrete sub-tasks that AI can handle reliably — the foundational skill for using AI on real projects.