Skip to content

Module 05 · Lesson 5.3

Directing an Assistant on a Bounded Task

45 minUpdated 19 Nov 2026Part of Implementing Changes in an Existing Codebase · Existing Project Engineering
On this page
  1. What you will learn
  2. What a bounded task is, and why it works
  3. Worked scenario: briefing the assistant for the minimum order rule
  4. Step-by-step workflow
  5. Reviewing the diff line by line
  6. Recording what you accepted, changed and rejected
  7. Conclusion and your next step
  8. Reusable prompt
  9. Expected output
  10. Common errors and fixes
  11. Validation checklist
  12. Hands-on exercise
  13. Knowledge check
  14. Frequently asked questions
  15. References

Think of an AI coding assistant as a very fast new colleague who has never seen your project. If you say 'improve the order code', they will happily rewrite half of it. If you say 'add this one check, in these three files, and show me only the diff', they can do good work. The narrower the job, the safer the result.

In this lesson you write a bounded task brief for the minimum order value rule from Planning a Small Change, and review the diff that comes back. The example uses the fictional Tidewell Wholesale. The company and data are invented, and the assistant's reply is an illustration written for this lesson.

What you will learn

  • Write a brief with a file list, rules, acceptance criteria and an output format.
  • Review an assistant's diff hunk by hunk and mark each one accept, change or reject.
  • Catch an out-of-scope edit and a missing criterion, using the diff and your tests.
  • Record what the assistant produced and what you changed, for the pull request.

Before you start

What a bounded task is, and why it works

A bounded task is a job with a clear edge. It names what to change, what not to change, and how you will know it is right. The edge is what lets you check the work. If the assistant may change anything, you must check everything.

AI coding assistant
A tool that reads your instructions and the code you give it, then suggests changes. It writes fluently, but it only knows what you pasted, like a colleague on their first day.
Constraint
A rule the answer must obey, such as 'no new dependencies'. Constraints are the fence round the job.
Unified diff
A standard text layout for changes. Lines starting with a minus sign were removed and lines starting with a plus sign were added. It is easy to review one hunk at a time.
Hunk
One block of changed lines inside a diff, with a few unchanged lines around it for context. Think of it as one paragraph of edits.

Asking for the diff only has a second benefit. You cannot be talked into a change by a fluent explanation, because there is no explanation to read. You see the lines, and you judge the lines.

Worked scenario: briefing the assistant for the minimum order rule

You already have the criteria, the conventions and seven failing tests. Now you hand the narrow part to an assistant. The brief has six parts: the goal, the files it may change, the files it must not change, the rules, the criteria, and the output format. You also paste the real source it needs. This is a simplified version of the service's code, so you can run it without Django.

Texttask-brief.txt
Task: add a minimum order value rule to create_order in a Python service. Work only on the files listed below.

Files you may change:
- orders/services.py
- orders/messages.py
- tests/orders/test_services.py (add tests only)

Files you must NOT change: everything else, including invoicing/totals.py and api/views.py.

Rules for the change:
- No new dependencies, classes or helper modules.
- Follow the existing pattern: raise OrderRejected(code, message). Message text goes in orders/messages.py as a constant.
- No formatting changes and no renaming. Do not touch lines unrelated to the rule.
- Put the check after price_order and before the order is saved.
- Add a keyword argument min_order_sources (a set of source names). An empty set means the rule is off.

Acceptance criteria (agreed with the sales operations manager). "Goods total" is before VAT and delivery.
C1 A Standard-band customer (band compared ignoring letter case) whose goods total is below 75.00 is rejected with the code below_minimum, for the sources portal and edi.
C2 The source replay is exempt.
C3 Volume and Contract bands are not affected.
C4 Exactly 75.00 is accepted.
C5 A rejected order saves nothing and queues no confirmation.
C6 Portal message: "Orders on a Standard account must be at least £75.00 before VAT and delivery. Your basket is £62.40." (basket filled in).
C7 EDI rejections are logged with the account code and no personal data.

