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

Function getErrorMessageIfRefusal

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

Source from the content-addressed store, hash-verified

1180}
1181
1182export function getErrorMessageIfRefusal(
1183 stopReason: BetaStopReason | null,
1184 model: string,
1185): AssistantMessage | undefined {
1186 if (stopReason !== 'refusal') {
1187 return
1188 }
1189
1190 logEvent('tengu_refusal_api_response', {})
1191
1192 const baseMessage = getIsNonInteractiveSession()
1193 ? `${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.`
1194 : `${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.`
1195
1196 const modelSuggestion =
1197 model !== 'claude-sonnet-4-20250514'
1198 ? ' If you are seeing this refusal repeatedly, try running /model claude-sonnet-4-20250514 to switch models.'
1199 : ''
1200
1201 return createAssistantAPIErrorMessage({
1202 content: baseMessage + modelSuggestion,
1203 error: 'invalid_request',
1204 })
1205}

Callers 1

queryModelFunction · 0.85

Calls 3

logEventFunction · 0.85

Tested by

no test coverage detected