-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issue
Description
An invalid history of messages starting with ModelResponse passes validation, but causes API errors down the line (see below)
Example Code
The following code does not raise any validation errors and instead fails after receiving error code from Bedrock API:
import boto3
from pydantic_ai import Agent
from pydantic_ai.messages import TextPart, ModelResponse
from pydantic_ai.models.bedrock import BedrockConverseModel
from pydantic_ai.providers.bedrock import BedrockProvider
model = BedrockConverseModel(
"eu.amazon.nova-lite-v1:0",
provider=BedrockProvider(bedrock_client=boto3.client("bedrock-runtime")),
)
agent = Agent(model, output_type=str)
truncated_history = [ModelResponse(parts=[TextPart(content="ai response")])]
response = agent.run_sync("hello", message_history=truncated_history)
print(response.output)And fails with exception
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the Converse operation: A conversation must start with a user message. Try again with a conversation that starts with a user message.
Python, Pydantic AI & LLM client version
pydantic-ai: 1.0.10
model client: BedrockConverseModel