{"record":{"id":"66e777badd4daf38","repo":"vercel/ai","slug":"unsupported-role-exhaustivecheck-66e777","errorCode":null,"errorMessage":"Unsupported role: ${_exhaustiveCheck}","messagePattern":"Unsupported role: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mistral/src/convert-to-mistral-chat-messages.ts","lineNumber":193,"sourceCode":"            case 'content':\n            case 'json':\n            case 'error-json':\n              contentValue = JSON.stringify(output.value);\n              break;\n          }\n\n          messages.push({\n            role: 'tool',\n            name: toolResponse.toolName,\n            tool_call_id: toolResponse.toolCallId,\n            content: contentValue,\n          });\n        }\n        break;\n      }\n      default: {\n        const _exhaustiveCheck: never = role;\n        throw new Error(`Unsupported role: ${_exhaustiveCheck}`);\n      }\n    }\n  }\n\n  return messages;\n}\n","sourceCodeStart":175,"sourceCodeEnd":200,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/mistral/src/convert-to-mistral-chat-messages.ts#L175-L200","documentation":"convertToMistralChatMessages exhaustively switches over prompt message roles (system/user/assistant/tool). The default branch uses TypeScript's never-exhaustiveness check and throws for any role outside those, so this only fires with a role the converter doesn't know.","triggerScenarios":"A LanguageModelV4Prompt containing a message role other than 'system', 'user', 'assistant', or 'tool' — typically only possible with type-unsafe prompt construction or a version mismatch between prompt types and the Mistral package.","commonSituations":"Casting untyped/legacy message arrays into prompts; building prompts programmatically with wrong role strings; running mismatched versions of `ai` core and `@ai-sdk/mistral`.","solutions":["Only use system/user/assistant/tool roles in prompts sent to Mistral.","Update both `ai` and `@ai-sdk/mistral` to matching latest versions.","Fix type-unsafe prompt construction (remove `as any` casts).","Sanitize roles before converting legacy chat histories."],"exampleFix":"// before\nconst prompt = [{ role: 'developer', content: 'hi' }] as any;\n// after\nconst prompt = [{ role: 'system', content: 'hi' }];","handlingStrategy":"type-guard","validationCode":"const roles = ['system', 'user', 'assistant', 'tool'] as const;\nfunction hasValidRoles(prompt: { role: string }[]): boolean {\n  return prompt.every(m => (roles as readonly string[]).includes(m.role));\n}","typeGuard":"type MessageRole = 'system' | 'user' | 'assistant' | 'tool';\nfunction isSupportedRole(role: string): role is MessageRole {\n  return ['system', 'user', 'assistant', 'tool'].includes(role);\n}","tryCatchPattern":"try {\n  await generateText({ model: mistral(modelId), prompt });\n} catch (error) {\n  if (error instanceof Error && error.message.startsWith('Unsupported role:')) {\n    console.error('Invalid role:', error.message);\n    // fix prompt construction / versions, then retry\n  } else {\n    throw error;\n  }\n}","preventionTips":["Type prompts as LanguageModelV4Prompt instead of casting with `as any`.","Keep `ai` and `@ai-sdk/mistral` on compatible versions.","Validate legacy chat-history roles when importing into prompts."],"tags":["mistral","prompt-conversion","exhaustive-check","message-role"],"backgroundTag":"unsupported-message-role","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}