microsoft/semantic-kernel · error · InvalidOperationException
No file found in the response.
Error message
No file found in the response.
What it means
After invoking a Bedrock agent configured with a code interpreter, the code scans the response chunks for BinaryContent items. If no BinaryContent was found across all chunks (binaryContent remains null), it throws InvalidOperationException. This indicates the agent's response did not contain any file output, which the sample expects.
Source
Thrown at dotnet/samples/GettingStartedWithAgents/BedrockAgent/Step02_BedrockAgent_CodeInterpreter.cs:54
try
{
BinaryContent? binaryContent = null;
var responses = bedrockAgent.InvokeAsync(new ChatMessageContent(AuthorRole.User, UserQuery), bedrockAgentThread, null);
await foreach (ChatMessageContent response in responses)
{
if (response.Content != null)
{
this.Output.WriteLine(response.Content);
}
if (binaryContent == null && response.Items.Count > 0)
{
binaryContent = response.Items.OfType<BinaryContent>().FirstOrDefault();
}
}
if (binaryContent == null)
{
throw new InvalidOperationException("No file found in the response.");
}
// Save the file to the same directory as the test assembly
var filePath = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!,
binaryContent.Metadata!["Name"]!.ToString()!);
this.Output.WriteLine($"Saving file to {filePath}");
binaryContent.WriteToFile(filePath, overwrite: true);
// Expected output:
// Here is the bar chart for the given data:
// [A bar chart showing the following data:
// Panda 5
// Tiger 8
// Lion 3
// Monkey 6
// Dolphin 2]
// Saving file to ...View on GitHub (pinned to c028a0c7dc)
Solutions
- Ensure the prompt explicitly asks for a file or computation that triggers the code interpreter (e.g., 'Create a bar chart of this data').
- Verify the Bedrock agent has a code interpreter action group enabled and properly configured.
- Check the response chunks for text content — the agent may have responded with an explanation instead of a file.
- Handle the null case gracefully by reporting the text response instead of throwing.
Example fix
// before
if (binaryContent == null)
{
throw new InvalidOperationException("No file found in the response.");
}
// after — fall back to text content and warn
if (binaryContent == null)
{
this.Output.WriteLine("No file was generated. The agent may have responded with text only.");
return;
} Defensive patterns
Strategy: validation
Validate before calling
// Check response items for binary content without throwing
var binaryContent = responses.SelectMany(r => r.Items).OfType<BinaryContent>().FirstOrDefault();
if (binaryContent is null)
{ Console.WriteLine("No file in response. The agent responded with text only."); return; } Type guard
bool HasBinaryContent(ChatMessageContentResponse r) => r.Items.OfType<BinaryContent>().Any();
Try / catch
try { /* invoke agent and save file */ } catch (InvalidOperationException ex) when (ex.Message == "No file found in the response.") { Console.WriteLine("Agent did not produce a file; check the prompt and code interpreter config."); } Prevention
- Ensure the prompt explicitly requests file/chart output to trigger the code interpreter.
- Verify the Bedrock agent has a code interpreter action group enabled.
- Handle the no-file case gracefully by reporting text content.
When it happens
Trigger: Invoking a Bedrock agent with code interpreter enabled, but the agent's response contained no file/binary output — e.g., the agent answered with text only, the code interpreter tool wasn't triggered, or the file generation failed server-side.
Common situations: The prompt didn't request a file/chart/ computation, so the agent responded with text only; the Bedrock code interpreter action group wasn't properly configured; the agent didn't decide to use the code interpreter tool; a transient Bedrock-side issue prevented file generation; the response items were consumed/iterated differently so BinaryContent was missed.
Related errors
- The Bedrock agent requires a message to be invoked.
- The streaming configuration must be null for non-streaming r
- The streaming configuration must have StreamFinalResponse se
- Bedrock agents must be invoked with a user message
- Invalid role: {authorRole}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/7aabcc49962d4fc2.
Report an issue: GitHub.