{"record":{"id":"9d2d220c185785d4","repo":"microsoft/semantic-kernel","slug":"no-chart-generated","errorCode":null,"errorMessage":"No chart generated","messagePattern":"No chart generated","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"warning","filePath":"python/samples/concepts/agents/bedrock_agent/bedrock_agent_with_code_interpreter.py","lineNumber":58,"sourceCode":"\n    try:\n        # Invoke the agent\n        async for response in bedrock_agent.invoke(\n            messages=ASK,\n            thread=thread,\n        ):\n            print(f\"Response:\\n{response}\")\n            thread = response.thread\n            if not binary_item:\n                binary_item = next((item for item in response.items if isinstance(item, BinaryContent)), None)\n    finally:\n        # Delete the agent\n        await bedrock_agent.delete_agent()\n        await thread.delete() if thread else None\n\n    # Save the chart to a file\n    if not binary_item:\n        raise RuntimeError(\"No chart generated\")\n\n    # Securely assemble the file path and validate it's within the expected directory\n    # This is a defense-in-depth measure against directory traversal attacks\n    output_dir = Path(__file__).parent.resolve()\n    file_path = (output_dir / binary_item.metadata[\"name\"]).resolve()\n\n    # Verify the resolved path is within the expected directory\n    if not file_path.is_relative_to(output_dir):\n        raise RuntimeError(\"Invalid filename: would write outside the expected directory\")\n\n    binary_item.write_to_file(file_path)\n    print(f\"Chart saved to {file_path}\")\n\n    # Sample output (using anthropic.claude-3-haiku-20240307-v1:0):\n    # Response:\n    # Here is the bar chart for the given data:\n    # [A bar chart showing the following data:\n    # Panda   5","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/concepts/agents/bedrock_agent/bedrock_agent_with_code_interpreter.py#L40-L76","documentation":"RuntimeError raised in the Bedrock code-interpreter sample after the agent run, when no BinaryContent item was found among the response.items (the binary_item variable stayed None). It is sample plumbing, not a library error: it signals the model never produced a downloadable file (e.g. the chart) for the turn. The agent and thread are already deleted in the finally block before this check.","triggerScenarios":"Running the sample, the Bedrock agent completes its turn but returns no BinaryContent in response.items (the model produced only text, declined to run code, or the code-interpreter session yielded no file). binary_item stays None and the post-run check raises.","commonSituations":"The model answered in prose without invoking the code interpreter; the prompt did not clearly request a file; the Bedrock agent's action group lacks the code-interpreter tool; or an upstream Bedrock error silently produced an empty items list.","solutions":["Make the prompt explicitly request a chart/file so the code interpreter runs (the sample expects a bar chart).","Verify the Bedrock agent configuration enables the code interpreter action group.","Inspect response.items before deletion (move logging before the finally delete) to see whether text or tool messages came back instead of a file.","Treat the error as informational: catch RuntimeError and fall back to printing the text response."],"exampleFix":"# before\nif not binary_item:\n    raise RuntimeError(\"No chart generated\")\n# after - graceful fallback, log what came back\nif not binary_item:\n    print(\"No chart was produced. Response items:\")\n    for item in response.items:\n        print(repr(item))\n    return","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents import BinaryContent\n\ndef find_binary(response) -> BinaryContent | None:\n    return next((i for i in response.items if isinstance(i, BinaryContent)), None)\n\nbinary_item = find_binary(response)\nif binary_item is None:\n    print(\"No chart produced; items:\", [type(i).__name__ for i in response.items])\n    return","typeGuard":"from semantic_kernel.contents import BinaryContent\ndef has_binary_content(response) -> bool:\n    return any(isinstance(i, BinaryContent) for i in getattr(response, \"items\", []))","tryCatchPattern":"try:\n    # ... run agent, capture binary_item ...\n    if not binary_item:\n        raise RuntimeError(\"No chart generated\")\nexcept RuntimeError:\n    # degrade gracefully: show the textual response instead\n    pass","preventionTips":["Make prompts explicitly request a file/chart so the code interpreter runs.","Confirm the Bedrock agent's action group has the code interpreter enabled.","Log response.items before deleting the agent so failures are diagnosable."],"tags":["python","sample","bedrock","agents"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}