vercel/ai · error · UnsupportedFunctionalityError

'tool choice type: ${_exhaustiveCheck}' functionality not su

Error message

'tool choice type: ${_exhaustiveCheck}' functionality not supported.

What it means

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.

Source

Thrown at packages/google/src/google-prepare-tools.ts:310

            mode: 'ANY',
          },
        },
        toolWarnings,
      };
    case 'tool':
      return {
        tools: [{ functionDeclarations }],
        toolConfig: {
          functionCallingConfig: {
            mode: 'ANY',
            allowedFunctionNames: [toolChoice.toolName],
          },
        },
        toolWarnings,
      };
    default: {
      const _exhaustiveCheck: never = type;
      throw new UnsupportedFunctionalityError({
        functionality: `tool choice type: ${_exhaustiveCheck}`,
      });
    }
  }
}

function prepareFunctionDeclaration(
  tool: FunctionTool,
): GoogleFunctionDeclaration {
  const declaration = {
    name: tool.name,
    description: tool.description ?? '',
  };

  try {
    return {
      ...declaration,
      parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema),

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Use only supported toolChoice values: 'auto', 'none', 'required', or { type: 'tool', toolName }
  2. Update @ai-sdk/google to the latest version so newly introduced tool-choice types are mapped
  3. Ensure @ai-sdk/provider and @ai-sdk/google versions are compatible (run pnpm update / check lockfile for mismatched transitive versions)

Example fix

// before
const toolChoice = { type: 'any' } as any;
// after
const toolChoice: LanguageModelV4ToolChoice = { type: 'required' };
Defensive patterns

Strategy: validation

Validate before calling

const allowed = ['auto', 'none', 'required', 'tool'];
if (!allowed.includes(toolChoice.type)) {
  throw new Error(`Unsupported toolChoice type: ${toolChoice.type}`);
}

Type guard

function isSupportedToolChoice(tc: { type: string }): boolean {
  return ['auto', 'none', 'required', 'tool'].includes(tc.type);
}

Try / catch

try {
  await generateText({ model, prompt, toolChoice });
} catch (error) {
  if (AISDKError.isInstance(error) && error.message.includes('tool choice type')) {
    // fall back to toolChoice: 'auto' or update @ai-sdk/google
  }
  throw error;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/e41cdd4e41b57dc2. Report an issue: GitHub.