All Tech Notes

Tech Notes

AI Best Practices Part 3 Define done before the AI starts

Chris Byers

When you ask an AI agent to build a feature or fix a bug, you need to define what “Done” or “Fixed” means.

That definition belongs to the person requesting the work. The agent can help turn it into a test plan, identify missing cases, and suggest ways to verify it. You still need to review and approve the expected behavior before implementation begins.

Otherwise, you can end up with an agent that writes the code, writes tests around its own interpretation, and declares success when those tests pass. The original misunderstanding can survive every step.

In Part 2, I covered where an agent should work. This part is about how you establish that the work meets your expectations.

Give the agent a functional definition of success

“Fix the invoice form” leaves a lot open to interpretation. Describe the behavior you expect and the situations where it must hold.

For example, a user could give the agent these acceptance criteria before work begins:

  1. A signed-in customer can create an invoice with a recipient and at least one line item.
  2. Submitting an incomplete form identifies the missing fields and preserves the values already entered.
  3. A successful submission creates one invoice, shows a confirmation, and leaves the invoice available after refreshing the page.
  4. Clicking submit repeatedly while a request is pending creates a single invoice.
  5. A failed save shows an actionable error and preserves the draft for retry.
  6. Another customer cannot retrieve or modify the invoice, including through a direct API request.
  7. The form and its error messages remain readable and usable on a phone.

Those criteria describe the result the user needs. They give the agent a target that exists independently of the implementation it chooses. Testing user-visible behavior is also a central recommendation in Playwright’s testing guidance. Playwright testing best practices.

For a bug fix, add the exact steps that reproduce the problem, the expected result, and the behavior that must continue working. If the agent discovers that a requirement needs to change, have it explain the issue and get your agreement before changing the target.

Understand what generated unit tests establish

I put little confidence in a newly generated unit test that simply restates the code an AI has just written. Both can contain the same mistaken assumption.

Imagine the implementation applies a discount at the wrong stage of an invoice calculation. If the agent derives its expected test result from that implementation, the test can pass while the customer still receives the wrong total. More tests written from the same assumption can make the result look thoroughly checked.

A unit test based on an independently established calculation can catch that error immediately. The important question is where the expected answer came from.

Once the intended behavior has been verified, meaningful unit tests also provide lasting regression protection. A later change to a shared calculation, validation rule, or date utility can affect a feature that appears unrelated. Tests can expose that break before it reaches customers. Tests that focus on behavior also tend to hold up better as implementation details change. Unit testing in Software Engineering at Google.

Specify how each requirement will be verified

Give the agent a functional test plan alongside the acceptance criteria. Decide what evidence would establish each outcome.

For the invoice example, I would ask for a live test of the successful save, invalid input, repeated submission, and failed-request recovery. I would also want confirmation that the saved record exists after a refresh.

The account-access requirement needs an unauthorized request against a test account’s invoice, plus review of the server’s authorization checks. A hidden button alone gives you very little information about whether the API enforces ownership.

Code review should examine how retries, validation, and persistence work together. The reviewer needs to compare those decisions against the agreed criteria and look for missing paths.

For the phone layout, ask the agent to open the running application at a specified viewport, exercise the form, and capture the normal, error, and success states. That checks what the customer actually sees.

Use disposable test data and an appropriate development or staging environment for these checks.

Use screenshots for the evidence they can provide

A screenshot can reveal clipped labels, an obscured submit button, or an error message positioned where a customer is unlikely to see it. Capture the relevant state and inspect it against the user’s requirements.

It provides evidence of the visible interface at that moment. Saving a record, enforcing account access, and handling a retry require additional verification of behavior and state.

Visual regression tests can preserve an approved appearance for future comparisons. Review the initial baseline carefully, since subsequent comparisons will treat it as the reference. Keep the rendering environment consistent when comparing screenshots. Playwright visual comparisons.

Ask the agent to report against your definition

Before work begins, tell the agent how to report completion. For each acceptance criterion, have it state what it checked, the observed result, and where you can inspect the evidence. Anything it could not verify should remain explicitly unresolved.

For a bug, ask it to reproduce the original failure before the change where possible, then repeat the same steps after the fix. Review a focused regression test that would fail for the original defect.

“The tests pass” tells you something about the tests that ran. Your definition of “Done” or “Fixed” should require the agreed functional outcomes, supported by the relevant review, live results, and screenshots.

The user sets that definition. The AI’s job is to implement the change and provide enough evidence for the user to judge whether it has been met.

A first conversation

Let’s find a time.

Leave your contact details and I’ll get in touch to arrange a meeting. Feel free to add a message.

Your contact details and optional message