BoundaryML/baml · error

AWS region is required to build modular request. Set it in t

Error message

AWS region is required to build modular request. Set it in the client options or via AWS_REGION.

What it means

The modular Bedrock request path needs an AWS region to construct the request (region is required by the Bedrock Converse endpoint). It reads the region from client options or the AWS_REGION environment variable, and if the resulting value is empty it bails with this error before sending anything.

Source

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

        chat_messages: &[RenderedChatMessage],
        stream: bool,
        request_id: HttpRequestId,
    ) -> Result<HTTPRequest> {
        if stream {
            anyhow::bail!(
                "AWS Bedrock modular streaming is not supported. Use non-streaming modular requests."
            );
        }

        let region = self.properties.region.clone().unwrap_or_else(|| {
            ctx.env_vars()
                .get("AWS_REGION")
                .cloned()
                .unwrap_or_default()
        });

        if region.is_empty() {
            anyhow::bail!(
                "AWS region is required to build modular request. Set it in the client options or via AWS_REGION."
            );
        }

        let body_string = serde_json::to_string(&serde_json::Value::Object(
            self.build_converse_body_json(chat_messages)?,
        ))?;
        let body_bytes = body_string.as_bytes().to_vec();

        let host = format!("bedrock-runtime.{region}.amazonaws.com");
        let encoded_model =
            utf8_percent_encode(&self.properties.model, PATH_SEGMENT_ENCODE_SET).to_string();
        let url = format!("https://{host}/model/{encoded_model}/converse");

        let mut header_map = HashMap::new();
        header_map.insert("content-type".to_string(), "application/json".to_string());
        header_map.insert("accept".to_string(), "application/json".to_string());

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Set region in the client's options block, e.g. options { region us-east-1 }.
  2. Export AWS_REGION (e.g. export AWS_REGION=us-east-1) in the runtime environment.
  3. Ensure the region string isn't empty at deploy time (check .env loading, container env inheritance).

Example fix

// before
client<llm> BedrockNova {
  provider aws-bedrock
  options { model nova-pro }
}
// after
client<llm> BedrockNova {
  provider aws-bedrock
  options { model nova-pro region us-east-1 }
}
Defensive patterns

Strategy: validation

Validate before calling

region = client_options.get('region') or os.environ.get('AWS_REGION', '')
if not region:
    raise ValueError("AWS region required: set client options region or AWS_REGION")

Prevention

When it happens

Trigger: Calling a function on an aws-bedrock client (modular path) when neither client options specify region nor the AWS_REGION env var is set (or is set to an empty string).

Common situations: Deploying to environments (containers, CI, serverless) where AWS_REGION isn't injected; forgetting the region key in client options; AWS_REGION set as empty in .env files.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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