MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / getErrorMessageIfRefusal

Function getErrorMessageIfRefusal

src/services/api/errors.ts:1187–1210  ·  view source on GitHub ↗
(
  stopReason: BetaStopReason | null,
  model: string,
)

Source from the content-addressed store, hash-verified

1185}
1186
1187export function getErrorMessageIfRefusal(
1188 stopReason: BetaStopReason | null,
1189 model: string,
1190): AssistantMessage | undefined {
1191 if (stopReason !== 'refusal') {
1192 return
1193 }
1194
1195 logEvent('tengu_refusal_api_response', {})
1196
1197 const baseMessage = getIsNonInteractiveSession()
1198 ? `${API_ERROR_MESSAGE_PREFIX}: Claude Code is unable to respond to this request, which appears to violate our Usage Policy (https://www.anthropic.com/legal/aup). Try rephrasing the request or attempting a different approach.`
1199 : `${API_ERROR_MESSAGE_PREFIX}: Claude Code is unable to respond to this request, which appears to violate our Usage Policy (https://www.anthropic.com/legal/aup). Please double press esc to edit your last message or start a new session for Claude Code to assist with a different task.`
1200
1201 const modelSuggestion =
1202 model !== 'claude-sonnet-4-20250514'
1203 ? ' If you are seeing this refusal repeatedly, try running /model claude-sonnet-4-20250514 to switch models.'
1204 : ''
1205
1206 return createAssistantAPIErrorMessage({
1207 content: baseMessage + modelSuggestion,
1208 error: 'invalid_request',
1209 })
1210}

Callers 1

queryModelFunction · 0.85

Calls 3

logEventFunction · 0.85

Tested by

no test coverage detected