# 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.

AI and LLM interview question Q234, Guardrails and AI safety. Beginner, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-should-an-app-handle-refusals

## Say it in 30 seconds

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.

## Say it in 2 minutes

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.

- **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)

*Diagram, Two ways a refusal reaches the app: Two of the three kinds reach the app from the model's reply. A safety check flags Kind 1, and Kind 3, the plain-text no, has only its words to go on. Rejected input (Kind 2) comes back as an error code, so it is not drawn here.*
1. The request reaches the model.
2. A safety check flags the reply as a refusal.
3. Or the model writes a plain no in its words.
4. The app receives the flagged reply and handles it.
5. The 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.

```python
# 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:

```text
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.
```

*Diagram, What happens after a refusal: A refusal goes three ways at once: the partial text is dropped, the customer gets a plain message with a next step, and the category is logged. Only the log feeds the weekly review by a person.*
1. The partial text from the stream is thrown away.
2. The customer gets a plain message with a next step.
3. The request id and the category go into the log.
4. The 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." Better: Plain 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." Better: Show 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." Better: Retrying 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?

A. Keep the first half on screen, then add the rest later.
B. Throw the partial text away, then show the plain message.
C. Send the same request again straight away.
D. Show the model's raw text in the chat, because it is accurate.

**Answer:** B. Partial text from a refused reply is incomplete, so it is thrown away and never shown. The plain message comes next. Retrying at once is the loop to avoid.

**Quick check:** A product manager asks if the app can quietly send a refused request to another model. What is the best answer?

A. Yes, always, until one model says yes.
B. Only for a category a person has reviewed, with every try logged.
C. Never, because a refusal is always right.
D. Yes, if the first model's reply is logged as a refusal.

**Answer:** B. A refusal can be wrong. Anthropic lists a fallback as a best practice, but you choose which categories to retry. Only retry a category a person has reviewed, and log every try. Retrying until one model answers turns the safety check into a guessing game.

## Can you answer these from memory?

**Flash cards**

- **What is a refusal?** The model, or a safety check around it, declines to help. It is a normal result.
- **How many kinds of no are there?** Three: a flagged refusal, rejected input (an error code), and a plain-text no.
- **Why check the stop reason?** It is the API's own flag for a refusal. Where the API sends one, use it.
- **What about partial text?** Discard it. Treat it as incomplete, and never show it to the customer.
- **What do you do after a refusal?** Show a plain message with a next step, log the category, and hand it to a person.
- **Can a refusal be wrong?** Yes. Harmless security work can be declined, so review the patterns each week.

## Likely follow-up questions

- Q232 What is over-refusal? https://designervenkat.online/interview/ai/what-is-over-refusal
- Q233 How do you balance safety and helpfulness? https://designervenkat.online/interview/ai/how-do-you-balance-safety-and-helpfulness
- Q235 What is misuse monitoring? https://designervenkat.online/interview/ai/what-is-misuse-monitoring
- Q239 How do you respond to an AI incident? https://designervenkat.online/interview/ai/how-do-you-respond-to-an-ai-incident
- Q244 How do you measure guardrail false positives and negatives? https://designervenkat.online/interview/ai/guardrail-false-positives-and-negatives
- Q245 Design a guardrail pipeline for a public chatbot. https://designervenkat.online/interview/ai/design-a-guardrail-pipeline-for-a-public-chatbot
