{"record":{"id":"1cd7fe1d449ca678","repo":"BoundaryML/baml","slug":"expected-message-output-in-response-but-is-type","errorCode":null,"errorMessage":"Expected message output in response, but is type {}","messagePattern":"Expected message output in response, but is type (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs","lineNumber":686,"sourceCode":"            // Adding a custom http client (above) breaks the stalled stream protection for some reason. If a bedrock request takes longer than 5s (the default grace period, it makes it error out), so we disable it.\n            .stalled_stream_protection(StalledStreamProtectionConfig::disabled())\n            .interceptor(CollectorInterceptor::new(\n                call_stack,\n                http_request_id.clone(),\n                &self.properties,\n            ));\n\n        // Set endpoint_url if specified\n        if let Some(endpoint_url) = self.properties.endpoint_url.as_ref() {\n            bedrock_config = bedrock_config.endpoint_url(endpoint_url);\n        }\n\n        Ok(BedrockRuntimeClient::from_conf(bedrock_config.build()))\n    }\n\n    async fn chat_anyhow(&self, response: &ConverseOutput) -> Result<String> {\n        let Some(bedrock::types::ConverseOutput::Message(ref message)) = response.output else {\n            anyhow::bail!(\n                \"Expected message output in response, but is type {}\",\n                \"unknown\"\n            );\n        };\n        // Try to extract text from all content blocks\n        let mut extracted_text = String::new();\n        let mut has_text = false;\n\n        if message.content.is_empty() {\n            anyhow::bail!(\"Expected message output to have content, but content is empty\");\n        }\n\n        for content_block in &message.content {\n            if let bedrock::types::ContentBlock::Text(text) = content_block {\n                has_text = true;\n                extracted_text.push_str(text);\n            }\n        }","sourceCodeStart":668,"sourceCodeEnd":704,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs#L668-L704","documentation":"After calling Bedrock Converse, chat_anyhow expects response.output to be the ConverseOutput::Message variant. Any other variant (or None) means the model didn't return a message output, so the client bails. Note the current implementation always formats the type as the literal 'unknown', so the error doesn't tell you which variant it actually saw.","triggerScenarios":"Bedrock Converse returns output other than a message — e.g. the response is empty, the request was consumed by a guardrail, or the model produced a non-message output type — while calling chat on an aws-bedrock client.","commonSituations":"Guardrails intercepting the response; model misconfiguration where the invoked model ID doesn't support Converse message output; transient empty responses from the service.","solutions":["Check AWS guardrail configuration for the model — guardrail-intervened outputs are not returned as message output.","Verify the model ID in client options supports the Converse API and returns message outputs.","Retry the request; if persistent, enable logging/dumping the raw ConverseOutput to see the actual variant."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = baml_client.MyFunction(...)\nexcept Exception as e:\n    if 'Expected message output in response' in str(e):\n        log_raw_converse_output(...)  # inspect guardrails/stop reason\n        out = retry_with_backoff(baml_client.MyFunction, ...)\n    else:\n        raise","preventionTips":["Audit AWS guardrail configs that can replace message output","Confirm the model ID supports Converse message outputs","Log StopReason and raw responses for Bedrock calls in staging"],"tags":["aws","bedrock","response","unexpected-shape"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}