LESSON 5

AI-Assisted Implementation: The Vertical Slice

Implement a feature end to end in small verified steps: from acceptance criteria and tests to working code, reviewed and committed.

Introduction

Building all the database code, then all the API code, then all the screens delivers nothing usable until the end, and hides integration problems until it is too late. A vertical slice cuts through every layer to deliver one small piece of user-visible behavior.

For SignalDesk, the first slice is: a workspace member uploads a CSV of customer feedback and sees the imported items listed. This lesson implements the core of it using the loop from lesson 1, and shows how to keep AI assistance under control while doing so.

Learning Objectives

  • Choose and define a thin vertical slice from the backlog.
  • Convert acceptance criteria into executable tests before implementation.
  • Drive an assistant through plan, test, implement, verify, review, and commit in small steps.
  • Review generated code for edge cases, error handling, security, and performance.
  • Recognize when to discard output and restart rather than keep patching.

1. Slicing the Work

A good slice is:

  • Valuable: a user or stakeholder can observe the behavior.
  • Thin: a few days at most for one person.
  • Vertical: it touches interface, logic, and storage.
  • Testable: it has clear acceptance criteria.

SignalDesk slice 1 (illustrative), traced to the SRS:

Requirement Acceptance criterion (summarized)
FR-IMP-01 A member uploads a CSV with columns body, source, date; valid rows become feedback items in their workspace
FR-IMP-02 Rows with an empty body or an invalid date are rejected with a reason; valid rows still import
FR-IMP-03 The result shows counts of imported, rejected, and the reasons
FR-IMP-04 Uploading the same file twice does not create duplicates
NFR (limits) Files above the size limit are rejected before processing

If the slice is larger than your sprint capacity allows, cut it further: for example, deliver validation and import first, and the rejected-row report second.

2. Plan the Slice

Start with a plan, reviewed by you. Ask the assistant for one and challenge it.

1
2
3
4
5
6
7
8
Context: [ASSISTANT_INSTRUCTIONS.md, module structure,
          requirements FR-IMP-01 to FR-IMP-04, data model excerpt]

Task: Propose a plan for implementing the CSV import slice.
Include: files to add or change, function signatures, data flow,
the order of steps (smallest testable step first), edge cases,
and risks. Do not write code yet.
Question anything in the requirements that is ambiguous.

Look for hidden decisions: maximum file size and row count, encoding, delimiter handling, header variations, how duplicates are identified, what happens when half the rows fail. Record the decisions, and update the SRS or backlog if you make a requirement-level choice (for example, “a partially valid file imports its valid rows”).

3. Tests First, From the Acceptance Criteria

Turn the criteria into tests before writing implementation. The tests are your executable definition of “correct,” and the assistant can then iterate against something objective.

1
2
3
4
5
6
7
8
9
10
11
12
def test_rows_with_empty_body_are_rejected_and_valid_rows_import():
    csv_text = (
        "body,source,date\n"
        "Search is slow,email,2026-11-02\n"
        ",email,2026-11-03\n"          # empty body
    )
    result = import_feedback(workspace_id=WS_A, csv_text=csv_text)

    assert result.imported == 1
    assert result.rejected == 1
    assert result.errors[0].code == "MISSING_BODY"
    assert result.errors[0].row_number == 3   # header is row 1

Ask the assistant to propose tests for the criteria, then review them: do they express the requirement, or just the implementation it has in mind? Add the cases it missed: empty file, header only, very long body, unexpected columns, mixed encodings, a date in an unexpected format.

Run the tests and confirm they fail for the right reason before implementing.

4. Implement in Small Steps

Work from the smallest piece outward: the pure validation function, then the parser, then the service that writes to the repository, then the API endpoint.

1
2
3
4
5
6
7
8
9
10
Implement only `validate_row` in `imports/validation.py` so that the
failing tests in `tests/unit/test_validation.py` pass.

Constraints:
- Pure function: no I/O, no database access.
- Return a ValidationResult; do not raise for invalid data.
- No new dependencies.
- Do not modify tests.

Show me the diff, and list any assumptions you made.

After each step: run the tests, read the diff, stage with git add -p, and commit. The sequence of small commits is also your audit trail.

5. Duplicate Handling and Idempotency

FR-IMP-04 requires that re-uploading a file does not duplicate data. This is a design decision, not a coding detail. A common approach is to compute a content fingerprint per row (for example, a hash of workspace, normalized body, source, and date) and enforce uniqueness in the database:

1
2
ALTER TABLE feedback_item
  ADD CONSTRAINT uq_feedback_fingerprint UNIQUE (workspace_id, fingerprint);

The service then inserts rows and treats a uniqueness conflict as “already imported.” Enforcing the rule in the database, not just in application code, protects against races, such as two uploads at the same time. Ask the assistant for alternatives and their trade-offs, then decide.

6. Review What the Assistant Produced

Generated code often passes the obvious tests and fails elsewhere. Review deliberately:

Area Questions
Correctness Does it satisfy every acceptance criterion, including edge cases?
Error handling Are failures reported clearly? Are exceptions swallowed or too broad?
Security Is input validated? Are size limits enforced? Is the tenant filter applied on every query? Is user text ever concatenated into SQL or logged?
Performance Does it load the whole file into memory? Does it do one query per row?
Design fit Does it follow module boundaries and project conventions?
Simplicity Is there unneeded abstraction, dead code, or duplicated logic?
Observability Are failures logged without leaking personal data?

For a 50,000-row file, “one insert per row, in a loop, inside a request” may pass your small tests and still time out. Test with realistic sizes, and move heavy work to the background worker as the architecture intends.

7. When to Discard and Restart

Patching bad output costs more than it seems. Discard and restart with a better prompt when:

  • The assistant misunderstood the task, and each correction makes the code more tangled.
  • The diff is far larger than the task warranted.
  • You do not understand the approach and cannot explain it.
  • Tests pass only because the assistant weakened or deleted them.

With a clean branch and small commits, discarding is cheap. Add what you learned to the instruction file or prompt, then try again with a smaller step.

8. Practical Exercise

Implement slice 1 for SignalDesk (or an equivalent slice in your project):

  1. Write the slice definition with requirement traceability and the decisions you made.
  2. Get a plan from the assistant and record at least one change you made to it.
  3. Write the tests first (from the criteria, plus your own edge cases) and confirm they fail correctly.
  4. Implement in steps: validation, parsing, service, API endpoint. Commit after each step.
  5. Review the final result with the table above and record at least three findings, whether fixed or accepted with a reason.
  6. Run the slice manually through the real API with a realistic file, and record what you saw.

Verification

You are ready to continue when:

  • Every acceptance criterion has at least one passing test, and no test was weakened to pass.
  • The slice works through the real interface, not only in unit tests.
  • Duplicate handling is enforced at the database level.
  • You can explain every part of the code that was merged.
  • The review findings are recorded.

Key Takeaways

  • Build thin vertical slices; they deliver usable value and expose integration risk early.
  • Turn acceptance criteria into tests before implementation.
  • Work in small steps: plan, test, implement, verify, review, commit.
  • Generated code that passes simple tests can still fail on scale, security, and design fit.
  • Discarding output is a normal, cheap tool when work is in small commits.

What’s Next?

The first slice touched only the surface of data, APIs, and background processing. Next, we go deeper on those: migrations, API contracts, tenant isolation, and reliable background jobs.