-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
bugSomething isn't workingSomething isn't working
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
Sorry that this might be hard to reproduce. I've tried a few ways but putting this up first in case anyone runs into a similar error. It seems like there is a missing signature which causes the following error
Error
status_code: 400
body: {
'type': 'error',
'error': {
'type': 'invalid_request_error',
'message': "messages.1.content.0.type: Expected `thinking` or `redacted_thinking`,
but found `text`. When `thinking` is enabled, a final `assistant` message
must start with a thinking block..."
}
}Workaround
To fix this, I modified pydantic_ai/ui/vercel_ai/_event_stream.py to pass the signature in provider_metadata
async def handle_thinking_end(
self, part: ThinkingPart, followed_by_thinking: bool = False
) -> AsyncIterator[BaseChunk]:
yield ReasoningEndChunk(id=self.message_id) # <-- part.signature not passed async def handle_thinking_end(
self, part: ThinkingPart, followed_by_thinking: bool = False
) -> AsyncIterator[BaseChunk]:
provider_metadata = None
if part.signature:
pydantic_ai_meta = {"signature": part.signature}
if part.provider_name:
pydantic_ai_meta["provider_name"] = part.provider_name
if part.id:
pydantic_ai_meta["id"] = part.id
provider_metadata = {"pydantic_ai": pydantic_ai_meta}
yield ReasoningEndChunk(
id=self.message_id, provider_metadata=provider_metadata
)Example Code
Python, Pydantic AI & LLM client version
python 3.13
pydantic 1.34.0
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working