I need to create a tool that retrieves a PDF and returns it to the LLM.
Configuration
- LLM Provider: ChatBedrock
- Model: Anthropic Claude Sonnet 3.5 v2
- Agent Type: React Agent
Currently, my tool looks like this:
import base64
from langchain_core.tools import tool
@tool
def get_pdf():
"""
Search on PDF information
"""
pdf_path = "/sample/sample"
with open(pdf_path, "rb") as pdf_file:
pdf_data = base64.b64encode(pdf_file.read()).decode("utf-8")
return [
{
"type": "file",
"source_type": "base64",
"data": pdf_data,
"mime_type": "application/pdf",
},
]
Problem
When running this, I get the following error:
{"error":"An error occurred (ValidationException) when calling the InvokeModel operation: Input is too long for requested model."}
This makes me think that toolMessage
is passing the PDF as plain text instead of sending it as a proper file.