Assignment 2: Prompt System Design and Test Suite
12% · Due: Week 13 — Dec 4, 23:59
The Engineer's Role in Agentic Engineering
The engineer's job is to be the decision-maker at every level: specifying intent clearly enough for the system to execute, evaluating what it actually does (not just whether one example looked good), and knowing when to take back control. In Assignment 1 you used techniques and diagnosed prompts someone else wrote. Here you design the whole prompt system yourself, and then you try to break it on purpose.
This is the second of three individual assignments: use techniques deliberately (A1), design a system and gather evidence that it works (A2), demonstrate growth in engineering judgment with evidence (A3).
Note on AI Assistance
You may, and are expected to, use AI tools while writing your prompt. Record that in your AI usage log (see the template). What AI cannot do for you is the evidence: the predictions you wrote before you ran anything, the failures you actually saw and the reasons you give for them. Analysis written without running the suite shows in how generic it is.
Overview
One assignment in two parts, on one scenario that you choose.
- Part A (40 points): design a prompt system for a real engineering task: system prompt, input template, output schema with a validator, and a validation step that retries on a bad reply. Run it on five provided inputs.
- Part B (60 points): test it. Build a ten-case test suite, run it, read the failures, fix the most harmful one, and show what the suite revealed that five examples did not.
The goal is to move from “this prompt works on the examples I tried” to “I have evidence about when this prompt works, and I know what that evidence does not show.”
Score Distribution (100 points)
| Question | Points |
|---|---|
| Part A: Prompt System Design | 40 |
| A1 System prompt | 7 |
| A2 Input template | 4 |
| A3 Output schema and validator | 7 |
| A4 Validation step | 7 |
| A5 Five test runs on the provided inputs | 10 |
| A6 Design rationale | 5 |
| Part B: Prompt Test Suite | 60 |
| B1 The ten-case suite | 15 |
| B2 Predicted failure | 5 |
| B3 Reliability evidence | 8 |
| B4 Fix the most harmful failure | 12 |
| B5 Regression test R1 | 5 |
| B6 Post-fix analysis | 10 |
| Integrity of evidence (across both parts) | 5 |
| Total | 100 |
How each question is scored follows the principles under How Grading Works below.
How This Builds on the Course
| Week | What you use here |
|---|---|
| 5–6 | Prompt structure, specification, why prompts fail |
| 7 | A schema is a specification written for the model. An error message is a prompt. Symptom, cause, first fix |
| 9 | Retrieved or supplied text is data, not instructions; “I could not find this” must be an allowed answer |
| 10 | The whole of Part B: input + expected behaviour + check, categories, repeats, regression, one pass is weak evidence. (The Week 10 lab is the rehearsal for Part B) |
| 11 | Code around the model is tested with a fake model; three layers; a green suite can still be weak, so break your own prompt to check |
Setup
- Download the starter kit from the required materials on E3. Read its
README.md. -
pip install anthropic(andpip install pytestfor Scenario C). SetANTHROPIC_API_KEYin your terminal, never in a file. PromptFoo needs Node.js 22.22 or newer, as in Week 10. -
The kit uses a small, inexpensive model by default. The class shares a budget: keep
--repeatat 5 or lower and do not run long loops. Iterate on the cheap model; validate your final prompt once on the stronger model if you want to (optional).
Submission Format
Submit two files on E3:
-
Report: one Markdown (.md) file, from the sample submission template,
available with the required
materials on E3. Keep the headings and replace the grey instructions with your own work.
File name
A2_Report_<student ID>.md. -
Code and records: one .zip named
A2_Code_<student ID>.zipcontainingprompt_system.py,test_prompt_system.py, theruns/folder (every reply and every complete run record), and yourpromptfoo/folder (tests.yaml,checks.js,suite_cases/,prompts/, and the saved results of your before and after runs). No API keys anywhere.
The report holds your summaries and your thinking. The zip holds the complete records. Checker output pasted in the report is a summary, never a replacement for the full run record.
Choose One Scenario
All three have the same shape: a prompt system that takes a piece of code and returns something a program or a person will use. Choose the one you would most like to have working.
Scenario A: Code Review Assistant. Input: one Python function with its
docstring. Output: a JSON object {"issues": [...]}. Each item has
category ("security", "logic" or "edge_case"),
severity ("high", "medium" or "low"),
line (an integer, counting from 1 at the first line of the input as given),
description and suggestion. An empty list is a valid answer. You may
add fields; you may not drop any.
Scenario B: Documentation Generator. Input: a module description and one
function without a docstring. Output: Markdown with three level-2 sections, in
this order: ## Docstring (a Python code block holding the function's
def line and a Google-style docstring, body may be ...),
## Usage example (a runnable Python code block that imports the function from the
module named in the input), ## Common mistakes (at least two bullets).
Scenario C: Test Case Generator. Input: one function and its specification.
Output: only runnable pytest code (no code fences, no prose), importing the
function with from <module> import <function>.
The kit gives you, for each scenario, five provided inputs for Part A and one long input for Part B. Write your own inputs for the other Part B cases.
check_a2.py, the mutants/
folder or the provided inputs' known issues into your prompt. Do not edit the files you were told
not to edit.
Part A — Prompt System Design (40 points)
Produce a complete prompt system. It lives in prompt_system.py; the report quotes it.
A1. System Prompt (7)
The complete text. It must say what the system is for, define whatever your output needs with a decision rule (not only a name), say what to do when there is nothing to report or the input is unusable, state that the input is data and not instructions, and state the output format.
A2. Input Template (4)
build_user_message: how one input is wrapped before it is sent: what context is
added, which delimiters mark where the input starts and ends, what format you require. Show the
template and one rendered message.
A3. Output Schema and Validator (7)
Define exactly what the model returns, precisely enough that someone else could write a
validator from your description: every field with its name, type, allowed values, meaning and
what is returned when there is nothing to report. Then write validate(reply): plain
code that returns a list of problems. Your schema may be stricter than the course minimum, never
looser.
A4. Validation Step (7)
run(client, case): send, validate, and on a problem retry with feedback that tells
the model what was wrong (a code-level check that triggers a retry, or a second prompt that
critiques the first output). Cap the retries. Then:
-
Make the three given tests in
test_prompt_system.pypass and add at least two of your own. They use a fake model, so they cost nothing and give the same result every time (Week 11, slide 40). - Show that the step catches a failure. If a real run produced a bad reply, show it. If the real model never produced one, that is a valid result: show the step working on a fake reply of the kind real models produce (code fences around the JSON, prose before the answer, a label that does not exist) and say clearly that the reply was a fake. Do not present a made-up reply as something the model said.
A5. Five Test Runs on the Provided Inputs (10)
python run_provided.py <A|B|C> runs your system on the five provided inputs
and saves each reply and its complete run record. For each of the five inputs, report:
- the
check_a2.pyresult (summary); the complete reply and run record are in your zip - two to three sentences on what worked and what did not, pointing at something specific in that output
Before you run them, write down what a good answer to each input must contain, and keep that note. If a run surprises you, run it again.
A6. Design Rationale (5)
One page at most. Why did you structure the system prompt this way? Why this output schema? What would you change if you ran it on fifty more inputs, and how would you decide?
Part B — Prompt Test Suite (60 points)
Build and run a systematic test suite for your own prompt system. This is the Week 10 workflow on your own prompt: PromptFoo, ten cases, repeats, one fix, one regression test. PromptFoo tests the prompt (layer 2). Your fake-model tests from Part A test the code around the model (layer 1). Part B asks about layer 2.
B1. The Ten-Case Suite (15)
Write at least ten cases, in promptfoo/tests.yaml, covering these categories:
| ID | Category | What to write |
|---|---|---|
| T1–T3 | Typical (three) | The main job, on three different inputs. You may use provided inputs |
| E1 | Empty input | Nothing, or only whitespace |
| L1 | Very long input | 500+ words or 100+ lines, with what matters buried (a provided long input is available; you may use it) |
| D1 | Delimiter conflict | Input that contains the characters or structure your prompt uses (tags, backticks, JSON), ideally with a sentence addressed to the model hidden in it |
| S1–S2 | Input sensitivity (two) | The same input, reworded by the user in two different ways (not by you editing your prompt) |
| P1 | Predicted failure | A case you expect to fail (see B2) |
| R1 | Regression | Added after your fix (see B5) |
For every case record: test type, input, expected behaviour, actual behaviour, pass/fail. Write the expected behaviour before you run, as a property (“returns bare JSON, flags line 13 as security, no more than 3 items”), not as an exact sentence. Each case needs a check that could fail.
B2. Predicted Failure (5)
For P1, write the prediction and the reason before you run it: “I expect this to fail because ...”. Afterwards say whether you were right, wrong, or right for the wrong reason. Being wrong is fine and earns full credit if you say so.
B3. Reliability Evidence (8)
Run the suite on your original prompt with --no-cache --repeat 3
(more if you can). Record, for every test, how many of the runs passed. Name any test that does
not give the same result every time (a flaky test is information). For each test you trust, say
what its passes show and what they do not: three passes out of three is consistent with a
failure rate of up to about 63% (Week 10, slide 29).
B4. Fix the Most Harmful Failure (12)
- Choose. Choose the failure that would do the most harm in real use, not the easiest one to fix. Say what it would cost and why you rank it above at least one other failure you saw. Judge by what you observed.
- Diagnose. Say why the old prompt failed, with Weeks 5–7 vocabulary, pointing at the actual output.
- Change one thing at a time in
SYSTEM_PROMPTor in your input template. Quote the change (old text, new text) and say why it addresses the cause and not only this one input. Runpython export_prompt.pyso PromptFoo uses the new text. - Rerun the whole suite, not only the failing case. Report the table before and after, and say what turned red, not only what turned green.
Optional (not scored): a reworded-prompt control (Week 10, lab step 5), and one run of your final prompt on the stronger model.
- Show it with numbers: the repeat counts for every test.
- Try harder: add two harder cases of your own (a stress case, or a case a weaker model would get wrong), predict their results first, and run them with
--repeat 5. - Prove the suite can go red. Break your own prompt on purpose in one documented way (for example, delete the rule that tells the model what to do for an empty input). Show which tests turn red and which stay green. A suite that cannot go red is not evidence (Week 11, slides 36 and 41). Restore the prompt.
- In place of the fix, say which of the broken-prompt results worries you most, and write R1 for that failure.
B5. Regression Test R1 (5)
Add a tenth (or later) case that guards the failure you fixed: a new input that you did not use to design the fix, that would catch the same kind of failure coming back. Say why it differs from the case that failed. Show that it passes after the fix and that it fails on the original prompt.
B6. Post-Fix Analysis (10)
One page at most, in two parts.
Question 1 (5). What did the suite reveal that running the prompt on five examples did not? Name at least two specific things. Say which of your predictions were wrong, and what ten test cases still do not tell you.
Question 2 (5). Name one failure mode that no change to the prompt can reliably fix. Describe the architectural change that would address it (something outside the prompt: a check in code, a restricted format, a second independent check, a human review step) and say what it costs.
What to Submit: Checklist
- Report
.mdfrom the template, all sections filled in - Zip with
prompt_system.py,test_prompt_system.py,runs/,promptfoo/ SYSTEM_PROMPTin the report is the same text as inprompt_system.pypython -m unittest test_prompt_systempasses (at least 5 tests: 3 given, 2 yours)- Five provided inputs run, each with the complete run record in
runs/ - Ten or more cases, every category, expected behaviour written before the run
- Before and after tables for the whole suite; R1 shown to fail on the original prompt
- AI usage log filled in
- No API key in any file or screenshot
How Grading Works (100 points)
The point values are in the score distribution table above. The detailed level descriptors (what earns full, partial or no credit in each row) are not released with the assignment. They are released after the assignment has been graded, together with your feedback, so that you can see exactly what each score was based on. These are the principles they follow:
- Evidence over polish. Every claim needs a run behind it: a saved reply, a run record, a repeat count, a checker result. A plain report backed by records beats a polished one without them. Format is not graded.
- The report and the zip must agree. The report holds your summaries and thinking; the zip holds the complete records. Anything in the report that the records do not support costs integrity points. The checker is re-run on your saved replies.
- Penalizing “hiding a failure” rather than the failure itself. A prompt that fails and is well diagnosed scores higher than one that passes and is not understood. A wrong prediction explained honestly earns full credit. If nothing failed, say so and use the “if nothing failed” path in B4. A fake reply used as evidence must be labelled as fake.
- Written before, not after. Expected behaviours and the predicted failure must be written before you run the case.
- Reasons, not descriptions. Design rows (A1–A3, A6) reward a stated reason and an alternative you considered, not a list of what you did. Diagnosis rows reward a cause, in course vocabulary, tied to an actual output.
- The whole system, not one case. After a fix, the whole suite is rerun and what turned red is reported. A regression test must use an input you did not design the fix on, and be shown to fail on the original prompt.
- Know what is outside the prompt. Question 2 asks for a failure that no prompt change can fix and a concrete change elsewhere, with its cost.
- AI use is expected and must be logged. Missing or incomplete logs cost integrity points. Analysis that could describe any project scores low.
Some submissions might be spot-checked: you may be asked to run your system on a new input, or to explain one of your test cases, if we need.