Sub topic 2
Start with a specific, testable goal
This chapter assumes you can write and run small programs and tests in at least one language, and that you have used a chat-based or editor-integrated AI assistant. The examples use Python and pytest, but the ideas apply to any language.
The previous chapter established that your prompt is the assistant's only view of the task. This chapter covers the first thing to put in that view: the goal. A goal is specific when the assistant can tell what you want. It is testable when you can tell whether you got it.
What a goal is, and what it is not
A goal is a statement of the outcome you want. It is not a description of the topic, and it is not a list of steps.
Compare these three prompts:
- "Help me with titles." This names a topic, not an outcome.
- "Loop over the titles, call
.lower(), then use a regex." This describes the steps. If the steps are wrong, the assistant will still follow them. - "Write a function that converts an article title into a URL slug." This states an outcome. The assistant can choose the method, and you can check the result.
The third form is the target. It has an action (write), an artifact (a function), and a purpose (convert a title into a slug). It still leaves some details open. Those details are what the rest of the tutorial covers: context, constraints, and examples.
Why vague goals fail
When a prompt leaves something open, the assistant fills the gap with the most statistically likely choice. That choice may be reasonable, but it is a guess. A vague goal produces three kinds of problems:
- Wrong interpretation. "Clean up titles" might mean trimming whitespace, fixing capitalization, removing punctuation, or generating slugs. The assistant picks one.
- Wrong scope. "Improve this module" can produce a full rewrite when you wanted one bug fixed.
- No way to judge the result. If you never said what "done" looks like, you cannot say whether the response meets it. You end up judging by whether the code looks plausible, which is a weak test.
The third problem is the most important. A goal you cannot check leads to a review process you cannot trust.
The testability rule
A practical rule: before you send a prompt, you should be able to describe a check that would pass if the answer is right and fail if it is wrong.
The check can take several forms:
- A unit test that calls the function with given inputs.
- A command that should run without error, such as
python -m pytest. - An observable behavior, such as "the endpoint returns HTTP 400 when the
emailfield is missing". - A measurable property, such as "processes 100,000 rows in under two seconds on the sample file".
If you cannot describe any check, the goal is not yet specific enough. Sharpen it before you ask.
Anatomy of a specific goal
A well-formed goal usually contains four parts.
| Part | Question it answers | Example |
|---|---|---|
| Action | What should the assistant do? | Write, fix, refactor, explain, convert |
| Artifact | What should it produce or change? | A function `slugify(text: str) -> str` |
| Behavior | What should the artifact do, observably? | Return a lowercase, hyphen-separated slug |
| Boundary | What is out of scope? | Do not change other functions in the file |
Not every prompt needs all four. A bug fix needs the action, the artifact, and the behavior. A refactor needs a boundary more than anything, because the usual failure is changing too much. The boundary overlaps with constraints, which the next chapters treat in detail. At this stage, one sentence about what the work should not touch is enough.
Name the artifact precisely
"A function" is weaker than "a Python function slugify(text: str) -> str". The signature fixes the name, the parameter type, and the return type. You can write a test against it before the assistant writes any code. That is the point: a precise artifact lets you check the response mechanically.
Describe behavior, not implementation
State what the result must do. Leave how it does it to the assistant, unless the method matters to you. If it does matter, say so as a constraint, not as part of the goal. Mixing the two is a common error. A prompt that says "use a for loop to build the slug" makes the assistant's job a transcription exercise, and it hides your real goal.
Worked example: from vague to testable
Start with a vague request:
Write a function to clean up titles.Apply the four-part anatomy and the testability rule step by step.
- Action and artifact. "Write a Python function
slugify(text: str) -> str." - Behavior. "It converts an article title into a URL slug."
- Check. "For
"Hello, World!"it returns"hello-world"."
The resulting goal sentence:
Write a Python function slugify(text: str) -> str that converts an
article title into a URL slug, so that slugify("Hello, World!")
returns "hello-world".This goal is short, and it can be checked. The single example shows the shape of the answer. Later chapters add more examples and constraints, such as lowercase output and standard-library-only code.
Write the check first
You can write the acceptance test before you send the prompt. Doing so forces you to decide what "right" means. Here is a minimal version as a plain script, so it runs without any extra tools:
import re
def slugify(text: str) -> str:
text = text.strip().lower()
text = re.sub(r"[^a-z0-9]+", "-", text)
return text.strip("-")
def check_goal() -> None:
assert slugify("Hello, World!") == "hello-world"
assert slugify(" Multiple spaces ") == "multiple-spaces"
assert slugify("") == ""
assert slugify("!!!") == ""
print("All checks passed.")
if __name__ == "__main__":
check_goal()The slugify function here stands in for a response from the assistant. The check_goal function is what you would write yourself. Notice that two of the checks ("" and "!!!") cover cases you did not mention in the one-sentence goal. Writing the check made you notice them. You can then decide whether to add them to the prompt as examples, or accept whatever the assistant does with them.
Goals for different kinds of tasks
The same principle applies to every kind of coding request, but the check looks different each time.
| Task type | Vague goal | Specific, testable goal |
|---|---|---|
| New function | "Make a date helper." | "Write `parse_iso_date(s: str) -> datetime.date` that returns a date for `YYYY-MM-DD` strings and raises `ValueError` otherwise." |
| Bug fix | "Fix the crash." | "Fix the `KeyError: 'user_id'` raised by `load_session()` when the cookie is missing, so it returns `None` instead." |
| Refactor | "Clean up this class." | "Split `ReportBuilder.build()` into two methods without changing its output. The existing tests must still pass." |
| Explanation | "Explain this code." | "Explain in five sentences or fewer what `merge_ranges` returns for overlapping input, and why it sorts first." |
| Test writing | "Add tests." | "Write pytest tests for `slugify` that cover empty input, only symbols, and repeated separators." |
Two patterns show up across the rows. First, each specific goal names an observable result, such as a return value, an exception, an unchanged output, or a sentence limit. Second, the bug fix and refactor goals both include a "before and after" comparison, which gives you something to verify against.
Common errors
Bundling several goals into one
"Add input validation, switch to async, and rename the variables" is three goals. The assistant will attempt all three, and the response is harder to check because failures can interact. If one part is wrong, you must untangle it from the rest. Send one goal per prompt where you can. The chapter on breaking tasks into steps covers how to sequence them.
Using subjective quality words as the goal
Words like "better", "cleaner", "more efficient", and "robust" carry no check. Replace them with something measurable or observable:
- "More efficient" becomes "runs in O(n log n) instead of O(n²)" or "finishes the benchmark file in under two seconds".
- "More readable" becomes "no function longer than 30 lines, and each function has a docstring".
- "Handle errors" becomes "raise
ValueErrorwith the messageempty titlewhen the input is blank".
Hiding the goal at the end of a long prompt
If you paste a page of code and then write one line at the bottom, the assistant has to infer which part of the code the line applies to. Put the goal first, then add the material that supports it.
Describing the symptom but not the desired state
"My function returns None" says what is wrong. It does not say what should happen. Add the other half: "It should return an empty list when no rows match."
Asking for a goal that cannot be tested from the response alone
Some goals depend on information the assistant does not have. "Make this pass in CI" cannot be checked from its response if the failure comes from your CI configuration. Provide the failing output or relevant files, which is the subject of the next chapter, or narrow the goal to something you can run locally.
A quick self-review before you send
Run through these questions on your draft prompt:
- Does the first sentence say what to produce or change?
- Does it name the artifact (function, file, class, query) precisely?
- Does it say what the artifact should do in terms I can observe?
- Could I write a test or command that would tell me if the answer is wrong?
- Is this one goal, not several?
If you answer "no" to any of these, edit the prompt before sending it. It takes a minute, and it usually saves a whole round of corrections.
Summary
- A goal states the outcome you want. It is not a topic and not a list of steps.
- A good goal has an action, a precisely named artifact, an observable behavior, and often a boundary.
- Apply the testability rule: before you send the prompt, you should be able to describe a check that passes or fails.
- Writing the check first exposes edge cases that the one-sentence goal missed.
- Avoid bundled goals, subjective quality words, buried goals, and goals with only a symptom.
Exercise
A teammate sends this prompt: "Make the login code better and faster, and add some error handling." Rewrite it as one specific, testable goal for a single prompt. Name the action, the artifact, and a check you could run on the response. State which parts of the original you left out and why.
Show answer
One acceptable rewrite: "Fix login(username: str, password: str) -> Session so that it raises AuthError('empty username') when username is blank, instead of querying the database. Do not change any other function. Check: pytest tests/test_login.py passes, including a new test that calls login('', 'x') and expects AuthError." The action is fix, the artifact is login, and the check is the test run plus the new test. "Better" and "faster" were left out because they are subjective and unmeasurable as written. They would need a number, such as a time limit on a benchmark. Each of the three requests also belongs in its own prompt, because bundling them makes failures hard to separate.
Exercise
You want an assistant to write a function chunk(items: list, size: int) -> list[list] that splits a list into pieces of at most size items. Write three checks (as assert statements) that you would write before sending the prompt, including at least one edge case.
Show answer
For example: assert chunk([1, 2, 3, 4], 2) == [[1, 2], [3, 4]], assert chunk([1, 2, 3], 2) == [[1, 2], [3]], and assert chunk([], 3) == []. Other valid edge cases are size larger than the list length (chunk([1], 5) == [[1]]) or what happens when size is 0 or negative. If you are unsure what should happen for size <= 0, that is a decision to make and state in the prompt, for example "raise ValueError". Without it, the assistant will choose for you.