Sub topic 14
Testing and iterating on your instructions
This chapter covers how to test and improve prompt files, custom agents, and skills. It assumes you have written at least one of each, that you can read Markdown and YAML frontmatter, and that you know your instructions share a context window with everything else the agent reads. Field names and file locations differ between products, so check your tool's documentation for the exact setup.
Why instructions need tests
An instruction file looks like documentation, but it behaves like code. It changes what an agent does, and a small edit can break a workflow that worked yesterday. The difference from code is that the same input can give different output on each run. A single successful run tells you very little.
Instructions fail in a few common ways:
- Not triggered. A skill or agent is never selected because its description does not match how people phrase the task.
- Triggered at the wrong time. The description is so broad that the skill loads for unrelated requests and wastes context.
- Followed loosely. The agent skips a step, changes the output format, or edits files you said not to touch.
- Conflicting. Two instruction sources disagree, such as a project-wide rule and a skill step, and the agent picks one unpredictably.
- Stale. The project changed (new test command, renamed folder) and the instructions still describe the old setup.
Testing means checking for each of these on purpose, with a small set of realistic tasks.
Build a small test set
Start with three to six tasks for each artifact. Write them down in a file in the repository, so you can rerun them after every change. A good set covers four kinds of case:
| Case | What it checks | Example for a changelog skill |
|---|---|---|
| Typical | The main workflow works | "Add a changelog entry for the login fix" |
| Variant phrasing | The skill is selected for different wording | "Draft release notes for this PR" |
| Edge case | Missing or odd input is handled | A PR with no number, or an empty CHANGELOG.md |
| Negative | The artifact stays out of unrelated work | "Refactor the login function" |
For each task, write the expected result before you run it. Keep expectations observable. "Entry appears under Fixed, in the past tense, and no other file changes" can be checked. "Entry is good" cannot.
## Test set: changelog-entry
1. "Add a changelog entry for the login timeout fix (#212)"
Expect: skill loads, one line under Fixed, past tense, mentions #212.
2. "Draft release notes for the last three commits"
Expect: skill loads, entries grouped by Added/Changed/Fixed.
3. "Add a changelog entry" in a repo with an empty CHANGELOG.md
Expect: agent asks for the format or states its assumption.
4. "Rename the loginUser function to signIn"
Expect: skill does not load, CHANGELOG.md unchanged.Test in a clean session
Context from earlier in a conversation can hide problems. If you told the agent your preferences ten messages ago, a later success may come from that conversation and not from your file. Start a fresh session for each test, with only the instruction files that a real user would have.
Also run each test more than once. Three runs of the same task is a practical minimum for a task you care about. If two out of three runs follow the format, the instruction is not reliable yet. Treat inconsistency as a finding, not as bad luck.
Check what the agent actually loaded
When behavior is wrong, first find out whether the instruction reached the model. Many tools show which skills, agents, or files were loaded, through a status line, a verbose mode, or a context inspection command. The name varies by product, so look in your tool's documentation. If your tool offers none of these, ask the agent directly: "Which instructions are you following for this task?" The answer is not a perfect record, but it often reveals a missing or ignored file.
This splits debugging into two separate questions:
- Was it loaded? If not, the problem is discovery: the file location, the frontmatter, or the description.
- Was it followed? If it was loaded but ignored, the problem is the wording, the length, or a conflict with other instructions.
The diagram below shows the decision path.
Iterate one change at a time
When a test fails, change one thing and rerun the whole set. If you change the description, the steps, and the output format together, you will not know which edit helped. Rerun all tests, not just the failing one, because a fix for one case often breaks another. This is the same reason software projects run regression tests.
Here are common fixes, matched to symptoms.
| Symptom | Likely cause | Fix |
|---|---|---|
| Skill never loads | Description does not name the trigger | Add the phrases users say, such as "release notes" and "changelog" |
| Skill loads for unrelated tasks | Description is too broad | Name the task and add a "use when" condition |
| Steps are skipped | Steps are buried in long prose | Use a short numbered list and move detail to a reference file |
| Output format drifts | Format is described, not shown | Add a short example of the exact output |
| Agent edits files it should not | Restriction only stated in text | Remove the write tool from the agent's tool list |
| Placeholder shows up literally | Wrong input syntax for your tool | Check the substitution syntax in your tool's documentation |
Notice the fix for unwanted edits. A sentence such as "Do not modify files" is a request. A tool list without write access is a limit. When the behavior matters, prefer the limit, and keep the sentence as a reminder.
Rewrite a weak description
Skill descriptions are the most common source of failures, so practice rewriting them. Suppose the changelog skill never loads for "write release notes".
# Before
description: Helps with changelogs.
# After
description: Writes a changelog entry in the project's format. Use when the user asks to add, draft, or update a changelog or release note.The second version says what the skill does and when to use it, and it contains the words users actually type. After the change, rerun the variant-phrasing test and the negative test. A description that now matches "release notes" might also match "write a release announcement email", which you may not want.
Test the negative cases
Teams often test only that an artifact works and never that it stays quiet. Negative tests protect your context budget. A skill that loads on every request costs tokens each time and may steer the agent away from what the user asked. For each artifact, include at least one request that should not trigger it, and check that nothing changed.
For custom agents, add a boundary test: ask the agent to do something outside its role, such as asking a read-only reviewer to fix a bug. The expected result is a refusal or a suggestion, and no changed files. If the agent edits anyway, the tool list is too wide.
Keep a record of changes
Keep a short note of why each change was made, either in the commit message or beside the test set. "Added 'release note' to description because test 2 did not trigger the skill" will help the next person, and the next version of you, avoid undoing the fix. Because instruction files live in the repository, ordinary Git history provides this record. The next chapter covers sharing them with a team.
Signs the instruction is done
Stop iterating when:
- All tests pass on three consecutive fresh runs.
- The file is as short as it can be while still passing. Remove any line whose deletion does not change a result.
- A teammate who has not seen the file can run the test set and get the same outcomes.
Recheck the tests when the project changes (a new test command, a moved directory) or when you switch to a different model, since models differ in how closely they follow instructions.
Exercise
A skill named db-migration never loads when a user types "add a column to the orders table", although it loads for "write a migration". The skill's description is "Database migration helper." What is the most likely cause, what single change would you make, and which tests would you rerun afterward?
Show answer
The description does not mention how users phrase the task or when to use the skill, so "add a column" does not match it. Rewrite it to say what the skill does and when to use it, for example: "Creates and edits database schema migrations. Use when the user asks to add, change, or remove a table, column, or index, or to write a migration." Then rerun the whole test set, including the typical and variant-phrasing cases and at least one negative case such as "write a SELECT query", to confirm the broader description does not trigger on unrelated database work.
Exercise
You have a code-reviewer agent with the instruction "Never modify files", but in one of three test runs it edited a file. What should you change, and why is rewording the instruction not enough?
Show answer
Remove write-capable tools from the agent's tool list so it can only read, search, and list files. The sentence in the prompt is a request that the model may fail to follow on some runs, while a tool list is enforced by the tool. Keep the sentence as a reminder, then rerun the boundary test several times in fresh sessions.