BoundaryML/baml · error

AWS Bedrock only supports text blocks for system messages…

Error message

AWS Bedrock only supports text blocks for system messages, but got {:#?}

What it means

Bedrock system prompts may only contain SystemContentBlock::Text. When a system-role message part is a media (ChatMessagePart::Media), BAML cannot convert it and bails. System messages in Bedrock have no way to carry image/pdf/video blocks, so media there is always invalid.

Solutions

  1. Move the media out of the system message into a user/assistant message.
  2. Replace the system media with a text description of the content.
  3. If it was accidental, fix the prompt template role so media lives under user role.
  4. Use a provider that supports media in system messages if that design is required.

Example fix

// before
message "system" { {#.image} } // media in system
// after
message "system" "You are a vision assistant."
message "user" { {#.image} }
Defensive patterns

Strategy: validation

Validate before calling

if (systemMessageParts.some(p => p.type !== 'text')) { throw new Error('AWS Bedrock system messages must be text-only; move media to a user message.'); }

Type guard

const systemIsTextOnly = (parts) => parts.every(p => p.type === 'text');

Try / catch

try { await b.MyPrompt(...) } catch (e) { if (String(e).includes('only supports text blocks for system messages')) { /* relocate media parts to user role and retry */ } else throw e; }

Prevention

When it happens

Trigger: Putting media content (image/pdf/video) inside a system-role message of a prompt run against an AWS Bedrock client, including media nested inside WithMeta parts without cache_control-only metadata.

Common situations: Copying a chat-template that includes an image in the system prompt (common with OpenAI) and running it on Bedrock; multimodal system instructions that another provider tolerated.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/3e2c73a462b044b7. Report an issue: GitHub.

Appendix: source

Thrown at engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs:1294

            .flatten()
            .collect();

        bedrock::types::Message::builder()
            .set_role(Some(msg.role.as_str().into()))
            .set_content(Some(content))
            .build()
            .map_err(|e: bedrock::error::BuildError| e.into())
    }

    fn part_to_system_message(
        part: &ChatMessagePart,
        allowed_metadata: &AllowedRoleMetadata,
    ) -> Result<Vec<bedrock::types::SystemContentBlock>> {
        match part {
            ChatMessagePart::Text(t) => {
                Ok(vec![bedrock::types::SystemContentBlock::Text(t.clone())])
            }
            ChatMessagePart::Media(_) => anyhow::bail!(
                "AWS Bedrock only supports text blocks for system messages, but got {:#?}",
                part
            ),
            ChatMessagePart::WithMeta(p, meta) => {
                let mut blocks = Self::part_to_system_message(p, allowed_metadata)?;
                if allowed_metadata.is_allowed("cache_control")
                    && meta.contains_key("cache_control")
                {
                    blocks.push(bedrock::types::SystemContentBlock::CachePoint(
                        bedrock::types::CachePointBlock::builder()
                            .r#type(bedrock::types::CachePointType::Default)
                            .build()?,
                    ));
                }
                Ok(blocks)
            }
        }
    }

View on GitHub (pinned to bd85ce9dee)