Skip to content

[Bug] @ai-sdk/amazon-bedrock: Tool call IDs incompatible with Mistral models - "must be a-z, A-Z, 0-9, with a length of 9" #11802

Description

@arpanpal-at

Description

When using Mistral models via @ai-sdk/amazon-bedrock, tool calling fails on multi-turn conversations because the tool call IDs generated by the Bedrock Converse API do not meet Mistral's strict format requirements.

Code to reproduce:

import {createAmazonBedrock} from '@ai-sdk/amazon-bedrock';
import {generateText, jsonSchema} from 'ai';

const bedrock = createAmazonBedrock({
    region: 'us-east-1',
    // ... credentials
});

const model = bedrock('mistral.ministral-3-14b-instruct');

const result = await generateText({
    model,
    tools: {
        searchWeb: {
            description: 'Search the web for information',
            parameters: jsonSchema({
                type: 'object',
                properties: {
                    query: {type: 'string', description: 'Search query'},
                },
                required: ['query'],
            }),
        },
    },
    toolChoice: 'auto',
    messages: [
        {
            role: 'user',
            content: 'Search for the projected revenue for Alphabet Inc. in 2026',
        },
    ],
    maxRetries: 1,
});

Expected Behavior

Tool calling should work correctly with Mistral models on Bedrock, similar to how it works with Anthropic models on Bedrock.

Actual Behavior

The first tool call succeeds, but when sending the tool result back for the next turn, the request fails with:

ValidationException: The model returned the following errors:
{
  "code": "validation_error",
  "message": "Tool call id was i-nKGDr5g but must be a-z, A-Z, 0-9, with a length of 9.
              Tool call id was i-nKGDr5g but must be a-z, A-Z, 0-9, with a length of 9.",
  "param": null,
  "type": "invalid_request_error"
}

Root Cause Analysis

  1. Bedrock generates tool call IDs in its own format: tooluse_bpe71yCfRu2b5i-nKGDr5g
  2. Mistral requires tool call IDs to match the regex ^[a-zA-Z0-9]{9}$:
    • Exactly 9 characters
    • Alphanumeric only (no underscores, hyphens, or prefixes)
  3. When the tool result is sent back with the Bedrock-format ID, Mistral's validation rejects it

Related Issues

This is a known compatibility issue that has been addressed in other projects:

Suggested Fix

Add Mistral-specific tool call ID normalization in @ai-sdk/amazon-bedrock. The opencode project implemented this via a normalizeMistralToolCallIds() function that:

  1. Detects Mistral models by provider/model ID
  2. Transforms tool call IDs to meet Mistral's requirements (first 9 alphanumeric characters)

Example transformation:

  • tooluse_bpe71yCfRu2b5i-nKGDr5gbpe71yCfR (9 alphanumeric chars)

Workaround

Currently, there is no workaround other than avoiding tool use with Mistral models on Bedrock, or implementing a custom transformation layer at the application level.

Additional Context

Full error response from Bedrock:

{
  "statusCode": 400,
  "responseHeaders": {
    "x-amzn-errortype": "ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/",
    "x-amzn-requestid": "1db5f47e-7335-4051-bea0-224852765024"
  },
  "responseBody": {
    "message": "The model returned the following errors: {\"code\":\"validation_error\",\"message\":\"Tool call id was i-nKGDr5g but must be a-z, A-Z, 0-9, with a length of 9.\"}"
  }
}

AI SDK Version

Environment:

  • ai: 5.0.27
  • @ai-sdk/amazon-bedrock: 3.0.19
  • Node.js: 20.x
  • AWS Region: us-east-1

Mistral models affected:

  • mistral.mistral-large-2407-v1:0
  • mistral.ministral-3-14b-instruct
  • mistral.ministral-3-8b-instruct

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions