{"record":{"id":"e59052e171724dff","repo":"crewAIInc/crewAI","slug":"failed-to-extract-completion-json-dumps-debug-in","errorCode":null,"errorMessage":"Failed to extract completion: {json.dumps(debug_info, indent=2)}","messagePattern":"Failed to extract completion: (.+?)","errorType":"exception","errorClass":"BedrockAgentError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/aws/bedrock/agents/invoke_agent_tool.py","lineNumber":157,"sourceCode":"            # If no completion found in streaming format, try direct format\n            if not completion and \"chunk\" in response and \"bytes\" in response[\"chunk\"]:\n                chunk_bytes = response[\"chunk\"][\"bytes\"]\n                if isinstance(chunk_bytes, (bytes, bytearray)):\n                    completion = chunk_bytes.decode(\"utf-8\")\n                else:\n                    completion = str(chunk_bytes)\n\n            # If still no completion, return debug info\n            if not completion:\n                debug_info = {\n                    \"error\": \"Could not extract completion from response\",\n                    \"response_keys\": list(response.keys()),\n                }\n\n                if \"chunk\" in response:\n                    debug_info[\"chunk_keys\"] = list(response[\"chunk\"].keys())\n\n                raise BedrockAgentError(\n                    f\"Failed to extract completion: {json.dumps(debug_info, indent=2)}\"\n                )\n\n            return completion\n\n        except ClientError as e:\n            error_code = \"Unknown\"\n            error_message = str(e)\n\n            # Try to extract error code if available\n            if hasattr(e, \"response\") and \"Error\" in e.response:\n                error_code = e.response[\"Error\"].get(\"Code\", \"Unknown\")\n                error_message = e.response[\"Error\"].get(\"Message\", str(e))\n\n            raise BedrockAgentError(f\"Error ({error_code}): {error_message}\") from e\n        except BedrockAgentError:\n            # Re-raise BedrockAgentError exceptions\n            raise","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/aws/bedrock/agents/invoke_agent_tool.py#L139-L175","documentation":"A BedrockAgentError raised after a successful InvokeAgentWithResponseStream call when the response chunks could not be parsed into a completion — the streamed 'chunk' bytes did not decode/extract into text and `completion` stayed empty. The message embeds a debug_info JSON dump listing the response's top-level keys and, if present, the chunk's keys, to show what shape actually arrived.","triggerScenarios":"Invoking the tool against a Bedrock agent whose response stream contains an unexpected event/chunk structure — e.g. a new response section, a trace-only event with no completion, an access-denied partial response, or a model returning binary/metadata chunks the extraction logic (chunk_bytes -> str) does not handle.","commonSituations":"AWS changes the InvokeAgent stream event format; agent configured to return only trace/citation events; enabling enable_trace changes the chunk mix; regional model behavior differences. The JSON keys dump is the primary debugging artifact.","solutions":["Inspect the JSON in the message: response_keys/chunk_keys show the actual event shape — compare with the expected 'chunk'.'bytes' path.","Update crewai-tools to the latest version in case the extraction was patched for a newer stream format.","Retry once — transient partial streams (network interruption mid-stream) can produce empty completions.","If chunk_keys lack 'bytes', check the agent's configuration (traces, return-of-control) in the Bedrock console."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from crewai_tools.aws.bedrock.agents.invoke_agent_tool import BedrockAgentError\n\nfor attempt in range(2):\n    try:\n        return tool._run(query)\n    except BedrockAgentError as e:\n        if \"Failed to extract completion\" in str(e) and attempt == 0:\n            continue  # transient empty stream — retry once\n        raise","preventionTips":["Keep crewai-tools updated so stream-parsing matches current AWS event shapes.","Reproduce with a minimal agent (no trace) to isolate whether trace/citation events cause empty completions.","Capture the embedded debug_info JSON when reporting — it contains the actual response keys."],"tags":["aws","bedrock","streaming","parsing","runtime"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}