Using Document Chat with the Amazon Bedrock Converse API

Using Document Chat with the Amazon Bedrock Converse API

Learn the basics of using Amazon Bedrock Converse API document chat to directly pass PDF, text, HTML, and other file formats directly to Amazon Bedrock.

Jason Stehle
Amazon Employee
Published Jun 25, 2024


In a previous article, I provided a quick tutorial on the Amazon Bedrock Converse API. In this article, I will walk through a simple document chat example to illustrate how it works.
The Converse API provides a consistent way to access large language models (LLMs) on Amazon Bedrock. It supports turn-based messages between the user and the generative AI model. It also provides convenient structures for supporting image and document data types.
Document chat is a capability that allows the developer to send a document directly to Amazon Bedrock without needing to first extract the text of the document. I recommend using document chat with the following formats:
  • PDF
  • HTML
  • Word (.docx, .doc)
  • Markdown (.md)
  • Text (.txt)
Note that you will likely have the most success using document chat with flowing text formats. For example, don't expect embedded images in a PDF to be included along with the text, or tabular information to come through cleanly.

Setting up your development environment and AWS account

You’ll want to have the latest AWS SDK and Amazon Bedrock model access configured before proceeding:


  • Large language models are non-deterministic. You should expect different results than those shown in this article.
  • If you run this code from your own AWS account, you will be charged for the tokens consumed.
  • I generally subscribe to a “Minimum Viable Prompt” philosophy. You may need to write more detailed prompts for your use case.
  • Not every model supports all of the capabilities of the Converse API, so it’s important to review the supported model features in the official documentation.

Code walkthrough: using Document Chat with the Amazon Bedrock Converse API

Define dependencies and initiate the Boto3 session

Read a document and add it to a message

NOTE: The code below requires a local PDF-format file named “amazon-leadership-principles-070621-us.pdf”. You can download this file from the Amazon Leadership Principles page, or alter the code to use a document of your choosing. See the Converse API DocumentBlock documentation for the list of supported document formats.

Call the Amazon Bedrock Converse API

Review the model’s response

This will generate a response similar to the following:
Based on the leadership principles outlined in the document, I believe the most important one for an intern to adopt at the start of their career is "Learn and Be Curious".
Here's why I think this principle is particularly crucial for someone just starting out:
  1. As an intern or someone new to the workforce, there is a vast amount to learn - about the company, the industry, professional skills, and more. Having a mindset of continuous learning and curiosity will allow the intern to soak up as much knowledge and experience as possible during this formative stage.
  2. The principle states "Leaders are never done learning and always seek to improve themselves." This growth mindset is invaluable early in one's career when the potential for development is immense.
  3. Being curious about "new possibilities and acting to explore them" as mentioned in the principle can open doors to new opportunities, projects, and career paths that the intern may not have initially considered.
  4. Many of the other principles like "Customer Obsession", "Invent and Simplify", and "Think Big" require a foundation of learning, curiosity, and always seeking to improve oneself.
While all the leadership principles are important, embracing a mindset of continuous learning and curiosity can set an intern up for success by allowing them to rapidly acquire new skills, adapt to new situations, and uncover new avenues for growth and development in their early career stage.


I hope this gave you a good sense of how Amazon Bedrock Converse API's new document chat capability can help simplify handling documents with Amazon Bedrock!

Learn more

Continue reading articles about the Amazon Bedrock Converse API:

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

1 Comment