microsoft/semantic-kernel · error · ArgumentException
Response is null
Error message
Response is null
What it means
Thrown by BedrockTextGenerationClient when InvokeModelAsync returned a response that is null or whose Body is null (non-throwing but empty). It is an ArgumentException guarding the GetInvokeResponseBody parse step in the text-generation (InvokeModel) path.
Source
Thrown at dotnet/src/Connectors/Connectors.Amazon/Bedrock/Core/Clients/BedrockTextGenerationClient.cs:110
if (activity is not null)
{
activity.SetError(ex);
if (response != null)
{
activityStatus = BedrockClientUtilities.ConvertHttpStatusCodeToActivityStatusCode(response.HttpStatusCode);
activity.SetStatus(activityStatus);
}
else
{
// If response is null, set a default status or leave it unset
activity.SetStatus(ActivityStatusCode.Error); // or ActivityStatusCode.Unset
}
}
throw;
}
if ((response == null) || (response.Body == null))
{
throw new ArgumentException("Response is null");
}
activityStatus = BedrockClientUtilities.ConvertHttpStatusCodeToActivityStatusCode(response.HttpStatusCode);
activity?.SetStatus(activityStatus);
IReadOnlyList<TextContent> textResponse = this._ioTextService.GetInvokeResponseBody(response);
activity?.SetCompletionResponse(textResponse);
return textResponse;
}
internal async IAsyncEnumerable<StreamingTextContent> StreamTextAsync(
string prompt,
PromptExecutionSettings? executionSettings = null,
Kernel? kernel = null,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
Verify.NotNullOrWhiteSpace(prompt);
var requestBody = this._ioTextService.GetInvokeModelRequestBody(this._modelId, prompt, executionSettings);
var invokeRequest = new InvokeModelWithResponseStreamRequest
{View on GitHub (pinned to c028a0c7dc)
Solutions
- Confirm modelId is a Bedrock text-generation model and is enabled in the region.
- Retry once on this ArgumentException; empty bodies can be transient.
- Wrap the text-generation call in try/catch (ArgumentException) and log modelId + region.
- Check the model's content-filter/guardrail configuration.
Example fix
// before
var text = await textGen.GetTextContentAsync("prompt", settings);
// after
try
{
var text = await textGen.GetTextContentAsync("prompt", settings);
}
catch (ArgumentException ex) when (ex.Message == "Response is null")
{
throw new InvalidOperationException($"Bedrock returned an empty body for text model '{modelId}'.", ex);
} Defensive patterns
Strategy: try-catch
Try / catch
try { var text = await textGen.GetTextContentAsync(prompt, settings, ct); }
catch (ArgumentException ex) when (ex.Message == "Response is null")
{ throw new InvalidOperationException($"Bedrock returned an empty body for text model '{modelId}'.", ex); } Prevention
- Use a Bedrock text-generation modelId enabled in the region.
- Retry once on transient empty bodies.
- Log modelId and HTTP status via SK diagnostics.
When it happens
Trigger: Text generation (non-streaming) call where the Bedrock InvokeModel response had no Body. Occurs with a model id the runtime accepts but returns an empty body for, content-policy interventions, or transient empty responses.
Common situations: Using a non-text model id in the text-generation path. Model not enabled in region. Content filter emptying the response. Transient transport anomaly.
Related errors
- Response failed
- Response is null
- An error occurred while initializing the {nameof(BedrockText
- Message role must be either Assistant or User.
- runtimeClient
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/77f6cd7d2b1731f4.
Report an issue: GitHub.