{"record":{"id":"341b8cc7f2deb893","repo":"microsoft/semantic-kernel","slug":"no-chart-generated-341b8c","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_streaming.py","lineNumber":60,"sourceCode":"        # Invoke the agent\n        print(\"Response: \")\n        async for response in bedrock_agent.invoke_stream(\n            messages=ASK,\n            thread=thread,\n        ):\n            print(response, end=\"\")\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        print()\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":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/concepts/agents/bedrock_agent/bedrock_agent_with_code_interpreter_streaming.py#L42-L78","documentation":"Identical logic to error 625 but in the streaming variant of the Bedrock code-interpreter sample. After consuming the streamed response and deleting the agent/thread, if no BinaryContent was captured into binary_item during the stream, the sample raises RuntimeError to indicate the model produced no downloadable chart.","triggerScenarios":"Streaming the Bedrock agent turn and never observing an item of type BinaryContent in response.items (model produced text only, did not run code, or the code interpreter returned no file).","commonSituations":"Prompt did not clearly request a chart; code-interpreter action group not enabled on the agent; the model finished the turn before emitting a file; or an upstream Bedrock streaming error produced no binary frame.","solutions":["Make the prompt explicitly request a chart/file so the code interpreter runs.","Verify the Bedrock agent's action group enables the code interpreter tool.","Log response.items inside the stream loop (before the finally delete) to see what the model actually returned.","Catch RuntimeError and degrade gracefully to printing the streamed text."],"exampleFix":"# before\nif not binary_item:\n    raise RuntimeError(\"No chart generated\")\n# after\nif not binary_item:\n    print(\"No chart produced by the code interpreter.\")\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 getattr(response, \"items\", []) if isinstance(i, BinaryContent)), None)\n\nbinary_item = find_binary(response)\nif binary_item is None:\n    print(\"No chart produced during stream; item types:\",\n          [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    # ... consume stream, capture binary_item ...\n    if not binary_item:\n        raise RuntimeError(\"No chart generated\")\nexcept RuntimeError:\n    # print whatever was streamed and exit gracefully\n    pass","preventionTips":["Request a chart explicitly in the prompt so the code interpreter emits a file.","Verify the Bedrock agent enables the code interpreter action group.","Capture and log streamed items as they arrive, before the finally block deletes the agent."],"tags":["python","sample","bedrock","agents","streaming"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}