BEDROCK LLAMA 3.3 70B keeps returning response in markdown although it is specified to be in JSON

0

I am using the LLAMA 3 70B model on a project, and in my prompts i have specified it to return the response in JSON format. I have it this way so that my response can be in a controlled format. I used the system and user tags(https://www.llama.com/docs/model-cards-and-prompt-formats/llama3_3/) in my prompt to ensure that integrity of the response adheres to JSON format. However, when ever the model generates a response, it takes a 50/50 approach by producing some in JSON and others in markdown. This is tends to break the execution as the underlycode is not programmed to deal with markdown text.

1 Answer
0

The issue you're experiencing with Llama 3 70B on AWS Bedrock, where responses are inconsistently formatted between JSON and Markdown, is a known problem that others have encountered as well. This inconsistency can indeed cause issues with code execution when expecting a specific format.

To address this problem, consider the following approaches:

  1. Double-check your prompt format: Ensure that you're using the correct prompt structure for Llama 3 models. The prompt should start with "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n", followed by your actual prompt content, and end with "<|start_header_id|>assistant<|end_header_id|>\n\n".

  2. Be explicit in your instructions: In your prompt, be very specific about the desired output format. For example, you could include instructions like "Respond only in valid JSON format. Do not use Markdown or any other formatting."

  3. Use a wrapper or post-processing: Implement a wrapper function or post-processing step that attempts to parse the response as JSON. If parsing fails, you could either retry the request or have a fallback mechanism to handle non-JSON responses.

  4. Adjust model parameters: Experiment with different temperature and top_p settings. Lower values might lead to more consistent outputs, though at the cost of reduced creativity.

  5. Consider using a different model: If the inconsistency persists and is causing significant issues in your application, you might want to explore other models available in Bedrock that may provide more consistent JSON outputs.

  6. Implement retry logic: When you receive a non-JSON response, you could implement logic to retry the request, potentially with a slightly modified prompt emphasizing the need for JSON output.

If these approaches don't resolve the issue, it may be worth reaching out to AWS support for further assistance, as they might have additional insights or be able to investigate any potential issues with the model's implementation in Bedrock.
Sources
Bedrock Llama 3 empty string response problem | AWS re:Post
Llama 3 providing empty response and string response instead of JSON | AWS re:Post

profile picture
answered 20 days 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.

Guidelines for Answering Questions