{"record":{"id":"e41cdd4e41b57dc2","repo":"vercel/ai","slug":"tool-choice-type-exhaustivecheck-functional","errorCode":null,"errorMessage":"'tool choice type: ${_exhaustiveCheck}' functionality not supported.","messagePattern":"'tool choice type: (.+?)' functionality not supported\\.","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/google/src/google-prepare-tools.ts","lineNumber":310,"sourceCode":"            mode: 'ANY',\n          },\n        },\n        toolWarnings,\n      };\n    case 'tool':\n      return {\n        tools: [{ functionDeclarations }],\n        toolConfig: {\n          functionCallingConfig: {\n            mode: 'ANY',\n            allowedFunctionNames: [toolChoice.toolName],\n          },\n        },\n        toolWarnings,\n      };\n    default: {\n      const _exhaustiveCheck: never = type;\n      throw new UnsupportedFunctionalityError({\n        functionality: `tool choice type: ${_exhaustiveCheck}`,\n      });\n    }\n  }\n}\n\nfunction prepareFunctionDeclaration(\n  tool: FunctionTool,\n): GoogleFunctionDeclaration {\n  const declaration = {\n    name: tool.name,\n    description: tool.description ?? '',\n  };\n\n  try {\n    return {\n      ...declaration,\n      parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema),","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/google/src/google-prepare-tools.ts#L292-L328","documentation":"When converting the AI SDK's tool choice to Google's format, an unrecognized tool choice `type` reaches the exhaustive switch default. The library throws UnsupportedFunctionalityError because it cannot map that tool-choice type to a Google API value.","triggerScenarios":"Passing a toolChoice object whose `type` is not one of the supported values ('auto', 'none', 'required', 'tool') — typically only possible when constructing the value manually, bypassing typed helpers, or after a spec version adds a new type the installed @ai-sdk/google does not yet handle.","commonSituations":"Mixing @ai-sdk/provider versions (spec added a new tool-choice type while the google package is older); hand-constructed tool config objects in tests or custom plumbing.","solutions":["Use only supported toolChoice values: 'auto', 'none', 'required', or { type: 'tool', toolName }","Update @ai-sdk/google to the latest version so newly introduced tool-choice types are mapped","Ensure @ai-sdk/provider and @ai-sdk/google versions are compatible (run pnpm update / check lockfile for mismatched transitive versions)"],"exampleFix":"// before\nconst toolChoice = { type: 'any' } as any;\n// after\nconst toolChoice: LanguageModelV4ToolChoice = { type: 'required' };","handlingStrategy":"validation","validationCode":"const allowed = ['auto', 'none', 'required', 'tool'];\nif (!allowed.includes(toolChoice.type)) {\n  throw new Error(`Unsupported toolChoice type: ${toolChoice.type}`);\n}","typeGuard":"function isSupportedToolChoice(tc: { type: string }): boolean {\n  return ['auto', 'none', 'required', 'tool'].includes(tc.type);\n}","tryCatchPattern":"try {\n  await generateText({ model, prompt, toolChoice });\n} catch (error) {\n  if (AISDKError.isInstance(error) && error.message.includes('tool choice type')) {\n    // fall back to toolChoice: 'auto' or update @ai-sdk/google\n  }\n  throw error;\n}","preventionTips":["Use the typed toolChoice helpers/values from the SDK instead of casting raw objects","Keep @ai-sdk/provider and @ai-sdk/google versions in sync","Handle toolChoice defensively in multi-provider abstraction layers"],"tags":["google","tool-choice","unsupported-functionality","exhaustiveness"],"backgroundTag":"unsupported-functionality","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}