Why the model comes first
The notes call the data model the contract every endpoint is built on. If the model is loose or wrong, every endpoint inherits those mistakes. That is why the first implementation prompt in the module is strict and verification-heavy. Part 2.1 has four goals: create app/models.py with Pydantic v2 request and response models; create app/storage.py with an in-memory storage layer and predictable helper functions; use enums for task status and priority instead of plain strings; and keep server-managed fields, such as id, created_at and updated_at, out of client input models.
Key ideaThe data model is the contract every endpoint is built on. A loose model makes every endpoint loose.
Core model expectations
The notes list what each element of the contract is for.
| Element | Expected role |
|---|---|
| TaskStatus | Enum values such as ToDo, InProgress, and Done. |
| TaskPriority | Enum values for priority, with Medium as the default used in the demo. |
| TaskCreate | Client input for creating a task. Requires a non-blank title and rejects extra fields. |
| TaskUpdate | Client input for partial updates. Allows optional editable fields, but not server-managed fields. |
| TaskResponse | Response model returned by the API. Includes server-generated id and timestamps. |
| storage helpers | add_task, get_all_tasks, get_task_by_id, update_task, delete_task, and _reset. |
Client input versus server-managed fields
The split between what a client may send and what the server owns is the heart of the model. A client creates or edits a task’s content; the server decides its identity and its timestamps. Prompt A1 makes this concrete: TaskCreate and TaskUpdate both forbid extra fields and never include id, created_at or updated_at, while TaskResponse carries all of them. Storage, not the route, generates the id and timestamps.
Client input (TaskCreate, TaskUpdate)
- title (stripped, 1 to 200 characters)
- description
- status (TaskStatus enum)
- priority (TaskPriority enum)
- assignee
- extra fields rejected
Server-managed (TaskResponse only)
- id, generated in storage
- created_at, set on create
- updated_at, refreshed on change
- never accepted from a payload
If a client can send its own id or timestamps, the API no longer controls its own records.
Prompt A1 and what to inspect
Prompt A1 specifies exact files, class names, enum values, defaults, validators, storage function names and Pydantic v2 syntax, plus a list of hard constraints: no database or ORM, no Pydantic v1 syntax, no server fields in input models, no logging, no routes yet. Before you apply what comes back, the notes ask you to check five things. Then run the one-line import check to confirm every name loads.
- Pydantic v2 syntax is used, such as @field_validator and model_dump where needed.
- Status and priority are enums, not unconstrained strings.
- Title validation rejects empty and whitespace-only titles.
- Extra fields are forbidden in input models.
- id, created_at and updated_at are generated by storage or API code, not accepted from create or update payloads.
Import check from the notespython -c "from app.models import TaskCreate, TaskUpdate, TaskResponse, TaskStatus, TaskPriority; from app.storage import add_task, get_all_tasks, get_task_by_id, update_task, delete_task, _reset; print('OK')"
Verification A: eight checks
The verification script, tests/verify_a.py, should print PASS for all eight checks. If any line says FAIL, use Prompt A2 as a targeted fix and rerun the script before continuing. If instead the import check fails, or a storage helper has the wrong name, signature or a Pydantic v1 method, Prompt A3 fixes storage only. Keeping those two fixes separate stops the assistant from rewriting the wrong file.
- Whitespace title rejected.
- Empty title rejected.
- Title over 200 characters rejected.
- Defaults applied: status ToDo, priority Medium, and empty description.
- Extra field rejected on TaskCreate.
- id rejected on TaskCreate.
- created_at rejected on TaskUpdate.
- Invalid status rejected.
Command from the notespython -m tests.verify_a # Expected: every line says PASS.
Read with careThe notes describe what verify_a.py checks but do not print the script itself, and the hands-on guide that may contain it was not supplied. You write or obtain it as part of the module.
Common AI mistakes in the model layer
The notes list six mistakes to catch. Most of them produce code that runs, which is exactly why they are dangerous: nothing crashes, the model just quietly accepts something it shouldn’t.
- Mixes Pydantic v1 syntax into a Pydantic v2 project.
- Uses plain strings for status instead of TaskStatus.
- Accepts whitespace-only titles because it does not strip before checking.
- Allows clients to send id or timestamps in TaskCreate or TaskUpdate.
- Omits extra="forbid", allowing arbitrary fields silently.
- Invents helper names that later endpoint prompts do not use.
Key ideaThe last mistake matters later: every endpoint prompt names the storage helpers exactly, so an invented helper name breaks Part 2.2 before it starts.
What you leave Part 2.1 with
Part 2.1 ends with code, a passing script and a note.
- app/models.py with strict Pydantic v2 models and enums.
- app/storage.py with in-memory storage helpers and _reset.
- tests/verify_a.py saved and passing all eight checks.
- At least one note in your correction log if Cursor required a fix.
Key takeaways
- The model is the contract; a loose model makes every endpoint loose.
- Use enums for status and priority, strip and validate the title, and forbid extra fields.
- Clients never send id or timestamps; storage generates them.
- Fix verify_a.py failures with A2 (models) or A3 (storage), never with a broad rewrite.