Open
Description
Testing both structured output and tool calling provide the same error: An error occurred (ModelErrorException) when calling the Converse operation: The system encountered an unexpected error during processing. Try your request again. This doesn't occur when using normal generation, and it works without using Langchain.
Code to replicate:
from langchain_core.messages import SystemMessage, HumanMessage
from pydantic import Field, BaseModel
from models import OutputGuardrail
client = client(
service_name='bedrock-runtime',
region_name='eu-west-1',
)
additionalModelRequestFields={"inferenceConfig": {"topK": 1}}
nova_micro = ChatBedrockConverse(
model="eu.amazon.nova-micro-v1:0",
client=client,
region_name="eu-west-1",
temperature=1,
top_p=1,
additional_model_request_fields=additionalModelRequestFields,
)
class TestModel(BaseModel):
"""A test model to check the tool use conversion."""
name: str = Field(description="The name of the user.")
age: int = Field(description="The age of the user.")
model = nova_micro.bind_tools([TestModel], tool_choice="any")
messages = [SystemMessage(content="You are a chatbot assistant."), HumanMessage(content="Hi")]
response = model.invoke(messages)
print(response)```
Update: I've been testing this functionality with the Converse API directly, and believe it's a problem with that, not the LangChain implementation. Whenever I try to use 'any' or named tool parameter, it gives the error above.