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

Function getErrorMessageIfRefusal

source code/services/api/errors.ts:1186–1209  ·  view source on GitHub ↗
(
  stopReason: BetaStopReason | null,
  model: string,
)

Source from the content-addressed store, hash-verified

1184}
1185
1186export function getErrorMessageIfRefusal(
1187 stopReason: BetaStopReason | null,
1188 model: string,
1189): AssistantMessage | undefined {
1190 if (stopReason !== 'refusal') {
1191 return
1192 }
1193
1194 logEvent('tengu_refusal_api_response', {})
1195
1196 const baseMessage = getIsNonInteractiveSession()
1197 ? `${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.`
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). Please double press esc to edit your last message or start a new session for Claude Code to assist with a different task.`
1199
1200 const modelSuggestion =
1201 model !== 'claude-sonnet-4-20250514'
1202 ? ' If you are seeing this refusal repeatedly, try running /model claude-sonnet-4-20250514 to switch models.'
1203 : ''
1204
1205 return createAssistantAPIErrorMessage({
1206 content: baseMessage + modelSuggestion,
1207 error: 'invalid_request',
1208 })
1209}

Callers 1

queryModelFunction · 0.85

Calls 3

logEventFunction · 0.85

Tested by

no test coverage detected