MCPcopy Create free account
hub / github.com/Noumena-Network/code / getErrorMessageIfRefusal

Function getErrorMessageIfRefusal

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

Source from the content-addressed store, hash-verified

1237}
1238
1239export function getErrorMessageIfRefusal(
1240 stopReason: BetaStopReason | null,
1241 model: string,
1242): AssistantMessage | undefined {
1243 if (stopReason !== 'refusal') {
1244 return
1245 }
1246
1247 logEvent('ncode_refusal_api_response', {})
1248
1249 const baseMessage = getIsNonInteractiveSession()
1250 ? `${API_ERROR_MESSAGE_PREFIX}: 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.`
1251 : `${API_ERROR_MESSAGE_PREFIX}: 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 Code to assist with a different task.`
1252
1253 const modelSuggestion =
1254 model !== 'claude-sonnet-4-20250514'
1255 ? ' If you are seeing this refusal repeatedly, try running /model claude-sonnet-4-20250514 to switch models.'
1256 : ''
1257
1258 return createAssistantAPIErrorMessage({
1259 content: baseMessage + modelSuggestion,
1260 error: 'invalid_request',
1261 })
1262}

Callers 1

queryModelFunction · 0.85

Calls 3

logEventFunction · 0.70

Tested by

no test coverage detected