microsoft/semantic-kernel · warning · RuntimeError
No chart generated
Error message
No chart generated
What it means
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.
Source
Thrown at python/samples/concepts/agents/bedrock_agent/bedrock_agent_with_code_interpreter_streaming.py:60
# Invoke the agent
print("Response: ")
async for response in bedrock_agent.invoke_stream(
messages=ASK,
thread=thread,
):
print(response, end="")
thread = response.thread
if not binary_item:
binary_item = next((item for item in response.items if isinstance(item, BinaryContent)), None)
print()
finally:
# Delete the agent
await bedrock_agent.delete_agent()
await thread.delete() if thread else None
# Save the chart to a file
if not binary_item:
raise RuntimeError("No chart generated")
# Securely assemble the file path and validate it's within the expected directory
# This is a defense-in-depth measure against directory traversal attacks
output_dir = Path(__file__).parent.resolve()
file_path = (output_dir / binary_item.metadata["name"]).resolve()
# Verify the resolved path is within the expected directory
if not file_path.is_relative_to(output_dir):
raise RuntimeError("Invalid filename: would write outside the expected directory")
binary_item.write_to_file(file_path)
print(f"Chart saved to {file_path}")
# Sample output (using anthropic.claude-3-haiku-20240307-v1:0):
# Response:
# Here is the bar chart for the given data:
# [A bar chart showing the following data:
# Panda 5View on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before
if not binary_item:
raise RuntimeError("No chart generated")
# after
if not binary_item:
print("No chart produced by the code interpreter.")
return Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.contents import BinaryContent
def find_binary(response) -> BinaryContent | None:
return next((i for i in getattr(response, "items", []) if isinstance(i, BinaryContent)), None)
binary_item = find_binary(response)
if binary_item is None:
print("No chart produced during stream; item types:",
[type(i).__name__ for i in response.items])
return Type guard
from semantic_kernel.contents import BinaryContent
def has_binary_content(response) -> bool:
return any(isinstance(i, BinaryContent) for i in getattr(response, "items", [])) Try / catch
try:
# ... consume stream, capture binary_item ...
if not binary_item:
raise RuntimeError("No chart generated")
except RuntimeError:
# print whatever was streamed and exit gracefully
pass Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- No chart generated
- Invalid filename: would write outside the expected directory
- Failed to handle Bedrock Agent stream event.
- Failed to handle Bedrock Agent stream event: {responseEvent}
- Invalid operator
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/341b8cc7f2deb893.
Report an issue: GitHub.