Material: the current source of orders/services.py, orders/messages.py and the test fixtures follows.
(paste source)

Output: show the diff only, in unified diff format. Then list every assumption you made. Do not describe code you did not change.

The brief. The line (paste source) stands for the code you paste.

The assistant answers with a diff. Here it is, with git diff --stat first. The diff itself is an illustration, written to show typical mistakes. The commands and test runs after it are real.

git diff --stat for the assistant's change (illustrative reply, real command)Illustrative — your output will differ
invoicing/totals.py |  2 +-
orders/messages.py  |  4 ++++
orders/services.py  | 27 ++++++++++++++++++++++++++-
3 files changed, 31 insertions(+), 2 deletions(-)

Already there is a surprise. You listed two source files, but the stat shows three. invoicing/totals.py was on the 'must NOT change' list. Stop and read that one first.

The assistant's diff (illustrative)Illustrative — your output will differ
diff --git a/invoicing/totals.py b/invoicing/totals.py
index 2a9d071..43e9ca8 100644
--- a/invoicing/totals.py
+++ b/invoicing/totals.py
@@ -7,6 +7,6 @@ FREE_DELIVERY_FROM = Decimal("50.00")
 def price_order(lines, band):
     goods = sum((line.qty * line.unit_price for line in lines), Decimal("0"))
     delivery = Decimal("0.00")
-    if band == "Standard" and goods < FREE_DELIVERY_FROM:
+    if band.lower() == "standard" and goods < FREE_DELIVERY_FROM:
         delivery = DELIVERY_CHARGE
     return {"goods": goods, "delivery": delivery}
diff --git a/orders/messages.py b/orders/messages.py
index d9ba70a..923ed2c 100644
--- a/orders/messages.py
+++ b/orders/messages.py
@@ -1 +1,5 @@
 OUT_OF_STOCK = "Sorry, {sku} is out of stock."
+BELOW_MINIMUM = (
+    "Orders on a Standard account must be at least £{minimum} "
+    "before VAT and delivery. Your basket is £{basket}."
+)
diff --git a/orders/services.py b/orders/services.py
index 8639bda..4d2d817 100644
--- a/orders/services.py
+++ b/orders/services.py
@@ -1,6 +1,13 @@
+import logging
+from decimal import Decimal
+
 from invoicing.totals import price_order
 from orders import messages
 
+MIN_ORDER_VALUE = Decimal("75.00")
+
+logger = logging.getLogger("orders")
+
 
 class OrderRejected(Exception):
     """Raised when an order must not be created. The portal shows `message`."""
@@ -11,7 +18,9 @@ class OrderRejected(Exception):
         self.message = message
 
 
