#1542·aichat

Bedrock: tool results with non-object JSON output are rejected (toolResult.content[].json must be an object)

Author: sjanotaCreated Aug 19, 2026Updated Aug 19, 2026

Describe the bug With the bedrock client, any tool whose output is a top-level JSON array (or string/number/null) makes the follow-up request fail. Bedrock's Converse API requires the value under toolResult.content[].json to be a JSON object, but aichat always places the raw tool output there. This breaks MCP/function-calling tools that don't return an object. The same tools work on the Anthropic-native client.

To Reproduce

  1. Configure a bedrock client and set function_calling: true, use_tools: all.
  2. Register a tool that returns a top-level JSON array. Reproduced via the MCP atlassian server's getAccessibleAtlassianResources, which returns a list.
  3. Run a prompt that invokes the tool: aichat 'list JIRA issues in project reported by '
  4. Approve the tool call. The tool executes, but sending its result back to the model fails.

Root cause — src/client/bedrock.rs unconditionally wraps output in a json block: "content": [ { "json": tool_result.output } ]. tool_result.output is a serde_json::Value of any type, but per the Bedrock Converse ToolResultContentBlock the json member must be an object.

Proposed fix — use json only for objects, else fall back to a text block:

+                        let tool_result_content = if tool_result.output.is_object() {
+                            json!({ "json": tool_result.output })
+                        } else {
+                            json!({ "text": tool_result.output.to_string() })
+                        };
                         user_parts.push(json!({
                             "toolResult": {
                                "toolUseId": tool_result.call.id,
-                                "content": [
-                                    {
-                                        "json": tool_result.output,
-                                    }
-                                ]
+                                "content": [tool_result_content]
                             }
                         }));

Happy to open a PR.

Expected behavior Tool results are accepted regardless of the JSON shape the tool returns, as on the Anthropic-native client.

Logs

Call atlassian_getaccessibleatlassianresources {}
Are you sure you want to continue? [Y/n]
Error: Failed to call chat-completions api

Caused by:
    The format of the value at messages.2.content.0.toolResult.content.0.json is invalid. Provide a json object for the field and try again.

Screenshots N/A

Configuration

aichat --info

model bedrock:sonnet use_tools all function_calling true stream true save true config_file ~/Library/Application Support/aichat/config.yaml functions_dir ~/Library/Application Support/aichat/functions (bedrock client with global.* inference profiles; credentials supplied at runtime via BEDROCK_* env vars)

Environment (please complete the following information):

  • os version: macOS 15
  • aichat version: 0.30.0 (built from main, commit 82976d34)
  • terminal version: iTerm2 3.6.11

Additional context Bedrock-specific: the Anthropic-native client tolerates non-object tool output, so this only affects type: bedrock. Any array-returning tool triggers it; MCP tools (via llm-functions mcp-bridge) are a common source since many MCP tools return arrays.