Skip to content

Empty responses from Claude 3 Haiku on Bedrock

0

I am using Claude 3 Haiku on Bedrock (Model ID: anthropic.claude-3-haiku-20240307-v1:0). I use it to generate MySQL queries from the natural language questions of a user. The system prompts consist of a large text with information about the tables in my database including table schema, join hints and examples. Recently, I have been receiving empty responses from the model with HTTPS status 200. The assistant response is a blank array ([]) with around 3 output tokens. I have tried changing the model prompts and parameters, to no avail.

These empty responses are returned randomly. The same exact user prompt on separate occasions can return either empty response or the correct output. I did not notice a pattern in the kind of user prompts that generate such responses.

I use the converse API to generate responses from the model in two steps:

  1. Converse is first used to determine the domain of user prompt.
  2. That domain is extracted from the model response and used to select a system prompt for that domain from the list of prompts of all domains. This system prompt is then sent to the model along with the user prompt to generate the SQL query.

The problem of empty responses started when I added the model's response for the domain detection as part of the system prompt for SQL query generation. I need the domain detection response to influence the SQL query generation in multi-turn conversations. Removing it reduces the quality of multi-turn conversations drastically.

My input tokens have remained in the 3000-5000 token range both before and after making the above change.

Following are the model configurations:

maxTokens: 1024,

temperature: 0.2,

topP: 0.8

I have set the temperature and topP to those values to make sure that the model does not stray away from the defined table schemas.

Edit: I have experimented with different topP values and implemented a retry logic to converse with the model two more times with a 1 second delay between each retry. None of these solved the problem.

Edit 2: Removed domain response from system prompts. Now after applying proper formatting to remove special characters, I only send it as an 'assistant' message in the messages parameter of Converse API. Also updated formatting of the prompts as per AWS Bedrock prompt template for code generation and this GitHub repo from AWS samples for generating SQL queries with Bedrock. This did not solve the problem either.

1 Answer
1

The empty responses you're experiencing with Claude 3 Haiku on Bedrock appear to be an intermittent issue that several users have encountered with different models on the platform. Based on your description, here are some insights and potential solutions:

  1. Inconsistent Model Behavior: The fact that identical prompts sometimes work and sometimes return empty responses suggests this is likely a model or API behavior issue rather than something fundamentally wrong with your prompts.

  2. Response Format Issues: When you receive these empty responses, you're getting a blank array ([]) with around 3 output tokens. This indicates the model is responding but not generating content.

  3. Potential Causes:

  • The inclusion of the domain detection response in your system prompt might be creating formatting issues or confusing the model
  • There could be subtle differences in how the Bedrock API processes your requests compared to direct model access
  • Token counting might be different than expected, potentially approaching limits
  1. Possible Solutions:
  • Implement retry logic to handle empty responses
  • Try adjusting your prompt formatting to ensure it follows the exact guidelines for Claude models on Bedrock
  • Consider restructuring how you include the domain detection information (perhaps as a separate message rather than embedding it in the system prompt)
  • Experiment with slightly different temperature or top_p settings
  • Check if there are any special characters or formatting in your domain detection responses that might be causing issues when included in subsequent prompts
  1. Parameter Considerations: Your current settings (temperature: 0.2, topP: 0.8, maxTokens: 1024) seem reasonable for your use case. The low temperature should indeed help keep responses focused on your schema information.

If the issue persists, you might want to reach out to AWS support as this appears to be a known issue with various models on the Bedrock platform that might require investigation from their side.
Sources
Amazon Bedrock with Claude Sonnet 3.5 is not working the same as when I access Claude directly | AWS re:Post
Bedrock Llama 3 empty string response problem | AWS re:Post
Request and Response - Amazon Bedrock
Community | Customizing AI Behavior: System prompts and inference parameters in Bedrock's Converse API

answered a year ago

EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.