vercel/ai · error · UnsupportedFunctionalityError
Multiple system messages that are separated by user/assistan
Error message
Multiple system messages that are separated by user/assistant messages
What it means
convertToAmazonBedrockChatMessages only supports a system prompt as the very first message; Bedrock's Converse-style payload cannot represent a system message appearing after user/assistant turns. When a system message follows other messages, an UnsupportedFunctionalityError is thrown.
Source
Thrown at packages/amazon-bedrock/src/convert-to-amazon-bedrock-chat-messages.ts:174
messages: AmazonBedrockMessages;
}> {
const blocks = groupIntoBlocks(prompt);
let system: AmazonBedrockSystemMessages = [];
const messages: AmazonBedrockMessages = [];
let documentCounter = 0;
const generateDocumentName = () => `document-${++documentCounter}`;
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i];
const isLastBlock = i === blocks.length - 1;
const type = block.type;
switch (type) {
case 'system': {
if (messages.length > 0) {
throw new UnsupportedFunctionalityError({
functionality:
'Multiple system messages that are separated by user/assistant messages',
});
}
for (const message of block.messages) {
system.push({ text: message.content });
const cachePoint = getCachePoint(message.providerOptions);
if (cachePoint) {
system.push(cachePoint);
}
}
break;
}
case 'user': {
// combines all user and tool messages in this block into a single message:
const amazonBedrockContent: AmazonBedrockUserMessage['content'] = [];View on GitHub (pinned to 69428b1f8b)
Solutions
- Move all system content into a single system message at the start of the message array.
- Merge multiple/mid-conversation system text into the first system message or prepend it to the following user message.
- If a mid-conversation reminder is needed, include it as part of the user message content instead.
Example fix
// before
messages: [
{ role: 'user', content: 'Hi' },
{ role: 'system', content: 'Be terse' },
]
// after
messages: [
{ role: 'system', content: 'Be terse' },
{ role: 'user', content: 'Hi' },
] Defensive patterns
Strategy: validation
Validate before calling
function assertSystemFirst(messages) {
let seenOther = false;
for (const m of messages) {
if (m.role === 'system') {
if (seenOther) throw new Error('System message must be the first message for Bedrock.');
} else {
seenOther = true;
}
}
} Try / catch
import { UnsupportedFunctionalityError } from '@ai-sdk/provider';
try {
await generateText({ model: bedrock(modelId), messages });
} catch (error) {
if (UnsupportedFunctionalityError.isInstance(error) && error.functionality.includes('system messages')) {
// reorder messages: hoist system prompt to position 0
} else {
throw error;
}
} Prevention
- Normalize message arrays through a helper that hoists all system content to the front and merges it.
- Never append system messages to an in-flight conversation; fold reminders into user content.
- Add an assertion in tests for every prompt template sent to Bedrock.
When it happens
Trigger: Building a prompt array where a message with role 'system' appears after any user or assistant message — e.g. [user, system] or [user, assistant, system] — then passing it to generateText/streamText with a Bedrock model.
Common situations: Dynamically appending a system prompt mid-conversation; merging conversation histories where a reminder system message got inserted later; porting code from providers that allow interleaved system messages.
Related errors
- Unsupported task type: ${taskType}
- URL-based images are not supported for Amazon Bedrock image
- AI_UnsupportedFunctionalityError
- file parts with provider references
- File URL data
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/8972a84abd9391d0.
Report an issue: GitHub.