How Should an App Handle Refusals?
What a refusal is, the kinds an app can meet, and how to answer each one safely and clearly, explained for your AI interview.
In short
Handle a refusal as a planned result: detect it in code, throw away any partial text, show a plain message with a next step, and log it for review.
11 min readBeginnerOccasional · estimateFacts checked 27 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
A refusal is when an AI model, or a safety check around it, says no to a request. My rule is to plan for a refusal as a normal result the app handles. The app checks for the refusal in code, throws away any half-finished text, and shows a plain message with a next step. It logs the category so the team can see patterns. It never keeps resending the same request until something gets through. Some refusals are wrong, so a person reviews the patterns.
A refusal is when the AI says no. It can come from a safety check that stops the reply, from an input that fails a validation check and gets a 400 error code, or from the model writing a polite no in ordinary words. I handle all three the same way: each one gets a plain message, a log entry and no automatic retry. The first job is to notice that a refusal happened, and the signal differs by kind. A flagged refusal comes back with a stop reason, so my code checks that field first. Plain text has no flag, so I check the reply against rules I have tested.
Next, the response. If a streamed reply stopped mid-sentence, I throw away the partial text and never show it. The customer sees a short plain message that says what can't be done and what happens next, such as a person who will get back to them within a working day. I log the request id and the category, so the team can see patterns without reading private chats.
I don't keep resending the same request, since it usually gets another refusal. Anthropic's guide lets me reset by removing or rephrasing the refused turn, but rewording until a check lets it through is a guessing game. Some refusals are wrong, though. A security team asking about its own staging login can be declined. So a person reviews the patterns each week, and we tune the flow around the check and leave the check itself alone. A retry on another model is possible, but only for a category a person has reviewed.
What is a refusal, in plain words?
A refusal is the AI saying no. Sometimes the model decides not to help. Sometimes a safety check around the model stops the reply before a customer sees it. Either way, your app has to decide what the customer sees next.
Think of a bank teller who won't send a wire because it trips the fraud check. A good teller stays clear and calm. She says what she can't do here, what happens next, and who can help. An AI app should behave the same way.
Picture a support assistant at a mid-size bank. A customer asks it for another customer's card number. The assistant has to refuse, and the app around it decides what the customer sees and what the bank records.
Key words
- Refusal
- A reply where the model, or a safety check, declines to help.
- Stop reason
- A label the API sends with each reply that says why it stopped. A refusal has its own label.
- API
- The way your app sends a request to the AI service and gets the reply back.
- Streaming
- The reply arrives word by word, so a half-finished reply can show up first.
- Safety classifier
- A check that reads a request or a reply and flags policy problems.
What are the kinds of refusal?
There are three kinds of no, and each arrives differently, so the app needs a rule for each one. Anthropic's streaming guide lists them in one table: streaming classifier refusals, input and copyright validation with 400 error codes, and model-generated refusals.
- Kind 1
Flagged refusal
A safety check stops the reply. It comes back as a normal reply that carries a refusal flag, so no error is raised.
- Kind 2
Rejected input
The input fails a validation check, such as API input or copyright validation. The API returns a 400 error code, so there is no reply to show.
- Kind 3
Plain-text no
The model writes a polite no in ordinary words. Nothing flags it, so the app has to spot it in the reply.
“Safety classifiers return this stop reason as a normal HTTP 200 response, not an error.”
Anthropic
“Your application still needs to handle refusals, incomplete responses, and API errors”
OpenAI
Two ways a refusal reaches the app
Customer's request
a chat message or a tool call
Model
reads the request and writes a reply
Its reply
Flagged refusal
a safety check stops it, flagged
Plain-text no
the words say no, nothing flags it
Your app's reply
a plain message and a next step
- 1The request reaches the model.
- 2A safety check flags the reply as a refusal.
- 3Or the model writes a plain no in its words.
- 4The app receives the flagged reply and handles it.
- 5The app receives the plain-text no and handles it.
The flagged kind is the easy one, because the API tells you. The plain-text kind is the hard one, because nothing marks it. The app has to spot it in the reply, using rules that you have tested.
What should the app do after a refusal?
The steps are the same whatever the kind. Do them in order, every time.
- 1
Detect it in code
Check the stop reason where the API sends one. The code below uses Anthropic's field. OpenAI's structured outputs page says safety-based refusals are now programmatically detectable, so use the vendor's signal where one exists. Where there is no flag, check the reply against rules you have tested.
- 2
Throw away partial text
A streamed reply can stop mid-sentence. Drop that text and never show it.
- 3
Show a plain message
Say what can't be done in one or two sentences, and name the next step a person can take.
- 4
Log it with the category
Keep the request id, a code that traces one call in your logs, and the category. The team can see patterns without reading private chats.
- 5
Don't loop
Don't resend the same request, since it usually gets another refusal. Reset the conversation, then hand it to a person or change the flow. Rewording it until a check lets it through is a guessing game.
Here it is in plain Python. We pretend the model refused a streamed reply, and the marked lines decide what the customer sees.
# A simplified support bot. The model's reply arrives as a dict. We branch on
# its stop reason, and we never show the model's own partial text to the customer.
REPLY_TEXT = {
"refusal": "We can't help with that request here. A team member will contact you within one working day.",
}
def handle(reply, request_id):
if reply["stop_reason"] == "refusal":
# Partial text from a refused stream is thrown away, not shown.
category = reply["stop_details"]["category"] or "none"
print("log:", request_id, "refusal, category", category)
return REPLY_TEXT["refusal"]
return reply["text"]
streamed = {"stop_reason": "refusal", "text": "Step 1: open the",
"stop_details": {"category": "cyber"}}
done = {"stop_reason": "end_turn", "text": "Your card is ready.",
"stop_details": None}
print(handle(streamed, "req-1042"))
print(handle(done, "req-1043"))Output
log: req-1042 refusal, category cyber We can't help with that request here. A team member will contact you within one working day. Your card is ready.
What happens after a refusal
Refusal arrives
a flag, or a plain no in the words
Handle it now
Drop partial text
it is incomplete, never shown
Plain message
what can't be done, plus next step
Log the category
request id and category only
Weekly review
a person checks the patterns
- 1The partial text from the stream is thrown away.
- 2The customer gets a plain message with a next step.
- 3The request id and the category go into the log.
- 4The log feeds a review by a person, each week.
Anthropic's streaming guide adds one catch. Continuing the same conversation without a reset brings more refusals, so drop the refused turn or start a fresh conversation.
Anthropic's docs say a declined request can usually be retried on another Claude model, and their streaming guide lists a fallback as a best practice. Which requests you retry is still your call, so only retry a category a person has reviewed, and log every try.
Tip
Never tell a customer that a no is always right. Say you can't help here, and point them to someone who can.
How would you handle a refusal that was wrong?
A security team asks the assistant to help test its own staging login for SQL injection. The request is legitimate. The API still marks it as a cyber refusal, because harmless cybersecurity work can also trigger the same category.
“Benign cybersecurity work can also trigger this category.”
Anthropic
- Without a rule
Keep rewording
Engineers try synonyms until one gets through. The safety check becomes a guessing game, and nobody knows what was sent.
- With a rule
Plain message, a route
The app says it can't run that here, names the security review route, logs the category, and waits for a person.
In a made-up month, the assistant declined 40 of 1,200 security questions. A review found 9 of those 40 were fine to answer. The team fixed the route to a person, kept the safety check as it was, and moved its staging tests to its own tooling.
What does the interviewer want to hear?
A strong answer covers
- A refusal is a planned result the app handles with fixed steps.
- Three kinds: a flagged refusal, a rejected input, and a plain-text no.
- Detect it in code: the stop reason where the API sends one, and tested rules where it doesn't.
- Drop partial text, show a plain message with a next step, and log it.
- No loops: never resend or reword a request to slip past a check.
- Refusals can be wrong, so a person reviews the patterns.
Common traps
Trap"Just look for the word sorry in the reply."
BetterPlain text needs a rule that you test. Where the API sends a flag, use the flag, since it is the reliable signal.
Trap"Show the model's refusal text to the customer."
BetterShow your own plain message. The model's wording can be confusing, and it may say more than you want a customer to read.
Trap"If it refuses, try again until it answers."
BetterRetrying to get past a check turns it into a guessing game. Log it, change the flow, or hand it to a person.
Can you pick the right first step?
Pick the right first step
A streamed reply stopped partway, with a refusal flag. Which step comes first?
Quick check
A product manager asks if the app can quietly send a refused request to another model. What is the best answer?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
Last updated on 27 November 2026
Building an AI app that has to say no safely?
I design and build AI products and agents, including the interface and the system behind it. Book a short call and tell me what your app needs to do.