Logo

dev-resources.site

for different kinds of informations.

AWS Bedrock Claude 2.1 - Return only JSON

Published at
12/7/2023
Categories
aws
bedrock
claude
Author
mmuller88
Categories
3 categories in total
aws
open
bedrock
open
claude
open
Author
9 person written this
mmuller88
open
AWS Bedrock Claude 2.1 - Return only JSON

Working with the AWS Bedrock API is an exhilarating experience! I came across an interesting business case where I needed to develop an AI MVP. The MVP generates JSON data based on a prompt and utilizes the anthropic.claude-v2:1 model in AWS Bedrock.

I encountered an issue where the response I received was not pure JSON. It contained additional characters that I couldn't remove like:



" format: {\"one\":\"Supplier\",\"many\":\"Time\"}"


Enter fullscreen mode Exit fullscreen mode

Seeking help from the AWS Community, I was able to find a solution to this problem. In this post, I will share the solution with you.

The Problem



Human: $YOUR_PROMPT . Answer in JSON formatAssistant:{,


Enter fullscreen mode Exit fullscreen mode

This technique is known as "Put words in Claude’s mouth". It involves providing a prompt to Claude and letting it generate the rest of the response on its own. While there may be alternative approaches to solving this issue, I am currently happy with this solution.

Thanks

I would like to express my gratitude to the AWS Community for their invaluable assistance in helping me resolve this issue.

A special thanks goes to Corvus Lee for providing the advice that ultimately solved the problem.

I would also like to thank Ken Collins for bringing the Claude 2 docs sheet to my attention.

Once again, thank you all for your support and contributions.

Conclusion

Working with AWS Bedrock AI is incredibly enjoyable. The field is constantly evolving, and there is always something new to learn. In this post, I demonstrated how to obtain a pure JSON response from AWS Bedrock Claude 2.1. As AI technology continues to advance rapidly, you may not encounter this issue in the future. However, if you are working with Claude 2.1 or newer, be sure to refer to the documentation for more information.

I hope you found this post helpful, and I look forward to sharing more with you in the future.

I love to work on Open Source projects. A lot of my stuff you can already use on https://github.com/mmuller88 . If you like my work there and my blog posts, please consider supporting me on the:

Buy me a Ko-Fi

OR

Buy me a Ko-Fi

And don't forget to visit my site

martinmueller.dev

claude Article's
29 articles in total
Favicon
Integrating Locally running Postgres with Claude Desktop
Favicon
Write tools for LLMs with go - mcp-golang
Favicon
MCP using node on asdf
Favicon
Modify the local bolt.new interface to allow input of the API key
Favicon
Enabling Application Downloads in Local bolt.new
Favicon
Running bolt.new Locally
Favicon
In the Beginning...
Favicon
Dario Amodei: Anthropic CEO on Claude, AGI & the Future of AI & Humanity | Podcast Summary
Favicon
Certainly! Absolutely! I apologize!
Favicon
Claude prompting guide - General tips for effective prompting
Favicon
How I used ChatGPT o1 and Claude for generating a SQL RBAC report and was surprised by the results
Favicon
How to use AI for coding the right way
Favicon
Using Cursor + Claude to Make Full-Stack SaaS Apps
Favicon
Exploring Anthropic Claude: A Safe and Ethical AI Assistant
Favicon
Claude 3.5 API Introductory Tutorial
Favicon
Unlocking Rapid Data Extraction: Groq + OCR and Claude Vision
Favicon
Free AI Chat and AI Art
Favicon
Optimising Function Calling (GPT4 vs Opus vs Haiku vs Sonnet)
Favicon
DEMO - Voice to PDF - Complete PDF documents with voice commands using the Claude 3 Opus API
Favicon
Claude LLM - Pros and Cons Compared with Other LLMs
Favicon
Is Claude Self Aware
Favicon
Guide to Effective Prompt Engineering for ChatGPT and LLM Responses
Favicon
AI powered video summarizer with Amazon Bedrock and Anthropic’s Claude
Favicon
Claude 2.1 Unleashed: The AI Revolution That's Outshining GPT-4
Favicon
AWS Bedrock Claude 2.1 - Return only JSON
Favicon
Claude: 10 Minute Docs Audit
Favicon
New Discoveries in No-Code AI App Building with ChatGPT
Favicon
Meet Claude - The AI Assistant That Understands The World Like You Do
Favicon
La IA de Anthropic, Claude, Supera a ChatGPT

Featured ones: