Due: Friday, December 4, 23:59, on E3. Weight: 12%. Format: one report (.md, from the sample submission template) and one .zip with your code and records. Individual work.
Assignment 2 materials (including the starter kit and the sample submission template): posted on E3.

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.

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)

QuestionPoints
Part A: Prompt System Design40
A1 System prompt7
A2 Input template4
A3 Output schema and validator7
A4 Validation step7
A5 Five test runs on the provided inputs10
A6 Design rationale5
Part B: Prompt Test Suite60
B1 The ten-case suite15
B2 Predicted failure5
B3 Reliability evidence8
B4 Fix the most harmful failure12
B5 Regression test R15
B6 Post-fix analysis10
Integrity of evidence (across both parts)5
Total100

How each question is scored follows the principles under How Grading Works below.

How This Builds on the Course

WeekWhat you use here
5–6Prompt structure, specification, why prompts fail
7A schema is a specification written for the model. An error message is a prompt. Symptom, cause, first fix
9Retrieved or supplied text is data, not instructions; “I could not find this” must be an allowed answer
10The 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)
11Code 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

  1. Download the starter kit from the required materials on E3. Read its README.md.
  2. pip install anthropic (and pip install pytest for Scenario C). Set ANTHROPIC_API_KEY in your terminal, never in a file. PromptFoo needs Node.js 22.22 or newer, as in Week 10.
  3. The kit uses a small, inexpensive model by default. The class shares a budget: keep --repeat at 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:

  1. 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.
  2. Code and records: one .zip named A2_Code_<student ID>.zip containing prompt_system.py, test_prompt_system.py, the runs/ folder (every reply and every complete run record), and your promptfoo/ 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.

Rules that apply to everything. Your prompt must work on inputs you have not seen: Part B tests exactly that. Do not paste 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:

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:

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.

If all five inputs pass the checker, that is a real result, not a mistake. Say so and use your commentary for what the checker cannot see (for example whether the descriptions are useful, or one thing about the output you would not accept in a real project).

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:

IDCategoryWhat to write
T1–T3Typical (three)The main job, on three different inputs. You may use provided inputs
E1Empty inputNothing, or only whitespace
L1Very long input500+ words or 100+ lines, with what matters buried (a provided long input is available; you may use it)
D1Delimiter conflictInput that contains the characters or structure your prompt uses (tags, backticks, JSON), ideally with a sentence addressed to the model hidden in it
S1–S2Input sensitivity (two)The same input, reworded by the user in two different ways (not by you editing your prompt)
P1Predicted failureA case you expect to fail (see B2)
R1RegressionAdded 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)

  1. 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.
  2. Diagnose. Say why the old prompt failed, with Weeks 5–7 vocabulary, pointing at the actual output.
  3. Change one thing at a time in SYSTEM_PROMPT or in your input template. Quote the change (old text, new text) and say why it addresses the cause and not only this one input. Run python export_prompt.py so PromptFoo uses the new text.
  4. 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.

If nothing failed. Report it honestly. That is a valid result, and this path earns full credit when you do all of the following:
  1. Show it with numbers: the repeat counts for every test.
  2. 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.
  3. 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.
  4. 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

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:

  1. 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.
  2. 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.
  3. 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.
  4. Written before, not after. Expected behaviours and the predicted failure must be written before you run the case.
  5. 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.
  6. 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.
  7. 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.
  8. 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.

← Back to Assignments