microsoft/semantic-kernel · warning · RuntimeError
No chart generated
Error message
No chart generated
What it means
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.
Source
Thrown at python/samples/concepts/agents/bedrock_agent/bedrock_agent_with_code_interpreter.py:58
try:
# Invoke the agent
async for response in bedrock_agent.invoke(
messages=ASK,
thread=thread,
):
print(f"Response:\n{response}")
thread = response.thread
if not binary_item:
binary_item = next((item for item in response.items if isinstance(item, BinaryContent)), None)
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 (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.
Example fix
# before
if not binary_item:
raise RuntimeError("No chart generated")
# after - graceful fallback, log what came back
if not binary_item:
print("No chart was produced. Response items:")
for item in response.items:
print(repr(item))
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 response.items if isinstance(i, BinaryContent)), None)
binary_item = find_binary(response)
if binary_item is None:
print("No chart produced; items:", [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:
# ... run agent, capture binary_item ...
if not binary_item:
raise RuntimeError("No chart generated")
except RuntimeError:
# degrade gracefully: show the textual response instead
pass Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No chart generated
- Invalid operator
- Invalid filename: would write outside the expected directory
- Invalid filename: would write outside the expected directory
- Message role must be either Assistant or User.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/9d2d220c185785d4.
Report an issue: GitHub.