-def create_order(customer, lines, source, *, stock, store):
+def create_order(
+    customer, lines, source, *, stock, store, min_order_sources=frozenset()
+):
     for line in lines:
         if stock.get(line.sku, 0) < line.qty:
             raise OrderRejected(
@@ -21,6 +30,22 @@ def create_order(customer, lines, source, *, stock, store):
 
     totals = price_order(lines, customer.band)
 
+    if (
+        min_order_sources
+        and customer.band.lower() == "standard"
+        and totals["goods"] < MIN_ORDER_VALUE
+    ):
+        if source == "edi":
+            logger.warning(
+                "Rejected EDI order below minimum: account=%s", customer.account
+            )
+        raise OrderRejected(
+            "below_minimum",
+            messages.BELOW_MINIMUM.format(
+                minimum=MIN_ORDER_VALUE, basket=f"{totals['goods']:.2f}"
+            ),
+        )
+
     order = store.save(
         {"account": customer.account, "source": source, "goods": totals["goods"]}
     )

Step-by-step workflow

  1. Step 1: Choose a task that fits in one diff

    Pick a piece of the plan that touches a few files. If it needs a whole redesign, it is not bounded yet. Split it.

    What you should see: One task with a list of files.

  2. Step 2: Write the brief

    State the goal, the files it may change, the files it must not change, the rules, the acceptance criteria and the output format. Keep it to one page.

    What you should see: A brief you could hand to a person.

  3. Step 3: Paste only what it needs

    Include the source of the functions to change and one example of each convention. Remove secrets and personal data first.

    What you should see: A short, safe context block.

  4. Step 4: Ask for the diff only

    Ask for a unified diff and a list of assumptions. Ask it to say nothing about code it did not change.

    What you should see: A diff you can apply or read.

  5. Step 5: Check the file list first

    Run git diff --stat. Compare it with your list. Any extra file is a finding before you read a single line.

    What you should see: Either 'same files' or a list of extra files.

  6. Step 6: Review each hunk and run the tests

    Mark each hunk accept, change or reject. Then run the full test suite, not only the new tests.

    What you should see: A table of hunk verdicts and a test run.

  7. Step 7: Record the outcome

    Write down what was generated, what you changed and what you rejected, with a reason for each. This goes into the pull request.

    What you should see: A short assistant-use note.

A bounded task with a review gate
  1. Brief

    Files, rules, criteria

  2. Assistant

    Returns a diff

  3. Stat check

    Same files as listed?

  4. Hunk review

    Accept, change or reject

  5. Full tests

    Whole suite

  6. Record

    What you changed

Nothing is merged until each hunk has a verdict and the tests pass.

Reviewing the diff line by line

Go hunk by hunk. For each one ask three questions. Was I allowed to expect this? Does it meet a criterion? Could it break a caller I have not tested? Here is the review of the diff above.

HunkVerdictReason
invoicing/totals.py: band.lower() == "standard"RejectOut of scope and on the 'must NOT change' list. It changes who pays delivery, which is a finance decision. The old behaviour is pinned by a test.
orders/messages.py: BELOW_MINIMUMAcceptMatches the criterion text and the existing constant style.
orders/services.py: new argument min_order_sourcesAcceptAs asked, with an empty set meaning off.
orders/services.py: if min_order_sources and ...ChangeTests whether the set is non-empty, not whether this order's source is in it. So the replay source is not exempt and the EDI source is hit in stage one.
orders/services.py: EDI log lineAcceptLogs the account code only.
Five changes, three verdicts.

Reading found the first problem by itself, because of the file list. The second problem is easy to miss when reading. It looks fine. This is where your tests earn their keep. Run the whole suite on the assistant's version.

pytest on the assistant's version (real run; timings vary)Captured from a real run
.F.....F.......F                                                         [100%]
================================== FAILURES ===================================
___ test_lowercase_standard_band_gets_no_delivery_charge_CURRENT_BEHAVIOUR ____
tests\invoicing\test_totals.py:16: in test_lowercase_standard_band_gets_no_delivery_charge_CURRENT_BEHAVIOUR
    assert price_order([line(10, "1.25")], "standard")["delivery"] == Decimal("0.00")
E   AssertionError: assert Decimal('7.50') == Decimal('0.00')
E    +  where Decimal('0.00') = Decimal('0.00')
________________________ test_replay_orders_are_exempt ________________________
tests\orders\test_services.py:104: in test_replay_orders_are_exempt
    create_order(
orders\services.py:42: in create_order
    raise OrderRejected(
E   orders.services.OrderRejected: Orders on a Standard account must be at least £75.00 before VAT and delivery. Your basket is £62.40.
___________________ test_stage_one_enables_the_portal_only ____________________
tests\orders\test_services.py:184: in test_stage_one_enables_the_portal_only
    create_order(
orders\services.py:42: in create_order
    raise OrderRejected(
E   orders.services.OrderRejected: Orders on a Standard account must be at least £75.00 before VAT and delivery. Your basket is £62.40.
------------------------------ Captured log call ------------------------------
WARNING  orders:services.py:39 Rejected EDI order below minimum: account=TS1-0310
=========================== short test summary info ===========================
FAILED tests/invoicing/test_totals.py::test_lowercase_standard_band_gets_no_delivery_charge_CURRENT_BEHAVIOUR
FAILED tests/orders/test_services.py::test_replay_orders_are_exempt - orders....
FAILED tests/orders/test_services.py::test_stage_one_enables_the_portal_only
3 failed, 13 passed in Xs
  • The first failure is an existing test, test_lowercase_standard_band_gets_no_delivery_charge_CURRENT_BEHAVIOUR. It was written to pin the old behaviour, and it noticed the quiet edit to price_order.
  • The second is test_replay_orders_are_exempt. The criterion C2 was missed: replay orders are rejected.
  • The third is test_stage_one_enables_the_portal_only. With only the portal switched on, an EDI order was still rejected. The same wrong condition caused it.

Reject one hunk, change another

You do not ask for the diff again with a longer brief. For one rejected hunk and one line to correct, doing it by hand is quicker and safer. First undo the edit to invoicing/totals.py, then run the tests again.

After rejecting the edit to invoicing/totals.py (real run)Captured from a real run
.......F.......F                                                         [100%]
================================== FAILURES ===================================
________________________ test_replay_orders_are_exempt ________________________
tests\orders\test_services.py:104: in test_replay_orders_are_exempt
    create_order(
orders\services.py:42: in create_order
    raise OrderRejected(
E   orders.services.OrderRejected: Orders on a Standard account must be at least £75.00 before VAT and delivery. Your basket is £62.40.
___________________ test_stage_one_enables_the_portal_only ____________________
tests\orders\test_services.py:184: in test_stage_one_enables_the_portal_only
    create_order(
orders\services.py:42: in create_order
    raise OrderRejected(
E   orders.services.OrderRejected: Orders on a Standard account must be at least £75.00 before VAT and delivery. Your basket is £62.40.
------------------------------ Captured log call ------------------------------
WARNING  orders:services.py:39 Rejected EDI order below minimum: account=TS1-0310
=========================== short test summary info ===========================
FAILED tests/orders/test_services.py::test_replay_orders_are_exempt - orders....
FAILED tests/orders/test_services.py::test_stage_one_enables_the_portal_only
2 failed, 14 passed in 0.07s

The old test passes again. Two failures remain, and both come from the condition. This is the change, as a real diff between the assistant's file and the reviewed file.

The correction to orders/services.py (real diff)Captured from a real run
--- orders/services.py (assistant)
+++ orders/services.py (after review)
@@ -5,6 +5,7 @@
 from orders import messages
 
 MIN_ORDER_VALUE = Decimal("75.00")
+EXEMPT_SOURCES = frozenset({"replay"})
 
 logger = logging.getLogger("orders")
 
@@ -31,7 +32,8 @@
     totals = price_order(lines, customer.band)
 
     if (
-        min_order_sources
+        source in min_order_sources
+        and source not in EXEMPT_SOURCES
         and customer.band.lower() == "standard"
         and totals["goods"] < MIN_ORDER_VALUE
     ):
pytest after the correction (real run)Captured from a real run
................                                                         [100%]
16 passed in 0.07s

Recording what you accepted, changed and rejected

Write the outcome while you remember it. It takes five minutes and saves the reviewer an hour. It also helps you spot a pattern, such as 'this assistant keeps touching files outside the list'.

Markdownassistant-use-note.md
**Assistant use**
- Generated: the first version of the rule, the BELOW_MINIMUM message, the EDI log line and the new argument.
- Accepted as written: the message, the argument and the log line.
- Changed by me: the condition now checks that the order's source is in min_order_sources and is not replay. The generated version tested only whether the set was empty.
- Rejected: an edit to invoicing/totals.py that made the band check ignore letter case. It is out of scope and changes delivery charges. Raised as a separate question for the finance systems contact.
- Checked by: the full test suite (16 tests), and a read of every hunk.

A note for the pull request. The wording is an example.

When to stop asking and do it yourself

  • The second reply still touches files outside the list.
  • You spend longer explaining the fix than writing it.
  • The assistant keeps arguing for a change you already rejected.
  • The change needs knowledge that is not in the code, such as a business rule.

Using an assistant is a way to save typing, not a way to share responsibility. You own every line you commit.

Conclusion and your next step

A narrow brief gave you a diff you could check. The file list exposed one edit you never asked for, and the tests exposed a missing exemption. You rejected the first, fixed the second by hand, and wrote down what happened.

Your next step: the rule is correct, but it should not reach every customer at once. Continue with Feature Flags and Staged Rollout to switch it on in stages and to switch it off again if needed.

Further reading: the Giving AI Coding Assistants Useful Context guide, and the blog post How to Prevent AI Hallucinations in Code Generation.

Reusable prompt

Bounded change brief

Gives an assistant one narrow job with a file list, rules and acceptance criteria, and asks for the diff only.

Task: add a minimum order value rule to create_order in a Python service. Work only on the files listed below.

Files you may change:
- orders/services.py
- orders/messages.py
- tests/orders/test_services.py (add tests only)

Files you must NOT change: everything else, including invoicing/totals.py and api/views.py.

Rules for the change:
- No new dependencies, classes or helper modules.
- Follow the existing pattern: raise OrderRejected(code, message). Message text goes in orders/messages.py as a constant.
- No formatting changes and no renaming. Do not touch lines unrelated to the rule.
- Put the check after price_order and before the order is saved.
- Add a keyword argument min_order_sources (a set of source names). An empty set means the rule is off.

Acceptance criteria (agreed with the sales operations manager). "Goods total" is before VAT and delivery.
C1 A Standard-band customer (band compared ignoring letter case) whose goods total is below 75.00 is rejected with the code below_minimum, for the sources portal and edi.
C2 The source replay is exempt.
C3 Volume and Contract bands are not affected.
C4 Exactly 75.00 is accepted.
C5 A rejected order saves nothing and queues no confirmation.
C6 Portal message: "Orders on a Standard account must be at least £75.00 before VAT and delivery. Your basket is £62.40." (basket filled in).
C7 EDI rejections are logged with the account code and no personal data.

Material: the current source of orders/services.py, orders/messages.py and the test fixtures follows.
(paste source)

Output: show the diff only, in unified diff format. Then list every assumption you made. Do not describe code you did not change.
Show the reusable template

Replace each {{placeholder}} with your own details.

Task: {{one_sentence_task}}. Work only on the files listed below.

Files you may change:
{{files_you_may_change}}

Files you must NOT change: everything else{{named_files_to_protect}}.

Rules for the change:
- No new dependencies, classes or helper modules.
- Follow the existing pattern: {{pattern_to_copy}}.
- No formatting changes and no renaming. Do not touch lines unrelated to the change.
- {{where_the_change_goes}}

Acceptance criteria (agreed with {{role_who_agreed}}):
{{criteria}}

Material: the current source of the files follows.
{{pasted_source}}

Output: show the diff only, in unified diff format. Then list every assumption you made. Do not describe code you did not change.

Expected output and limitations

A unified diff touching only the listed files, followed by a short list of assumptions. Nothing else: no summary of the code, no tutorial, no changes to files you did not name.

Sample responseIllustrative — your output will differ
diff --git a/orders/messages.py b/orders/messages.py
--- a/orders/messages.py
+++ b/orders/messages.py
@@ -1 +1,5 @@
 OUT_OF_STOCK = "Sorry, {sku} is out of stock."
+BELOW_MINIMUM = (
+    "Orders on a Standard account must be at least £{minimum} "
+    "before VAT and delivery. Your basket is £{basket}."
+)

(more hunks for orders/services.py and the tests)

Assumptions
- The goods total is the value returned by price_order under the key "goods".
- A source name that is not in min_order_sources is never checked.

Limitations to keep in mind

  • The diff may touch files you did not list, or edit lines nobody asked about. Check the file list first.
  • The assistant cannot see callers or tests you did not paste, so a missing criterion may look complete.
  • Assumptions it lists are guesses. Each one is a question for a person.
  • A passing test run covers only what your tests cover. Read the hunks as well.

Common errors and how to fix them

An open-ended request such as 'add the rule and tidy up'

Why it happens: Nothing limits what the assistant may change, so it changes whatever looks improvable.

Fix: List the files it may change and the files it must not. Say 'do not touch unrelated lines' and ask for the diff only.

Reading the explanation instead of the diff

Why it happens: A clear explanation feels like proof that the code is right.

Fix: Ask for the diff only. Review hunks, run the whole suite and treat every assumption as a question.

Merging an assistant's edit that happens to pass the tests

Why it happens: No test covered the out-of-scope change, so nothing failed.

Fix: Compare the changed files with your list before you read the code, and reject any file you did not ask for.

Validation checklist

Tick each item once you have confirmed it.

Hands-on exercise

Brief an assistant and review its diff

Take the plan and failing tests you made in the first lesson of this module. Write a bounded brief, ask an assistant for the diff, and review it hunk by hunk. Write the assistant-use note.

You will need

  • Your acceptance criteria, failing tests and edit list.
  • A repository you may share with your assistant, with secrets removed.
  • The brief template from this lesson.

Acceptance criteria

Your work is done when every one of these is true.

Hints (3)
  • If the assistant returns no mistakes, look harder at what it left out. Compare the diff with each criterion.
  • If you have no assistant, ask a colleague to play the part, and give them only the brief.
  • Run git diff --stat before reading the diff. It takes five seconds.
Show a model answer

A strong answer shows the brief and the diff stat side by side. It notices any file outside the list before reading code, then goes hunk by hunk with a verdict for each. It names at least one thing that was easy to miss, such as a condition that tests the wrong thing, and shows the test that caught it. It runs the full suite, not only the new tests. Its note says plainly what was generated, changed and rejected, and why. A weak answer says 'the assistant did a good job', shows no verdicts and does not mention the files in the diff.

Knowledge check

Choose an answer, then check it. Nothing is recorded — this is for you.

  1. 1.The assistant's diff touches three files, but you listed two. What do you do first?
    Show the answer and explanation

    Answer: B. An extra file is outside the agreed edge, so the default is to reject it unless it is needed and you agree. Passing tests are tempting evidence, but a test only covers what someone thought to test. A fluent reason or a new test does not make the change in scope.

  2. 2.Why ask for 'the diff only'?
    Show the answer and explanation

    Answer: B. Reviewing lines is more reliable than trusting a story about them. Cost is a side effect, not the reason. Assistants can explain code well, but a persuasive explanation is not evidence that the code is right.

  3. 3.A condition says if min_order_sources and ... where it should say if source in min_order_sources and .... Which test would most likely catch it?
    Show the answer and explanation

    Answer: A. The faulty condition turns the rule on for every source, so a replay order is wrongly rejected. The message and boundary tests would still pass, because they use an order that is meant to be checked.

Frequently asked questions

What does 'bounded task' mean?

It means a job with a clear edge: which files to change, which to leave alone and what counts as done. The edge lets you check the result. Without it, you have to check everything.

Why not let the assistant fix other problems it sees?

Extra fixes make the diff bigger and hide the risk of the real change. They may also be wrong, because the assistant lacks your context. Note them and raise them as separate changes.

How much code should I paste?

Paste the functions you want changed and one example of each convention to copy. More than that adds noise and may leak things you should not share. Remove secrets and personal data first.

What if the assistant ignores my constraints?

Reject the parts that break them. Try once more with a shorter brief, and if it still strays, make the change yourself. You own what you commit, so you are allowed to stop using the tool.

Written by
PromptFable Editorial
Last updated 19 Nov 2026
Review
Reviewed by Waseem Nadir, Technical Reviewer
Last reviewed 27 Nov 2026

References

Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.

PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.