Sub topic 11
Building projects with clear AI boundaries
This chapter assumes you can write functions, conditionals and loops in Python, run a script and a simple test from a terminal, and have used a chat-based AI assistant. It also assumes you know the attempt-first workflow, the three AI roles (tutor, reviewer, generator) and how to check AI code with your own tests. Here you apply them to a whole project.
Why projects need explicit boundaries
Small exercises have a natural limit. You finish one function, check it, and move on. A project has no such limit. It has dozens of decisions, many files, and long stretches where asking the AI "just do this part" looks efficient. Without a rule set in advance, you will make that choice dozens of times while tired or stuck, and the answer will usually be "let the AI do it."
An AI boundary is a rule you write before you start that says which parts of the project the AI may touch, in which role, and which parts you must do yourself. The rule is made when you are calm, not in the middle of a bug.
Boundaries matter more in projects for three reasons:
- Skill gaps hide. A project can work while you do not understand half of it. The gaps show up later, when you extend or debug it.
- Errors compound. A wrong assumption in a generated module becomes the base for the next three modules.
- You own the result. Someone will ask why the code works this way. "The AI wrote it" is not an answer you can build on.
Sorting the work: learn, support and delegate
Not every task in a project teaches the same amount. Sort the tasks before you begin.
| Category | What it means | AI role allowed | Examples |
|---|---|---|---|
| Learn | The skill you are trying to build. | Tutor and reviewer only. You write the code. | Core logic, the data structures you are studying, the algorithm at the heart of the project. |
| Support | Needed, but not the learning target. | Generator, with your reading and tests. | Argument parsing, formatting output, config loading. |
| Delegate | Routine work with no learning value for you now. | Generator, with a quick check. | Boilerplate, a README template, repetitive test data. |
The categories depend on your goal, not on the task. A command-line parser is "support" in a project about text processing. It is "learn" if you are studying how to build command-line tools. Decide per project and write it down.
A good default: the part of the project that made you choose it is "learn." If you picked a to-do tracker to practice working with files and data, the code that stores and updates tasks is yours.
Write a boundary document
Before the first line of code, write a short plain-text file in the project folder. It takes ten minutes and replaces many in-the-moment decisions.
PROJECT: command-line expense tracker
GOAL: practice file handling, dictionaries and writing tests
LEARN (I write it, AI may only ask questions, give hints, review):
- reading and writing the expenses file
- the summarize() function that totals by category
SUPPORT (AI may generate; I read every line and write tests first):
- argument parsing
- date formatting
DELEGATE (AI may generate; I run it and skim it):
- README skeleton
- sample data for tests
RULES:
- Every function gets at least one test I wrote myself.
- If I have been stuck for more than 30 minutes, I ask for a hint, not a solution.
- I explain each AI-generated function aloud or in a comment before committing it.Keep this file in version control next to the code. You can revise it, and the history shows how your boundaries changed. That history feeds the later chapters on reducing support and tracking progress.
Break the project into slices
A boundary only works if the units of work are small enough to apply it to. Split the project into slices. A slice is a piece you can finish, run and test in one session, usually under two hours.
For the expense tracker, slices might be:
- Store one expense in a file and read it back.
- List all expenses.
- Summarize totals by category.
- Add command-line arguments.
- Handle bad input and missing files.
Each slice goes through the same loop. This gives a repeatable rhythm and keeps AI use tied to a specific step.
A worked slice
Take slice 3, the summary of totals by category. The boundary document says this is a "learn" slice, so you write it first.
Suppose your attempt looks like this:
def summarize(expenses):
totals = {}
for item in expenses:
category = item["category"]
totals[category] = totals[category] + item["amount"]
return totals
expenses = [
{"category": "food", "amount": 12.5},
{"category": "food", "amount": 7.5},
{"category": "travel", "amount": 30.0},
]
print(summarize(expenses))Running it raises KeyError: 'food'. Your attempt is done, and you are stuck. This is the right moment for the tutor role. Use the prompt pattern from the earlier chapter:
I am learning Python. I wrote summarize() to total expenses by category. My code is below and it raises KeyError: 'food' on the first item.
<paste your code and the error>
Do not give me the full solution. First, ask me one question that helps me find the problem. If I am still stuck, give a hint. After I fix it, review my code and tell me what to improve.A good tutor reply asks what value totals["food"] has the first time the loop sees a food item. You realize the key does not exist yet. You fix it yourself:
def summarize(expenses):
totals = {}
for item in expenses:
category = item["category"]
totals[category] = totals.get(category, 0) + item["amount"]
return totals
expenses = [
{"category": "food", "amount": 12.5},
{"category": "food", "amount": 7.5},
{"category": "travel", "amount": 30.0},
]
print(summarize(expenses))This prints {'food': 20.0, 'travel': 30.0}. Now you ask for review. The AI may suggest collections.defaultdict or point out that an empty list returns an empty dictionary. You decide which suggestions to take, and you add a test for the empty case.
Compare this with asking the AI to write summarize() at the start. You would have the same working function in seconds, and you would have missed the lesson that a dictionary key must exist before you read it.
Handling a support slice
Slice 4 (command-line arguments) is a "support" slice. The rule is: write tests first, then generate, then read.
A test for the behavior you want, before any generated code exists:
def test_parse_add_command():
result = parse_args(["add", "food", "12.5"])
assert result == {"command": "add", "category": "food", "amount": 12.5}
def test_parse_summary_command():
result = parse_args(["summary"])
assert result == {"command": "summary"}You then ask the AI for a parse_args function that satisfies these tests, using the standard library. When the code arrives, apply the reading checklist from the earlier chapter: What does each line do? Which library functions does it call, and do they exist? What happens with a missing argument or a non-numeric amount? Write those missing cases as extra tests. If you cannot explain a line, either ask the AI to explain it or replace it with something you do understand.
Boundary violations and how to recover
You will break your own rules. Treat that as information, not failure.
Common violations:
- Slow drift. A hint becomes a bigger hint, then a pasted solution. Watch for the moment you stop typing and only paste.
- Scope creep in the prompt. "Fix this bug" becomes "rewrite this file." Keep each request to one function or one question.
- Generated code you do not understand, already merged. This is the most costly one.
Recovery steps for the last case:
- Stop adding new code on top of it.
- Write tests that describe what the code should do.
- Read it line by line, adding a comment on each block in your own words.
- If you cannot, delete it and rewrite that part as a "learn" slice.
Note the violation in the boundary document. If the same category of task keeps being violated, move it to a different category or tighten the rule.
Using version control as a boundary tool
Version control gives you a record you can audit.
- Make a commit before each AI-assisted change and another after you have read and tested it.
- Use commit messages that say who wrote what, for example
summarize: written by me, reviewed by AIorparse_args: generated, tests added. - Read the diff before you commit. If the diff includes files you did not intend to change, undo it.
This habit costs a few seconds and gives you evidence for the progress review at the end of the tutorial.
Choosing projects that suit boundaries
Some projects are easier to bound than others.
- Good fits: small tools with a clear input and output, such as a text-statistics script, a flashcard quiz, a file organizer or a simple API client. They split cleanly into slices.
- Harder fits: projects built on large frameworks, where much of the work is configuration you have not learned yet. Here, treat setup as "support" and the first piece of your own logic as "learn."
- Poor fits: projects with a goal so large that no slice is understandable on its own. Reduce the scope until you can hold the whole design in your head.
A useful size test: can you explain the whole project's data flow on one sheet of paper without looking at the code? If not, the project is too big for now, or too much of it was generated.
Review the boundaries at the end
When the project is done, spend fifteen minutes on a retrospective:
- Which "learn" slices did you complete without a solution from the AI?
- Which "support" slices turned out to be learning targets after all?
- How many times did you break a rule, and where?
- Can you rebuild one "learn" slice from a blank file without AI help?
The last question is the real test, and it leads into the next chapter on gradually reducing support. Pick one slice and redo it unaided next week.
Exercise
You are building a flashcard quiz program to practice reading files and using lists and dictionaries. Write a boundary document with at least one item each under learn, support and delegate, and give one reason for each choice. Then say what you would do if you were stuck on the "learn" part for 45 minutes.
Show answer
A sample answer. Learn: loading cards from a file into a list of dictionaries and picking random cards, because file handling and data structures are the stated goal. Support: the scoring display and command-line menu, because they are needed but are not the skill you are practicing; the AI may generate them if you write tests first and read each line. Delegate: the README and a sample cards file, because they have no learning value for you right now. If stuck for 45 minutes on the learn part, ask the AI in the tutor role for a single guiding question, then a hint if needed. Do not ask for the full solution. Afterward, rewrite the failing part yourself and add a test for the case that tripped you up.
Exercise
A generated function parse_args was merged into your project last week. It passes your one test, but you cannot explain how it handles a non-numeric amount. List the recovery steps you would take.
Show answer
Stop building on top of it. Write tests that describe the expected behavior, including parse_args(["add", "food", "abc"]), and decide what should happen (for example, an error message). Run them to see what the function actually does. Read the function line by line and write a comment on each block in your own words. If a part still makes no sense, ask the AI to explain it, or delete it and rewrite it yourself. Record the violation in the boundary document.