- Use these prompts while completing Module 2. They are not magic scripts; they are reusable patterns for working with AI inside the editor.
- The module workflow is ask, inspect, run, test, refine. Don’t move to the next part until the verification for the current part passes.
- Attach real files before asking for code changes. In Cursor, use @ file references; if your environment uses GitHub Copilot Chat in VS Code, replace @ with the equivalent # file reference.
- Read generated code before applying it. The prompt tells the AI what to draft; you still decide whether the output is correct.
- Each card shows a weak version and an improved version, so the difference between vague and strict prompting is visible.
- Conventions: @app/main.py attaches the real file; [PASTE ...] is a placeholder for your actual output, user stories or observations; EXACT means use the exact name, route, status code, path or signature; DO NOT is a constraint against a common AI mistake; and “review before applying” means reading imports, route decorators, models, status codes and tests before clicking Apply in Editor.
- Five core principles: one task per prompt; name the exact files; specify exact outcomes (route, status code, response model, imports, function names, and what not to change); verify immediately; and treat AI output as a draft that you review, correct and prove.
Key mindset Treat AI output as a draft. The student owns review, correction, and proof.
T0.1 · T0.2
2.0 Tool setup
Two prompts that prove the editor assistant is reading your real Module 1 project before it writes anything.
T0.1 · First verified interaction: explain the existing /health endpoint
Use this before generating code. It proves the editor assistant can read the actual project file from Module 1.
Weak versionWhat does this project do?
Improved version · T0.1You are helping me work inside my existing FastAPI project for Module 2. Context file: @app/main.py Explain the existing /health endpoint in this file. Please include: 1. The route path and HTTP method. 2. What the route returns. 3. Whether it uses the existing FastAPI app instance. 4. One simple command or browser check I can use to verify it returns HTTP 200. Do NOT suggest code changes yet. I only want to confirm that you can read the real file.
Why it is betterIt attaches the real file, asks for observable facts, and prevents the assistant from jumping into code generation before setup is verified.
Then ask Now list the files you would need me to attach before you generate a data model and in-memory storage layer. Do not write code yet.
The mistake it avoidsAvoids starting Module 2 with an AI assistant that is guessing project structure instead of reading app/main.py.
Tool setup and file-aware context · Prompt library pp. 2-3
T0.2 · Confirm project context before a code-generation prompt
Use this when you are about to generate code and want the assistant to restate the current files and constraints before writing anything.
Weak versionCan you make the next files for me?
Improved version · T0.2Before writing any code, inspect these context files and summarize what already exists. Context files: @app/main.py Tell me: 1. The current FastAPI app variable name. 2. Existing routes. 3. Whether there is already a models.py, storage.py, or tests directory. 4. Any imports or app structure I should preserve. Do NOT generate or modify code in this response.
Why it is betterIt makes the assistant read the project first and gives the student a chance to catch wrong assumptions before code is generated.
Then ask Based on that summary, give me a short checklist of what to review before applying generated code in the next step.
The mistake it avoidsAvoids hallucinated file paths, duplicate FastAPI app instances, and changes that ignore the existing Module 1 skeleton.
Tool setup and context control · Prompt library p. 3
A1 · A2 · A3
2.1 Data model
One generation prompt for app/models.py and app/storage.py, and two targeted fixes: one for model-validation failures, one for storage or import failures.
A1 · Generate the data model and storage layer
Use this in Part 2.1 after setup is verified. This creates app/models.py and app/storage.py.
Weak versionGenerate models and storage for a task tracker API.
Improved version · A1You are a senior Python backend engineer. Generate TWO files for a FastAPI Task Tracker REST API. Context: - This project currently has a working /health endpoint from Module 1. - This module uses in-memory storage only. - Optional context from Module 1 user stories: [OPTIONAL: PASTE 2-3 RELEVANT USER STORIES HERE. Treat them as context only; do not change the required Module 2 model spec.] ============================================================ FILE 1 - app/models.py ============================================================ Use Pydantic v2 syntax only. Define these enums: - TaskStatus(str, Enum): TODO = "ToDo", IN_PROGRESS = "InProgress", DONE = "Done" - TaskPriority(str, Enum): LOW = "Low", MEDIUM = "Medium", HIGH = "High" Define these models: 1. TaskCreate - model_config = ConfigDict(extra="forbid") - title: str, required, 1..200 characters after strip - description: Optional[str] = "" - status: TaskStatus = TaskStatus.TODO - priority: TaskPriority = TaskPriority.MEDIUM - assignee: Optional[str] = None - Include a field_validator for title that strips whitespace, rejects blank titles, and rejects titles over 200 characters. 2. TaskUpdate - model_config = ConfigDict(extra="forbid") - all editable fields optional: title, description, status, priority, assignee - use the same title validator behavior only when title is provided. - DO NOT include id, created_at, or updated_at. 3. TaskResponse - model_config = ConfigDict(extra="forbid") - id: str - title: str - description: str - status: TaskStatus - priority: TaskPriority - assignee: Optional[str] - created_at: datetime - updated_at: datetime ============================================================ FILE 2 - app/storage.py ============================================================ Use an in-memory module-level dictionary: _tasks: dict[str, TaskResponse] = {} Define exactly these functions: - add_task(payload: TaskCreate) -> TaskResponse - get_all_tasks(status=None, priority=None) -> list[TaskResponse] - get_task_by_id(task_id: str) -> Optional[TaskResponse] - update_task(task_id: str, payload: TaskUpdate) -> Optional[TaskResponse] - use payload.model_dump(exclude_unset=True) - update updated_at when a task changes - delete_task(task_id: str) -> bool - _reset() -> None - clears _tasks for tests only HARD CONSTRAINTS: - DO NOT use SQLAlchemy, SQLModel, Alembic, a database, or an ORM. - DO NOT use Pydantic v1 syntax: no @validator, no class Config, no .dict(). - DO NOT include id, created_at, or updated_at in TaskCreate or TaskUpdate. - DO NOT add print or logging statements. - DO NOT create API routes in this step. - DO NOT wrap the answer in long explanation. Output only two code blocks, each preceded by: # FILE: app/models.py # FILE: app/storage.py
Why it is betterIt gives the assistant exact model names, enum values, field defaults, validation rules, storage signatures, and forbidden technologies. It also separates client input fields from server-managed fields.
Then ask Review the generated app/models.py and app/storage.py against this checklist before I apply it: - Pydantic v2 syntax only - TaskStatus and TaskPriority are enums, not plain strings - TaskCreate and TaskUpdate reject unknown fields - title strips whitespace and rejects blank/overlong values - id, created_at, updated_at are not accepted from client input - storage.update_task uses model_dump(exclude_unset=True) - no routes or database code were added
The mistake it avoidsAvoids models that silently accept invalid fields, use outdated Pydantic v1 syntax, or let clients set server-managed values.
Data model and in-memory storage · Prompt library pp. 3-5
A2 · Fix model validation failures from verify_a.py
Use only when python -m tests.verify_a reports FAIL lines related to model validation.
Weak versionMy model tests failed. Fix the models.
Improved version · A2My verification script printed these FAIL lines: [PASTE THE EXACT FAIL LINES FROM: python -m tests.verify_a] Relevant files: @app/models.py @app/storage.py For each failing check, identify the cause and modify ONLY app/models.py unless the failure clearly proves a storage signature problem. Constraints: - Keep the class names, field names, enum values, types, and defaults from Prompt A1. - Keep Pydantic v2 syntax: ConfigDict and field_validator. - Keep title behavior: strip whitespace, reject empty title, reject titles over 200 characters. - Keep extra="forbid" on input models. - DO NOT add id, created_at, or updated_at to TaskCreate or TaskUpdate. - DO NOT add unrelated helper methods or routes. Output only the full updated app/models.py in one code block, unless you explicitly state that a storage-only issue was found.
Why it is betterIt gives the assistant exact failing evidence and limits the change to the model instead of allowing a broad rewrite.
Then ask After your fix, list the exact verification checks that should now pass and explain why in one sentence each.
The mistake it avoidsAvoids broad rewrites that accidentally change fields, defaults, or storage behavior while trying to fix one validator.
Targeted correction after data-model verification · Prompt library pp. 5-6
A3 · Fix storage or import-check failures
Use only when the import check fails or a storage helper has the wrong name, signature, return type, or Pydantic v1 method.
Weak versionThe storage file is broken. Fix it.
Improved version · A3My import or storage check failed. Exact command I ran: [PASTE COMMAND] Exact output: [PASTE ERROR OR FAILING LINE] Relevant files: @app/models.py @app/storage.py Fix ONLY app/storage.py unless the error proves that app/models.py is missing a required class or enum. Required storage API: - add_task(payload: TaskCreate) -> TaskResponse - get_all_tasks(status=None, priority=None) -> list[TaskResponse] - get_task_by_id(task_id: str) -> Optional[TaskResponse] - update_task(task_id: str, payload: TaskUpdate) -> Optional[TaskResponse] - delete_task(task_id: str) -> bool - _reset() -> None Constraints: - Use the existing TaskCreate, TaskUpdate, and TaskResponse models. - Use payload.model_dump(exclude_unset=True), not .dict(). - Generate id, created_at, and updated_at inside storage, not in the route. - DO NOT add routes, databases, ORMs, or logging. Output only the full updated app/storage.py in one code block.
Why it is betterIt covers a missing prompt type from the old library: storage/import failures are different from model-validator failures.
Then ask Now give me a one-line import check I can run to confirm all model and storage names load successfully.
The mistake it avoidsAvoids letting the assistant “fix” endpoint code when the real problem is a storage function name or signature.
Targeted correction after the import check or storage signature review · Prompt library pp. 6-7
B1 · B2.1 · B2.2 · B2.3 · B2.4 · B3
2.2 CRUD endpoints
The vague-versus-strict POST experiment, then one prompt per remaining route in build order, and a targeted fix for any endpoint that fails its curl or Swagger check.
B1 · Vague versus strict prompt for POST /tasks
Use this in Part 2.2. First submit the weak version for review only. Then start a fresh chat and use the improved version.
Weak versionWrite a POST /tasks endpoint using FastAPI.
Improved version · B1You are a senior Python backend engineer. Add ONE route to my existing FastAPI app. Context files: @app/main.py @app/models.py @app/storage.py Generate ONLY the route handler for POST /tasks. Exact specification: - Route: POST /tasks - Status code: 201 Created using status.HTTP_201_CREATED - Tags: ["tasks"] - Request body: TaskCreate - Response model: TaskResponse - Behavior: call storage.add_task(payload) and return the result directly - Error behavior: - missing, blank, or overlong title -> HTTP 422 through Pydantic - invalid status or priority -> HTTP 422 through Pydantic - unknown input field -> HTTP 422 through Pydantic Imports to add at the top of app/main.py if missing: from fastapi import status from app.models import TaskCreate, TaskResponse from app import storage Exact decorator and signature: @app.post("/tasks", response_model=TaskResponse, status_code=status.HTTP_201_CREATED, tags=["tasks"]) def create_task(payload: TaskCreate) -> TaskResponse: ... DO NOT: - DO NOT create a new FastAPI() instance. - DO NOT generate UUIDs or timestamps in the route; storage handles that. - DO NOT add manual request validation; rely on Pydantic. - DO NOT add try/except around storage.add_task. - DO NOT add any other route. Output only the imports to add and the route function in one code block.
Why it is betterThe improved version names the real files, exact route decorator, response model, status code, behavior, and constraints. It turns a vague ask into verifiable backend work.
Then ask Compare the weak and improved outputs. List three concrete differences, especially status code, imports, and whether the generated code uses my existing app and storage layer.
The mistake it avoidsAvoids the default FastAPI 200 response, invented models, new app instances, and manual validation that conflicts with Pydantic.
CRUD endpoint prompting and prompt-quality experiment · Prompt library pp. 7-8
B2.1 · Add GET /tasks list endpoint
Use after POST /tasks is verified. Add only the list endpoint, then verify before moving on.
Weak versionAdd a route to list tasks.
Improved version · B2.1You are a senior Python backend engineer. Add ONE route to my existing FastAPI app. Context files: @app/main.py @app/models.py @app/storage.py Generate ONLY the GET /tasks list route. Exact specification: - Route: GET /tasks - Status code: 200 default is fine - Tags: ["tasks"] - Optional query params: - status: TaskStatus | None = None - priority: TaskPriority | None = None - Response model: list[TaskResponse] - Behavior: return storage.get_all_tasks(status=status, priority=priority) - Empty filter result returns 200 with [] Imports to add only if missing: from app.models import TaskStatus, TaskPriority, TaskResponse from app import storage DO NOT: - DO NOT return 404 for an empty list. - DO NOT manually validate enum values; Pydantic/FastAPI handles invalid query values. - DO NOT add try/except around storage.get_all_tasks. - DO NOT modify POST /tasks or any other route. Output only the imports to add and the new route function in one code block.
Why it is betterIt isolates one endpoint and states the expected empty-list behavior, which is a common source of incorrect 404 responses.
Then ask Give me two single-line curl checks for this route: one with no filters and one with a status filter.
The mistake it avoidsAvoids asking the assistant for all remaining endpoints at once, which makes errors harder to review.
CRUD endpoint scaffolding · Prompt library pp. 8-9
B2.2 · Add GET /tasks/{task_id} endpoint
Use after GET /tasks is verified. Add only the read-by-id endpoint.
Weak versionAdd a GET route for one task.
Improved version · B2.2You are a senior Python backend engineer. Add ONE route to my existing FastAPI app. Context files: @app/main.py @app/models.py @app/storage.py Generate ONLY the GET /tasks/{task_id} route. Exact specification: - Route: GET /tasks/{task_id} - Tags: ["tasks"] - Response model: TaskResponse - Behavior: - call storage.get_task_by_id(task_id) - if found, return the task - if missing, raise HTTPException with status_code=404 and detail="Task with id {task_id} not found" Imports to add only if missing: from fastapi import HTTPException from app.models import TaskResponse from app import storage DO NOT: - DO NOT wrap the storage call in try/except. - DO NOT return None for a missing task. - DO NOT create a new FastAPI() instance. - DO NOT modify other routes. Output only the imports to add and the new route function in one code block.
Why it is betterIt makes missing-task behavior explicit and prevents the assistant from returning null or relying on exceptions from storage.
Then ask Give me one curl check for an existing task id and one for a definitely missing id. Show the expected HTTP status for each.
The mistake it avoidsAvoids unclear 404 behavior and storage helper hallucinations such as storage.find_one().
CRUD endpoint scaffolding · Prompt library p. 10
B2.3 · Add PATCH /tasks/{task_id} endpoint without transition logic yet
Use after GET by id is verified. This is only the basic PATCH route; business rules come later in Part 2.3.
Weak versionAdd an update route.
Improved version · B2.3You are a senior Python backend engineer. Add ONE route to my existing FastAPI app. Context files: @app/main.py @app/models.py @app/storage.py Generate ONLY the PATCH /tasks/{task_id} route. Exact specification: - Route: PATCH /tasks/{task_id} - Tags: ["tasks"] - Request body: TaskUpdate - Response model: TaskResponse - Behavior: - call storage.update_task(task_id, payload) - if updated task is returned, return it - if None is returned, raise HTTPException with status_code=404 and detail="Task with id {task_id} not found" - Pydantic handles invalid body values with HTTP 422. Imports to add only if missing: from fastapi import HTTPException from app.models import TaskUpdate, TaskResponse from app import storage DO NOT: - DO NOT add status-transition validation yet. That comes in Part 2.3. - DO NOT manually inspect payload.model_dump in the route; storage handles updates. - DO NOT change storage.py. - DO NOT modify other routes. Output only the imports to add and the new route function in one code block.
Why it is betterIt keeps CRUD scaffolding separate from business logic, matching the module sequence.
Then ask Give me one curl check for a title-only PATCH and one curl check for PATCH on a missing task id.
The mistake it avoidsAvoids mixing business rules into the endpoint before the transition rules have been specified.
CRUD endpoint scaffolding · Prompt library pp. 11-12
B2.4 · Add DELETE /tasks/{task_id} endpoint
Use after PATCH is verified. This completes the five CRUD endpoints.
Weak versionAdd a delete route.
Improved version · B2.4You are a senior Python backend engineer. Add ONE route to my existing FastAPI app. Context files: @app/main.py @app/models.py @app/storage.py Generate ONLY the DELETE /tasks/{task_id} route. Exact specification: - Route: DELETE /tasks/{task_id} - Decorator status_code: status.HTTP_204_NO_CONTENT - Tags: ["tasks"] - Behavior: - call storage.delete_task(task_id) - if True, return an empty 204 response - if False, raise HTTPException with status_code=404 and detail="Task with id {task_id} not found" Imports to add only if missing: from fastapi import HTTPException, status from app import storage DO NOT: - DO NOT return a JSON body on success. - DO NOT call r.json() in verification for a 204 response. - DO NOT modify other routes. - DO NOT create a new FastAPI() instance. Output only the imports to add and the new route function in one code block.
Why it is betterIt calls out the 204 empty-body behavior, which is easy for AI-generated code and tests to get wrong.
Then ask Give me one curl check that creates a task, deletes it, and then confirms GET by id returns 404. Keep each command single-line.
The mistake it avoidsAvoids returning 200 or a JSON object for a successful delete.
CRUD endpoint scaffolding · Prompt library pp. 12-13
B3 · Fix endpoint verification failures
Use when an endpoint returns the wrong status code, wrong body shape, or calls the wrong storage helper.
Weak versionMy endpoint is returning the wrong thing. Fix it.
Improved version · B3One endpoint verification failed. Endpoint being tested: [PASTE METHOD AND PATH] Command or Swagger action: [PASTE COMMAND OR DESCRIPTION] Expected result: [PASTE EXPECTED STATUS/BODY] Actual result: [PASTE ACTUAL STATUS/BODY] Relevant files: @app/main.py @app/models.py @app/storage.py Fix only the route responsible for this endpoint unless the failure clearly proves a model or storage issue. Constraints: - Preserve the existing FastAPI app instance. - Preserve all other routes. - Use the existing storage helper names. - Use Pydantic/FastAPI validation instead of manual validation for request bodies and enum values. - DO NOT add try/except as a workaround. Output only the changed route function and any imports that must be added.
Why it is betterIt gives the assistant concrete expected-versus-actual evidence and limits the blast radius to the failing route.
Then ask After the fix, give me the exact single-line curl command I should run to confirm the endpoint now behaves correctly.
The mistake it avoidsAvoids vague debugging prompts that lead to broad rewrites of app/main.py.
Targeted correction after curl or Swagger verification · Prompt library pp. 13-14
C1 · C2
2.3 Business rules
Add the status-transition rule as its own module and wire it into PATCH, then fix the rule against the six-check matrix if any check is off.
C1 · Add status-transition validation
Use after all five CRUD endpoints work. This adds the domain rule that PATCH cannot set any arbitrary status.
Weak versionMake sure task status changes are valid.
Improved version · C1Add status-transition validation to my existing PATCH /tasks/{task_id} route. Context files: @app/main.py @app/models.py @app/storage.py Create a new module and modify only the existing PATCH route. ============================================================ FILE 1 - app/business_rules.py ============================================================ Use these imports: from fastapi import HTTPException, status from app.models import TaskStatus Create this constant: VALID_TRANSITIONS: frozenset[tuple[TaskStatus, TaskStatus]] = frozenset({ (TaskStatus.TODO, TaskStatus.IN_PROGRESS), (TaskStatus.IN_PROGRESS, TaskStatus.DONE), (TaskStatus.DONE, TaskStatus.IN_PROGRESS), }) Create this function: def validate_status_transition(current: TaskStatus, new: TaskStatus) -> None: # Same -> same is invalid. Anything not in VALID_TRANSITIONS is invalid. if (current, new) not in VALID_TRANSITIONS: allowed = sorted({f"{f.value}->{t.value}" for f, t in VALID_TRANSITIONS}) raise HTTPException( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=f"Invalid status transition from {current.value} to {new.value}. Allowed transitions: {allowed}", ) ============================================================ FILE 2 - app/main.py ============================================================ Modify the existing PATCH /tasks/{task_id} route only. Add this import if missing: from app.business_rules import validate_status_transition PATCH behavior: 1. If payload.status is None, skip transition validation and allow other partial updates. 2. If payload.status is provided: a. Get the existing task with storage.get_task_by_id(task_id). b. If it does not exist, raise the existing 404 behavior. c. Call validate_status_transition(existing.status, payload.status). 3. Then call storage.update_task(task_id, payload) and return the updated task. DO NOT: - DO NOT validate only whether the new status is a valid enum. The rule depends on the (current, new) pair. - DO NOT allow ToDo -> Done, Done -> ToDo, or same -> same. - DO NOT validate when payload.status is None. - DO NOT inline the rules with if/elif chains; use the frozenset. - DO NOT modify POST, GET, or DELETE routes. Output two code blocks: # FILE: app/business_rules.py # PATCH ROUTE ONLY FROM app/main.py
Why it is betterIt distinguishes a field setter from a business rule. The improved prompt specifies the allowed transition pairs and the exact place where validation belongs.
Then ask Before I apply this, review the proposed code and answer: 1. Does it compare the current and new status as a pair? 2. Does it skip validation for title-only PATCH requests? 3. Does a missing task still return 404 before validation? 4. Are same -> same transitions rejected?
The mistake it avoidsAvoids the common bug where the AI checks only that the new status is a valid enum value.
Business rules and PATCH route refinement · Prompt library pp. 14-15
C2 · Fix transition matrix failures
Use when the six transition checks do not produce the expected pattern: 200, 200, 422, 200, 422, 200.
Weak versionThe transition tests failed. Fix the business rules.
Improved version · C2My transition verification printed these failing line(s): [PASTE THE FAILING LINE(S)] Expected pattern for the six checks: 200, 200, 422, 200, 422, 200 Relevant files: @app/business_rules.py @app/main.py For each failing check, identify the root cause and fix it without changing the public function names or route paths. Checklist of common root causes: - validate_status_transition checks only the new status, not the (current, new) pair. - The PATCH route validates even when payload.status is None. - The PATCH route validates before checking whether the task exists. - Same -> same was accidentally allowed. - The route changed the expected 404 behavior. Constraints: - Keep VALID_TRANSITIONS as the three allowed pairs. - Keep same -> same invalid. - Keep invalid transitions as HTTP 422. - Do not modify unrelated routes. Output only the full updated app/business_rules.py and the updated PATCH route.
Why it is betterIt treats the transition matrix as evidence and focuses the assistant on the precise rule failure.
Then ask After the fix, restate which transition pair caused the failure and why the new code returns the expected status code.
The mistake it avoidsAvoids accidental changes that make a transition pass by weakening the rules.
Targeted correction after business-rule verification · Prompt library pp. 15-16
D1 · D2 · D3
2.4 API tests
Generate a named pytest suite, fix failures by saying whether the test or the production code is wrong, and read a Break Test without repairing the deliberate bug.
D1 · Generate the pytest API test suite
Use after the data model, CRUD routes, and business rules are working. Generate tests, review them, then run pytest.
Weak versionWrite tests for the API.
Improved version · D1You are a senior Python developer writing pytest tests for a FastAPI app. Context files: @app/main.py @app/models.py @app/storage.py @app/business_rules.py Generate TWO files. Output only two code blocks, each preceded by: # FILE: tests/conftest.py # FILE: tests/test_tasks.py ============================================================ FILE 1 - tests/conftest.py ============================================================ Use: - pytest - fastapi.testclient.TestClient - app.main import app - app import storage Fixtures: 1. _reset_storage autouse fixture - calls storage._reset() before and after each test 2. client fixture - returns TestClient(app) 3. created_task fixture - posts {"title": "fixture task"} - asserts status_code == 201 - returns response JSON ============================================================ FILE 2 - tests/test_tasks.py ============================================================ Generate these named tests: POST /tasks: - test_create_task_valid_returns_201_with_full_body - test_create_task_missing_title_returns_422 - test_create_task_blank_title_returns_422 - test_create_task_invalid_priority_returns_422 - test_create_task_unknown_field_returns_422 GET /tasks: - test_list_tasks_empty_returns_200_and_empty_list - test_list_tasks_filter_by_status_no_match_returns_200_and_empty_list - test_list_tasks_filter_by_priority_returns_only_matches GET /tasks/{id}: - test_get_task_by_id_returns_task - test_get_task_by_id_not_found_returns_404_with_detail PATCH /tasks/{id}: - test_patch_partial_update_keeps_other_fields - test_patch_not_found_returns_404 - test_patch_valid_transition_todo_to_inprogress_returns_200 - test_patch_invalid_transition_todo_to_done_returns_422 - test_patch_same_status_returns_422 DELETE /tasks/{id}: - test_delete_existing_returns_204_no_body - test_delete_missing_returns_404 Hard constraints: - Use TestClient only. Do not use AsyncClient. - Do not mock storage. Use the real in-memory storage with the reset fixture. - Do not call r.json() on a 204 response; assert r.content == b"". - Do not skip or rename the listed tests. - Do not add tests unrelated to Module 2. - Use the exact route paths from the app. Output only the two files.
Why it is betterIt names concrete test cases instead of asking for generic “coverage.” It also prevents common false-confidence issues such as state leakage and incorrect 204 assertions.
Then ask Before I apply these tests, review them against this checklist: - missing_title sends an empty JSON object - blank_title sends spaces - invalid transition expects 422 - same status expects 422 - 204 delete checks r.content == b"" - storage reset fixture uses autouse=True
The mistake it avoidsAvoids vague tests that pass without checking the behaviors Module 2 actually teaches.
API tests and fixtures · Prompt library pp. 16-18
D2 · Fix pytest failures with explicit test-versus-production reasoning
Use when pytest reports failures. The assistant must say whether the test or production code is wrong.
Weak versionPytest failed. Fix it.
Improved version · D2My pytest output shows these failures: [PASTE THE FULL FAILING PYTEST OUTPUT, INCLUDING ASSERT LINES AND ACTUAL/EXPECTED VALUES] Relevant files: @app/main.py @app/models.py @app/storage.py @app/business_rules.py @tests/conftest.py @tests/test_tasks.py For each failure: 1. Identify the root cause. 2. State explicitly whether you are fixing the TEST or the PRODUCTION CODE. 3. Explain why in one sentence. 4. Provide only the file(s) that need to change. Constraints: - Do not delete, skip, or rename any test from Prompt D1. - Do not add unrelated tests. - Do not change public route paths or model names. - Do not use try/except as a workaround. - Do not weaken assertions just to make tests pass. Output one code block per changed file, with a one-line comment at the top: # CHANGED: <which test or function and why>
Why it is betterIt prevents the AI from blindly editing tests to match broken code or editing production code when the test expectation is wrong.
Then ask After the fix, tell me the exact pytest command to rerun and which test names should now pass.
The mistake it avoidsAvoids “green by weakening the test,” which undermines the Break Test lesson.
Targeted correction after pytest · Prompt library pp. 18-19
D3 · Diagnose Break Test results
Use after deliberately breaking production code to prove the tests catch real regressions.
Weak versionI broke the code and pytest did something. What now?
Improved version · D3I am running a Break Test for Module 2. The production code is intentionally broken right now. Break I introduced: [PASTE EXACT CHANGE, such as "commented out validate_status_transition(...) in the PATCH route"] Tests I expected to fail: [PASTE EXPECTED TEST NAMES] Actual pytest output: [PASTE OUTPUT] Analyze the result. Rules: - Do NOT fix the intentionally broken production code in this response. - If the expected test failed, explain what behavior the test successfully protected. - If a test passed when it should have failed, identify the missing or weak assertion and propose a test-only fix. - If an unexpected test failed, explain whether that reveals a real dependency or a bad test. Output: 1. Break Test result summary 2. Which tests are trustworthy 3. Which tests need improvement, if any 4. Test-only code changes if needed
Why it is betterIt keeps the AI from “repairing” the intentional bug and instead focuses on whether the tests are meaningful.
Then ask Now that I restored the production code, here is the new pytest output. Confirm whether the Break Test cycle is complete and what I should record in my reflection log.
The mistake it avoidsAvoids treating a green test suite as proof before checking whether tests fail when the code is broken.
Break Test and test-quality validation · Prompt library pp. 19-20
E1 · E2
Deliverables
Two prompts that turn the module’s evidence into the documentation deliverables: the prompt comparison log and the reflection log.
E1 · Create the prompt comparison log
Use after the vague-versus-strict POST experiment. This helps students document what changed between prompts.
Weak versionSummarize which prompt was better.
Improved version · E1Help me create a short prompt comparison log for Module 2. Weak prompt: [PASTE THE VAGUE PROMPT] Weak output observations: [PASTE 3-5 THINGS YOU NOTICED] Improved prompt: [PASTE THE STRICT PROMPT OR A SUMMARY] Improved output observations: [PASTE 3-5 THINGS YOU NOTICED] Create a concise comparison with these columns: - Prompt difference - Weak output risk - Improved output benefit - What I learned for future prompts Keep it student-friendly and specific to the POST /tasks endpoint.
Why it is betterIt turns the lecture experiment into a reusable learning artifact rather than just a coding step.
Then ask Rewrite the comparison in 4-5 sentences for my Module 2 reflection log.
The mistake it avoidsAvoids vague reflections such as “the strict prompt was better” without evidence.
Module deliverable and reflection support · Prompt library pp. 20-21
E2 · Write the Module 2 reflection log
Use at the end of Module 2 after verification and Break Test are complete.
Weak versionWrite my reflection for this module.
Improved version · E2Help me draft a 3-5 sentence Module 2 reflection log. Facts from my work: - Data model verification result: [PASTE RESULT] - CRUD endpoint verification result: [PASTE RESULT] - Business-rule transition matrix result: [PASTE RESULT] - Pytest result: [PASTE RESULT] - Break Test result: [PASTE WHAT FAILED WHEN YOU BROKE THE CODE] - One thing Cursor/editor AI did well: [PASTE] - One thing I had to correct or verify carefully: [PASTE] Write the reflection in first person, but keep it professional and specific. Do not exaggerate; only mention evidence I provided.
Why it is betterIt connects prompt use to verification evidence, which is the core learning outcome of the module.
Then ask Make the reflection slightly shorter and more suitable for a course submission.
The mistake it avoidsAvoids generic AI reflections that do not mention the actual backend behaviors or verification results.
Module deliverable and learning consolidation · Prompt library pp. 21-22
O1 · O2
Optional extension prompts
Useful, but not required core prompts for Module 2. Use them only after the required implementation, verification, and Break Test are complete.
O1 · Explain pytest or framework warnings
Use if pytest passes but prints warnings. This was visible in the demo environment, but warning cleanup is not the main Module 2 learning goal.
Weak versionWhat are these warnings?
Improved version · O1My pytest suite passed, but it printed these warnings: [PASTE WARNINGS] Relevant files: @app/main.py @app/models.py @tests/test_tasks.py Explain each warning in beginner-friendly language. Do not change code yet. First classify each warning as: - safe to ignore for this module - should be fixed now - should be noted for later refactoring Then suggest the smallest safe change only for warnings that should be fixed now.
Why it is betterIt prevents warning cleanup from distracting students unless a warning affects correctness.
Then ask Give me a short note I can add to my reflection log explaining why I left this warning alone or fixed it.
The mistake it avoidsAvoids over-refactoring working code just to remove non-critical warnings.
Optional extension · Prompt library p. 22
O2 · Generate a final API summary checklist
Use after all work is complete to create a quick reference for the backend you built.
Weak versionMake a README for my API.
Improved version · O2Create a concise API summary checklist for the Module 2 Task Tracker backend. Use only these verified facts from my project: - Data model: [PASTE SUMMARY OR ATTACH @app/models.py] - Endpoints: [PASTE VERIFIED ENDPOINT LIST OR ATTACH @app/main.py] - Business rules: [PASTE SUMMARY OR ATTACH @app/business_rules.py] - Test result: [PASTE PYTEST RESULT] Keep the output to one page or less. Include: 1. Models and enums 2. Endpoints and expected status codes 3. Status transition rules 4. Verification commands already passed 5. Break Test proof Do not invent features, authentication, databases, or frontend behavior.
Why it is betterIt creates a compact summary without letting the AI add features beyond the module.
Then ask Turn that checklist into a short study guide for the quiz, using only Module 2 concepts.
The mistake it avoidsAvoids README-style hallucinations such as databases, authentication, deployment, or frontend features not covered in Module 2.
Optional extension · Prompt library p. 23
End-of-module checklist
The library closes with what you should have produced and saved before moving on.
| Part | Prompt cards |
|---|---|
| 2.0 Tool setup | T0.1 Explain /health; T0.2 Confirm project context |
| 2.1 Data model | A1 Generate models/storage; A2 Fix model validation failures; A3 Fix storage/import failures |
| 2.2 CRUD endpoints | B1 Vague vs strict POST; B2.1 GET list; B2.2 GET by id; B2.3 PATCH; B2.4 DELETE; B3 Fix endpoint verification failures |
| 2.3 Business rules | C1 Add status-transition validation; C2 Fix transition matrix failures |
| 2.4 API tests | D1 Generate pytest suite; D2 Fix pytest failures; D3 Diagnose Break Test results |
| Deliverables | E1 Prompt comparison log; E2 Reflection log |
| Optional extension | O1 Explain warnings; O2 Produce API summary/checklist |
Read with careThe library has no separate end-of-module checklist, so its own quick-reference table is shown here. The module’s deliverables list is in the lecture notes, pp. 10-11.