Sub topic 7
Break larger tasks into steps
A single prompt works well when the task fits in one function. Larger tasks, such as "add CSV export to the reporting tool", fail in a different way. The assistant has to guess the design, the file layout, and the edge cases all at once, and each guess can be wrong. This chapter shows how to split a large task into smaller prompts that you can check one at a time.
This chapter assumes you can already write a prompt with a goal, context, and constraints, and that you can run tests in your own project.
Why one big prompt fails
A large prompt gives the assistant many decisions to make silently. Three problems follow.
- Hidden choices. The assistant picks a data structure, a library, or an error policy without telling you. You find out only when you read the whole result.
- Hard review. A 300-line response mixes correct and incorrect parts. A bug is harder to locate, and a fix to one part can break another.
- Lost constraints. The more a prompt asks for, the more likely one constraint gets ignored.
Smaller steps give you a checkpoint after each response. If step two is wrong, you correct step two and do not redo everything.
How to split a task
Split by outcome, not by size. Each step should have its own testable goal, as described in the chapter on goals. Good boundaries are usually:
- Data and types. Define the inputs and outputs first.
- Pure logic. Write the core function that has no file, network, or database access.
- Edge cases. Add handling for empty input, bad values, and limits.
- Wiring. Connect the logic to the command line, web route, or file system.
- Tests. Cover the behavior, or write them earlier to define it.
A useful rule is that you can describe each step in one sentence and check it by running something.
A worked example
Suppose you want a command-line tool that reads a log file and prints the number of errors per hour. Asked in one prompt, the assistant must decide the log format, the parsing, the grouping, and the output. Split it instead.
Step 1: fix the data.
Task: Define the data for a log-summary tool.
Context: Python 3.10. Each log line looks like "2026-11-27 13:05:12 ERROR Disk full".
Constraints: standard library only; write no parsing code yet.
Output format: only a dataclass named LogEntry with fields timestamp (datetime), level (str), message (str).Step 2: write the pure logic. Paste the LogEntry you accepted into the next prompt, so the assistant sees it.
Task: Write parse_line(line: str) -> LogEntry | None.
Context: Python 3.10. Use this dataclass: <paste LogEntry>.
Constraints: standard library only; return None for lines that do not match the format; do not read files.
Examples:
parse_line("2026-11-27 13:05:12 ERROR Disk full") -> LogEntry(datetime(2026, 11, 27, 13, 5, 12), "ERROR", "Disk full")
parse_line("not a log line") -> None
Output format: only the function.Step 3: add the grouping.
Task: Write errors_per_hour(entries: list[LogEntry]) -> dict[str, int].
Context: Python 3.10, using the LogEntry dataclass and parse_line from the previous steps.
Constraints: count only entries whose level is "ERROR"; keys have the form "2026-11-27 13:00".
Output format: only the function.Step 4: wire it up. Only now do you ask for the main() function that opens the file and prints the result.
After each step you run the code. Here is a quick check for step 3:
from datetime import datetime
from log_summary import LogEntry, errors_per_hour
entries = [
LogEntry(datetime(2026, 11, 27, 13, 5), "ERROR", "Disk full"),
LogEntry(datetime(2026, 11, 27, 13, 40), "ERROR", "Timeout"),
LogEntry(datetime(2026, 11, 27, 13, 41), "INFO", "Retry"),
]
assert errors_per_hour(entries) == {"2026-11-27 13:00": 2}
print("ok")If the assertion fails, you know the fault is in step 3, because steps 1 and 2 already passed their checks.
Keeping steps connected
Splitting only works if each step carries forward what the assistant needs.
- Paste accepted code. The assistant does not reliably remember earlier work, so include the signatures or code it must use.
- Repeat key constraints. State the Python version and library limits again in each prompt.
- Name the next step. Saying "do not write the file-reading code yet" stops the assistant from jumping ahead.
Another useful move is to ask for a plan first. Prompt: "List the steps to build this tool. Do not write code." Review the list, fix it, and then work through it one step at a time.
Exercise
Exercise
You ask an assistant for "a script that downloads a web page, extracts all links, removes duplicates, and saves them to a CSV file". The result is 120 lines and one link is saved incorrectly. Split this into steps, and say which step you would check first for the bug.
Show answer
One possible split: (1) write a function that takes HTML text and returns a list of links, with no network access; (2) write a function that removes duplicates while keeping order; (3) write a function that writes a list of links to CSV; (4) write the download and main function that connects them. A link saved incorrectly most likely comes from step 1 (extraction) or step 3 (CSV writing). Check step 1 first by passing it a small HTML string with known links and comparing the output, because it has no network or file dependencies and is the cheapest to test.